Environmental consultancy for planning & development0330 236 7329hello@acp-consultants.com
ACP Consultants

ACP Knowledge Hub · Data & Coding

Environmental data,
statistics and coding

Build your environmental data analysis skills. Turn measurements into evidence you can explain, check and reproduce.

Start with six practical R and Python exercises. Investigate the observations, choose the right calculation and describe what the result can—and cannot—tell you.

Six worked lessonsR + PythonSynthetic practice data

Start environmental data analysis with a clear question

I am new to data and code

Begin with the browser lab, then run the monitoring example. You will see how a valid zero, a missing measurement and an excluded value produce different decisions.

Allow around 30–45 minutes for this first route. You need basic arithmetic and a willingness to inspect the records.

Open the guided browser lab

I already use spreadsheets, R or Python

Run both implementations and compare their results. Then complete the paired-change and validation exercises. Check the observation unit before choosing a statistical model.

Allow around 60–90 minutes for the full starter pack. The examples use Python’s standard library and base R, without extra package installation.

Read the run instructions

These are introductory learning materials, not accredited training or evidence of independent professional competence. Use unfamiliar methods with a suitable supervisor.

A clean table is not automatically reliable evidence

First, define what one row represents before you calculate anything. A sample, a survey visit, an instrument interval and a site are different observational units. Then keep the raw file unchanged and record every decision in a separate analysis file.

In the monitoring example, six valid values are 0, 10, 12, 14, 14 and 40 µg/m³. Their mean is 15 and median is 13. One planned observation is missing. A value of 99 is excluded because the fictional instrument log records a calibration fault.

However, the value 40 remains included. An unusual value is a reason to investigate the source record; it is not, by itself, a reason to delete it.

Also, the fictional data are deliberately small. They do not represent an annual air-quality assessment or establish a concentration trend.

Six valid concentrations with separate mean and median markers
Each point is one valid record. A missing record has no plotted value; the known faulty record remains in the audit.
Open full-size diagram
ACP ConsultantsOriginal educational figure · synthetic data
© 2026 ACP Consultants Ltd.

Keep the meaning of absence

Zero: a valid observation returned zero. Missing: no usable observation is available. Excluded: an observation exists but a documented rule removes it from this calculation. Never recode all three as zero.

Make the calculation traceable

Record the variable, units, instrument or method, time basis, quality flag and inclusion decision. In addition, keep stable identifiers. Before summarising, check dates, duplicate records, decimal separators and any joins.

Six lessons, with a result you can check

LESSON 01

Audit and summarise monitoring records

Count included, missing and excluded records. Calculate a mean, median and sample standard deviation for the valid records.

Expected result
6 valid; 1 missing; 1 excluded. Mean 15 µg/m³; median 13 µg/m³.

Explain why neither the mean nor median fills the missing day.

Inspect monitoring.csv

LESSON 02

Choose the denominator for a rate

Compare 12 passes in 1 hour, 18 in 3 hours and a valid zero in 2 hours.

Expected result
Pooled rate: 30 ÷ 6 = 5 passes/hour. Equal-visit mean: (12 + 6 + 0) ÷ 3 = 6 passes/hour.

As a result, these estimate different summaries. Neither gives the number of bats.

Inspect effort.csv

LESSON 03

Preserve pairing when measuring change

Subtract before from after at each of four fictional water-sampling sites. Therefore, keep each pair together.

Expected result
Changes: −2, −1, −3 and +1 mg/L. Mean site change: −1.25 mg/L.

A before–after difference alone does not demonstrate that a treatment caused the change.

Inspect paired_water.csv

LESSON 04

Average sound energy, not dB numbers

Combine two consecutive 30-minute intervals at 60 and 70 dB(A), with the same measurement basis.

Expected result
Equivalent level across the hour: 67.40 dB(A). The arithmetic mean, 65 dB(A), is unsuitable here.

This is a duration-weighted equivalent level, not simultaneous source addition or a noise impact assessment.

Inspect sound.csv

LESSON 05

Calculate an index and handle invalid inputs

Calculate (NIR − red) ÷ (NIR + red) using already-scaled, synthetic reflectances.

Expected result
0.50 NIR and 0.10 red give 0.6667. However, a zero denominator produces a blank output, not zero.

Clouds, shadows, scale factors and mixed pixels need their own checks. NDVI does not establish habitat condition.

Inspect reflectance.csv

LESSON 06

Distinguish bias from prediction error

Compare paired predicted and observed heights. Calculate error as predicted minus observed.

Expected result
Errors +1, −1, +2 and −2 m give bias 0 m, MAE 1.5 m and RMSE 1.5811 m.

Therefore, zero average bias does not imply accurate predictions. Assessment needs representative, independent validation.

Inspect validation.csv

Every calculation is implemented in both supplied scripts. The language changes; the question, units, inclusion rules and expected answer stay the same.

Why different averages answer different questions

