Skip to content

About

A reproducible journey through ANOVA, linear models and experimental design using a realistic analytical-chemistry problem.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

ANOVA and Linear Models for Analytical Chemistry

This repository explores how the statistical model should follow the experimental structure and the scientific question when comparing analytical methods.

The project starts with a simple comparison of four analytical methods and progressively introduces the features that make real method-comparison data more difficult: multiple matrices, interactions, unbalanced designs, continuous covariates, assumption violations, multiple responses, and non-independent observations.

The examples are implemented in R and Quarto using reproducible, simulated analytical-chemistry data.

The scientific question

The starting question is deliberately simple:

Which analytical method should we use?

But a comparison of methods cannot always be reduced to a comparison of four means.

As the experimental context becomes more realistic, additional questions arise:

  • Are the observed differences scientifically relevant?
  • Does the matrix affect method performance?
  • Does the effect of the method depend on the matrix?
  • What changes when the design is unbalanced?
  • Is matrix composition better represented as a continuous variable?
  • Do the model assumptions hold?
  • What if observations are not independent?
  • What changes when several responses are considered simultaneously?

The statistical model changes because the scientific question and experimental structure change, not because a more sophisticated model is automatically preferable.


From ANOVA to mixed models

The repository is organised as a cumulative sequence of analytical problems:

01  Four methods
    ↓
    One-way ANOVA

02  Which differences matter?
    ↓
    Contrasts

03  Does matrix matter?
    ↓
    Two-way ANOVA

04  Does method performance depend on matrix?
    ↓
    Interaction

05  What happens when the design is unbalanced?
    ↓
    Type I / II / III sums of squares

06  Is matrix composition the real driver?
    ↓
    ANCOVA

07  Can we trust the model?
    ↓
    Diagnostics

08  What if assumptions fail?
    ↓
    Robustness

09  What if we have several responses?
    ↓
    MANOVA / MANCOVA

10  What if observations are not independent?
    ↓
    Mixed models

Each episode introduces a model or analytical strategy in response to a limitation of the previous one. The sequence therefore treats statistical modelling as part of the interpretation of the experiment rather than as a collection of independent tests.


Data and experimental structure

The data are simulated to represent a method-comparison experiment in analytical chemistry.

The main dataset contains measurements obtained by applying four analytical methods to samples from three environmental matrices. Each sample is analysed by all four methods, creating a repeated-measures structure that becomes important in the later mixed-model analysis.

The response variable is relative bias.

The data are synthetic and intentionally constructed for methodological exploration. They should not be interpreted as results from a real laboratory method comparison.


Why this project

A common way to present ANOVA is as a sequence of tests:

check assumptions → run ANOVA → inspect p-values → run post-hoc tests.

This project takes a different perspective.

The relevant question is whether the statistical model represents the data-generating and experimental structure well enough to support the scientific interpretation.

That means considering, for example:

  • experimental units and sources of dependence;
  • fixed versus continuous explanatory variables;
  • interactions between factors;
  • balance and the interpretation of sums of squares;
  • residual behaviour and model diagnostics;
  • consequences of assumption violations;
  • repeated measurements and random effects;
  • the distinction between statistical significance and practical relevance.

The aim is to show why these considerations can lead naturally from simple ANOVA models to linear models and mixed-effects models.


Reproducibility

The project is developed as a reproducible Quarto project.

R package dependencies are managed with renv, and the project environment is recorded in renv.lock.

To reproduce the analyses:

  1. Clone the repository.
  2. Open the project in RStudio or another R environment.
  3. Restore the project library with renv::restore().
  4. Render an individual Quarto document or the complete project.

Using renv makes the package environment explicit and reproducible rather than depending on whatever versions happen to be installed locally.


Project structure

.
├── data/              # Input datasets
├── analyses/          # Quarto documents for the individual episodes
├── posts/             # Quarto documents for LinkedIn posts
├── renv/              # Project-specific renv infrastructure
├── renv.lock          # Locked R package versions
└── ...

The exact structure may evolve as the project develops.


Software

The analyses are written in R and documented with Quarto.

The code favours transparent base R and lightweight packages where practical. data.table is used for data manipulation, while additional packages are introduced when they provide functionality directly relevant to the statistical analysis.


Scope and limitations

This is a focused methodological project, not a general introduction to statistics or a comprehensive treatment of experimental design.

The examples use simulated data and simplified experimental structures. Real analytical method-comparison studies require decisions based on the actual measurement process, sampling design, validation requirements, and scientific objective.

The central principle throughout the project is therefore:

Do not choose the statistical test first. Start from the experimental structure and the scientific question, then choose a model that can represent them.

About

A reproducible journey through ANOVA, linear models and experimental design using a realistic analytical-chemistry problem.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages