From a question to a report

Day 23 — an integrated study briefing

Data Analysis in Life Sciences

About this lecture

In a later lab course, or in your thesis project, you will be handed a table from an experiment and asked: “what did the treatment do?” You will be expected to answer with a short report: the question, a plot, the numbers, one limitation, and code that someone else can run again. Today you do that whole job once, on one small study.

Today you will:

  • choose one study: duckweed biomass or organic product yield;
  • check the data and decide what one independent unit is;
  • plot, summarise and compare in a stated direction;
  • write a result paragraph and keep it all in one report that renders from scratch.

No new methods today: everything comes from weeks 2–4. Day 24 tests whether someone else can reproduce your report.

Choose one study

Duckweed (default)

  • 20 flasks, randomly given extra nutrient or control.
  • Outcome: dry biomass after seven days, mg.
  • Compare with the Welch test from Day 17.
  • Report: duckweed-report.Rmd

Organic alternative

  • 12 synthesis runs, standard or modified protocol.
  • Outcome: product yield, %.
  • Descriptive comparison, no test.
  • Report: organic-study.Rmd

Two study options: duckweed biomass in flasks, or collected-product yield from synthesis runs.

Write the plan before the code

Save in reports/study-decisions.txt:

  1. Question, in one sentence.
  2. Independent unit: what was randomly assigned?
  3. Outcome and units, and how it is calculated.
  4. Missing values: which, and what you will do.
  5. Plot, and the direction of the comparison (e.g. nutrient − control).

The analysis goes from the question to the independent unit and data, then to a description; inference needs extra model assumptions.

Count the independent units

  • Duckweed: the flask is the unit. The many fronds in one flask share its water and nutrients.
  • Organic: the synthesis run is the unit. Weighing one product three times is still one run.
  • More readings of the same unit do not add replicates (Day 14).

Four flasks with many fronds each are four units; four synthesis runs with repeated weighings are four units.

Import and check the flasks

> duckweed <- read_csv("data/duckweed.csv", show_col_types = FALSE)
> glimpse(duckweed)
Rows: 20
Columns: 3
$ flask_id   <chr> "F01", "F02", "F03", "F04", "F05", "F06", …
$ treatment  <chr> "control", "control", "control", "control",…
$ biomass_mg <dbl> 36.4, 38.0, 34.9, 36.1, 25.8, 35.6, 29.5, 1…
> count(duckweed, treatment)
# A tibble: 2 × 2
  treatment     n
  <chr>     <int>
1 control      10
2 nutrient     10
> duckweed$flask_id[is.na(duckweed$biomass_mg)]
[1] "F17"

Twenty flasks were started, ten per group; F17 in the nutrient group was spilled, leaving 19 measurements.
  • glimpse(): 20 flasks, 3 columns, biomass is a number (dbl).
  • count(): 10 flasks per group, as designed.
  • is.na() finds the flask without a biomass: F17, spilled before weighing. Missing is not zero.

Plot every flask that was weighed

> available <- duckweed |>
+   filter(!is.na(biomass_mg))
> count(available, treatment)
# A tibble: 2 × 2
  treatment     n
  <chr>     <int>
1 control      10
2 nutrient      9
ggplot(available, aes(x = treatment, y = biomass_mg)) +
  geom_point(position = position_jitter(
    width = 0.08, height = 0, seed = 23)) +
  labs(x = "Treatment",
       y = "Dry biomass after seven days (mg)") +
  theme_minimal()
  • available drops F17 for the plot; duckweed keeps its row.
  • The groups overlap: nutrient F11 (31.7 mg) is below most controls.

The plot made by this code: individual duckweed biomass values for 10 control and 9 nutrient flasks; nutrient values are higher on average but overlap with the controls.

Compare in a stated direction

> nutrient <- available |> filter(treatment == "nutrient")
> control <- available |> filter(treatment == "control")
> comparison <- t.test(nutrient$biomass_mg,
+                      control$biomass_mg)
> comparison

        Welch Two Sample t-test

data:  nutrient$biomass_mg and control$biomass_mg
t = 3.0522, df = 16.936, p-value = 0.007229
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  2.268932 12.437735
sample estimates:
mean of x mean of y
 39.63333  32.28000
  • Nutrient first, so the result is nutrient − control.
  • Means 39.63 and 32.28 mg: a difference of 7.35 mg.
  • 95% CI 2.27 to 12.44 mg: the whole interval is above zero.
  • p = 0.007: a difference this large would be rare if nutrients changed nothing.
  • n = 9 and 10 flasks: report them, R does not print them.

Organic route: compare yields, not grams

> organic <- read_csv("data/organic-recovery.csv",
+                     show_col_types = FALSE) |>
+   mutate(yield_percent = 100 * isolated_mass_g /
+                          theoretical_mass_g)
> organic |>
+   group_by(protocol) |>
+   summarise(n = n(), mean_yield = mean(yield_percent),
+             sd_yield = sd(yield_percent))
# A tibble: 2 × 4
  protocol     n mean_yield sd_yield
  <chr>    <int>      <dbl>    <dbl>
1 modified     6       77       3.74
2 standard     6       68.7     4.32
  • Runs started at different scales, so compare percent yield. Y01: 100 × 0.62 / 1.00 = 62 %.
  • Modified − standard: 8.33 percentage points. No test needed.

Individual product yields for six standard and six modified runs, with group means as diamonds.

Write a result paragraph someone can check

Include: direction and size with units, available n, the spread or overlap, the uncertainty if you estimated it, and one limitation.

“Nutrient flasks had on average 7.35 mg more dry biomass than controls (95% CI 2.27 to 12.44 mg; Welch, p ≈ 0.007; 9 nutrient and 10 control flasks). F17 was spilled and has no measurement.”

Faulty draft Repair
“There were 20 biomass results.” 20 flasks, 19 measurements; F17 missing.
“The nutrient plants all grew more.” The groups overlap; the mean is higher.
“The SD is the error in the treatment effect.” SD is spread of flasks; the CI is uncertainty in the difference.
“p is the probability that nutrients work.” p assumes no difference and asks how surprising the data are.

Practise on fresh data: algae cultures

  • data/algae.csv: 24 cultures, reference or supplement; A19 was spilled.
  • Available: 12 reference + 11 supplement.
  • Means: 28.20 mg and 33.92 mg: supplement − reference ≈ +5.72 mg.
  • The largest single culture, A11 (41.7 mg), is in the reference group: a higher mean does not mean every culture is higher.
  • Putting 0 for A19 would drop the supplement mean to 31.09 mg: wrong.

Individual algae biomass values for reference and supplement cultures with group means marked; the groups overlap and the highest value is a reference culture.

Before you finish: the report must run on its own

  1. Packages and import at the top of the report.
  2. Checks and calculations, with findings written down.
  3. Plot of individual units and a small summary table.
  4. Comparison in the stated direction, and the result paragraph.
  5. Restart R, render, and read the HTML as a stranger would.

Keep data/ unchanged and outputs in output/. If something fails, write down where.

Summary

  • One question, one independent unit, one outcome with units: write them down first.
  • Missing is not zero: report started and available counts (20 flasks, 19 measured).
  • Plot the individual units before any summary or test.
  • State the direction (nutrient − control) and report size, uncertainty, n and a limitation.
  • The report must render from a fresh R session using only its own code.

Next (Day 24, reproduce and share): can someone else run your report in a fresh copy of the project and get the same result?

Now: open the Day 23 exercises. Leave with duckweed-report.Rmd (or organic-study.Rmd) and its HTML, reports/study-decisions.txt, and the algae script and memo.