Rates of 12, 6 and 0 passes per hour alongside pooled rate 5 and equal-visit mean 6
Pooled rate weights visits by usable recording hours. An equal-visit mean gives each visit the same weight.
Open full-size diagram
ACP ConsultantsOriginal educational figure · synthetic data
© 2026 ACP Consultants Ltd.

First, an average needs a target. Pooling counts and effort estimates the overall pass rate across the included recording time. Averaging visit rates instead describes an equally weighted visit in this small set.

However, neither is automatically the right answer for every ecological question. For example, an equal-site comparison may need a site summary first. Repeated visits also share site conditions, so extra nights do not create extra independent sites.

Write the denominator in the result. Report “30 reviewed passes across 6 usable hours”, not just “activity = 5”. Keep the spatial coverage, recording settings and exclusions alongside the figure.

For the full bat-specific workflow, continue to bat survey data analysis in R and Python.

Describe variation before making an inference

Spread in observations

The sample standard deviation describes dispersion around the sample mean. A median and interquartile range can help describe a skewed distribution, but they answer different questions. Therefore, state the summary you use and show the observations where practical.

Also, percentile results can differ between software defaults. If you add quartiles to these scripts, choose and record an algorithm. R provides several options; identical labels alone do not guarantee identical computations.

Uncertainty in an estimate

Standard error concerns the variability of an estimator under a sampling model. It is not the same as the spread of individual observations. A conventional t interval for a mean uses the sample mean ± a t multiplier × s/√n.

That interval needs a suitable sampling and distributional basis. For example, treating repeated measurements as independent can make it misleadingly narrow. Moreover, a larger file does not repair a biased sampling design.

Association, prediction and causation

A regression describes a specified relationship conditional on its design and assumptions. In contrast, check prediction accuracy on data that did not guide model fitting. Keep sites, subjects or time blocks together when their dependence matters.

A correlation or before–after change cannot by itself separate a treatment effect from weather, season, site selection or another change. Therefore, explain alternative explanations and what additional design would address them.

A sensible next model

First, consider the response and study design. Counts, proportions, continuous measurements and censored laboratory results need different treatment. Examine residuals, effort, overdispersion, imbalance and missingness before interpreting coefficients.

This introductory pack deliberately stops at transparent descriptive calculations. It does not select an “appropriate test” automatically or turn a small synthetic example into an ecological conclusion.

Confidence is conditional. A 95% confidence interval describes the long-run coverage of the stated procedure under its assumptions. It is not a 95% probability statement about a fixed parameter, nor a guarantee that an individual future observation falls inside it.

A good-looking prediction can still hide substantial error

The validation example has a mean signed error of zero. Positive and negative errors cancel, even though every prediction differs from its paired observation. In contrast, MAE and RMSE reveal the remaining discrepancy.

Bias: mean(predicted − observed). MAE: mean absolute error. RMSE: square root of mean squared error. All three retain the units of the measured variable.

In particular, RMSE weights larger errors more strongly. Do not compare scores across different units or differently selected validation datasets. Also examine errors by magnitude, location, season and relevant subgroups.

For spatial models, nearby samples may share information. Randomly separating adjacent pixels can give an overly optimistic impression of performance. Therefore, plan validation around the intended new location or time period.

Four signed errors around zero, showing cancellation while absolute error remains
All four synthetic points have an error. Bias alone cannot describe predictive accuracy.
Open full-size diagram
ACP ConsultantsOriginal educational figure · synthetic data
© 2026 ACP Consultants Ltd.

Download the examples and reproduce the results

Python route

Install Python from python.org. Extract the complete pack, then open a terminal in that folder. The script uses the standard library only.

python learn.py --out outputs/python

On Windows, py learn.py --out outputs/python may be the available launcher. If the command is not found, use the installed interpreter’s full path.

Outputs: results CSV, quality audit, SVG plot and a run record containing the interpreter version and SHA-256 input hashes.

R route

Install R from CRAN. In a terminal opened in the extracted pack folder, run the following command. Also, no additional R packages are required.

Rscript --vanilla learn.R outputs/R

This is a terminal command, not an R-console expression. Use the full Rscript path if it is not on your system PATH.

Outputs: results CSV, quality audit, SVG plot and a run record with session details and input checksums.

Re-running replaces files inside the selected output folder. Therefore, use a new output folder for each comparison and keep the raw CSVs unchanged. The scripts process the supplied column layouts; they are not universal importers.

Original example code is available under the MIT licence. Original educational text, diagrams and synthetic datasets are available under CC BY 4.0. Credit ACP Consultants Ltd., link to this resource and state any changes. ACP logos and third-party material retain their separate rights. See the included reuse terms. Read the reuse terms.

Make the next person’s check possible

A small but complete analysis record

  1. State the question, observation unit and intended comparison.
  2. List source files, permissions, units, collection dates and coordinate reference systems.
  3. Keep the raw data and explain all cleaning or exclusion decisions.
  4. Record script and software versions, input hashes and relevant parameters.
  5. Check a small example independently before trusting a larger run.
  6. Export a readable table, labelled figure and limitations statement.

A practical portfolio task

Run all six lessons, then change one input in a copied dataset. First, predict the direction of change before you run the code. Then keep the original and revised output in separate folders.

Write 150–250 words explaining the result, the denominator, one quality concern and one conclusion the data cannot support. Include a figure caption with units, sample size, inclusion rules and the synthetic-data label.

Finally, ask a reviewer to reproduce your result from the pack alone. A reproducible mistake is still a mistake; numerical checks and domain review are both necessary.

Shared skills, different environmental decisions

Ecology and bats

Counts need usable effort, site structure and a reviewed identification process. Preserve uncertainty in labels and link results back to recordings and field notes.

Bat analysis lessons and tools

BNG and habitat evidence

Check parcel identifiers, area units, survey dates and data joins. An index or generic score does not replace the applicable biodiversity metric and ecological judgements.

Biodiversity net gain guidance

Noise and acoustics

Use the correct sound quantity, frequency weighting, time basis and logarithmic calculation. Keep source addition distinct from temporal energy averaging.

The sound lesson demonstrates arithmetic, not a full impact assessment.

Air quality and water

Preserve concentration units, sampling duration, quality flags and detection limits. A result reported below a detection limit is censored, not a measured zero.

For example, use the monitoring and paired-water lessons as introductory practice.

GIS and remote sensing

Check coordinate reference systems, resolution, alignment, acquisition dates and quality masks. Interpret map accuracy at the scale needed for the question.

For example, the reflectance and validation lessons give a small numerical starting point.

Research and professional reporting

First, choose a question before a technique. Record assumptions and distinguish observations, interpretation and recommendations. Also, make limitations visible next to the result.

Use the portfolio task and independent reproduction check.

This is a shared ACP Knowledge Hub resource. The bat campaign keeps its specialist acoustics, survey methods, identification and analysis pages. Explore related guidance through the Knowledge Hub’s Data & Coding section.

Frequently asked questions

Should I learn R or Python first?

Choose one and complete a small reproducible task. R is well suited to statistical workflows; Python also connects naturally to general programming and data processing. The examples here let you compare equivalent calculations without needing to learn both at once.

Do I have to upload project data?

No. The browser exercise uses a small list entered into the current page; its calculation code makes no data-upload requests. Similarly, the downloadable R and Python examples run on your computer. However, the hosting site can still receive ordinary page requests. Avoid entering confidential project information into a teaching exercise.

Does the browser lab run my R or Python code?

No. It runs one defined descriptive calculation in JavaScript. Download the source pack to run and edit R or Python locally. An unrestricted online coding service is a separate proposal and is not enabled.

Why do the average rates differ?

Pooling counts and hours weights each visit by its valid duration. An equal-visit mean weights each visit equally. Choose the summary that matches the question and report it explicitly.

Can I use these figures in a planning report?

The supplied values are invented and cannot support a site conclusion. For your own data, verify the method, permissions, inputs and professional suitability. The supplied code and educational resources have separate reuse terms; retain the appropriate attribution.

Can I replace a missing observation with zero?

Only when zero is the actual valid recorded value. Missingness and exclusions must remain explicit. Any imputation needs a stated method, justification and assessment of its effects.

Will completing the pack qualify me to undertake a survey?

No. These learning exercises support supervised development. They do not confer a licence, professional accreditation or competence for a particular regulated task.

How do I know my run worked?

Compare results.csv with the supplied expected-results.csv. First, confirm the same included records and units before comparing numbers. The instructions explain the expected outputs, blank NDVI result and common errors.

Sources and further learning

Primary documentation and methodological sources checked on 18 November 2026. The exercises, explanations and synthetic datasets are prepared by ACP Consultants; no source implies endorsement of this resource.

  1. Python CSV documentation

    Import records with explicit fields and types; CSV formats and quoting vary.

  2. Python statistics documentation

    Definitions of mean, median and sample standard deviation; missing values need explicit treatment.

  3. R data input documentation

    Explicit column classes, missing-value conventions and CSV parsing.

  4. R sample quantiles documentation

    Quantile algorithms differ; record the chosen algorithm when comparing software.

  5. NIST: exploratory data analysis

    Use graphics and diagnostics to investigate patterns and assumptions.

  6. NIST: confidence limits for a mean

    The t interval and its assumptions; intervals are not proof that a design is unbiased.

  7. Wilson et al. (2017): Good enough practices in scientific computing

    Reproducible organisation, data handling and recording the computational workflow.

  8. USGS: Normalized Difference Vegetation Index

    NDVI definition and Landsat product scale and fill conventions. This pack uses unscaled synthetic reflectance.

  9. QGIS: coordinate reference systems

    Choose coordinate reference systems for the analysis, including distance and area distortion.