Tell the reader what was measured

Day 15 — A short descriptive report

Data Analysis in Life Sciences

About this lecture

You send your supervisor a figure and one line: “treated plants grew more.” The replies come back: Which data file? How many plants? What are the dots? Did any values go missing? Can I rerun it? Every one of those questions is fair, and a short report can answer all of them at once. How do we write a report that a reader can understand, check, and regenerate?

Today you will:

  • give each part of a short report a job: question, data and methods, results, interpretation;
  • name the input file and the checks, so every number has a visible origin;
  • render from a fresh session at the project root, so the report rebuilds itself from saved files;
  • keep claims at the level of the evidence: describe the sample, without claiming a tested effect.

This day pulls together Days 11–14. The same report becomes the starting point for the comparisons in week 4.

One question, one evidence trail

Question: how does seven-day growth vary among plants, and between control and treated seedlings?

  • Input: data/seedlings.csv, 24 plants in separate pots, 12 per group, lengths in mm.
  • Source: descriptive-report.Rmd at the project root.
  • Output: an HTML file that anyone can open.
  • Each step can be traced to the one before it: question → data → code → result.

A biological question leads to the measured data file, which leads to a rendered report.

Give each part of the report a job

  • Question: one or two sentences: what and why.
  • Data and methods: input file, independent unit (one plant), outcome and units, checks, how growth was calculated.
  • Results: a table with n, mean, median and SD; a figure with individual plants and means; a caption.
  • Interpretation and limitation: what the numbers show, in words, and what they cannot show yet.

A short report divided into question, data and methods, results with a figure, and interpretation and limitation.

Data and methods: show the checks

> seedlings <- read_csv("data/seedlings.csv",
+                       show_col_types = FALSE)
> anyDuplicated(seedlings$plant_id)
[1] 0
> seedlings |> count(treatment)
# A tibble: 2 × 2
  treatment     n
  <chr>     <int>
1 control      12
2 treated      12
> sum(is.na(seedlings$initial_mm))
[1] 0
> sum(is.na(seedlings$final_mm))
[1] 0
> seedlings <- mutate(seedlings,
+                     growth_mm = final_mm - initial_mm)
  • These are Day 11’s checks, now inside the report, so a reader sees what was checked and what came out.
  • anyDuplicated() gives 0: no plant ID is repeated.
  • 12 plants per group, no missing lengths.
  • In the methods text: “24 plants (12 per group), no missing lengths; growth = final − initial length (mm).”

Results: a table and a figure that agree

> group_summary <- seedlings |>
+   group_by(treatment) |>
+   summarise(n_observed = sum(!is.na(growth_mm)),
+     mean_mm = mean(growth_mm, na.rm = TRUE),
+     median_mm = median(growth_mm, na.rm = TRUE),
+     sd_mm = sd(growth_mm, na.rm = TRUE),
+     .groups = "drop")
> knitr::kable(group_summary, digits = 2)

|treatment | n_observed| mean_mm| median_mm| sd_mm|
|:---------|----------:|-------:|---------:|-----:|
|control   |         12|   15.28|     15.65|  3.19|
|treated   |         12|   21.49|     20.85|  4.87|
  • In the Console kable() prints this text; in the rendered report it becomes a neat table, rounded to 2 decimals.

The Day 13 figure: one dot per plant and a red diamond at each group mean, 15.28 millimetres for control and 21.49 for treated.

The figure from Day 13, with a caption naming the unit, the symbols and n.

Interpretation: claims at the level of the evidence

Supported: “Treated plants grew a mean of 21.5 mm and controls 15.3 mm (n = 12 each). Treated plants also varied more (SD 4.9 vs 3.2 mm), and the groups overlap.”

Weak sentence Repair
“The results were good.” Name the pattern and its size.
“The treated group had more error.” “Treated plants varied more (SD 4.9 mm).”
“Every treated plant grew more.” False: the groups overlap.

Measured plants support a sample description; a further jump to a universal cause is crossed out.

We described the sample. Estimating how uncertain the difference is comes in week 4.

Every number has a visible origin

  • A reader should be able to trace each number in the text back to a saved input and a chunk of code.

  • Inline R puts a calculated value straight into a sentence. In the source:

    We measured `r nrow(seedlings)` plants.

    renders as “We measured 24 plants.”

  • The object must be created earlier in the report. The sentence still needs units and meaning.

A saved input CSV feeds analysis chunks, which produce the table and the prose in the report.

Keep the report where its paths work

  • Save descriptive-report.Rmd at the project root, beside data/ and output/.
  • Then "data/seedlings.csv" means the same file on every computer that has the project.
  • A path like C:/Users/anna/Downloads/... works only on Anna’s laptop.
  • Render from the R Console; output_dir puts the HTML into reports/.

The report source sits at the project root beside its data and output folders; a personal absolute path would not move with the folder.
> rmarkdown::render("descriptive-report.Rmd", output_dir = "reports")
processing file: descriptive-report.Rmd
...
Output created: reports/descriptive-report.html
> list.files("reports")
[1] "descriptive-report.html"

Render from files, not from memory

  • Restart R, then render. The report must load its own packages, import its data and create every object.
  • An object that exists only in your Environment pane is not part of the report; on another computer it is missing.
  • Best test: copy the project to a new folder, render there. Record any failure, fix it, rerun.
  • A .Rproj file does not contain the data. The CSV must travel with the report.

A fresh session rebuilds the new HTML from the saved data and saved report source; old console objects are not an input.

Adapt the structure to a new study, not the old conclusion

The second class’s data, data/seedlings-transfer.csv, go into transfer-description.Rmd.

  • 18 plants, 9 per group; treated mean 17.87 mm (SD 1.94), control 13.66 mm (SD 2.53).
  • Here the treated plants vary less, the opposite of the first study.
  • Replace imports, counts, numbers, captions and sentences together. A new title on an old report is still the old report.

In the transfer study, treated plants have a higher mean growth than controls but their points are less spread out.

Two reviews before you hand it in

Reader review (code closed, HTML only)

  • What was the question?
  • What is one unit, and how many were there?
  • Which file, which outcome, which units?
  • What do the dots and diamonds mean?
  • What is the main pattern and its main limitation?

Analyst review (source open)

  • Does every number match a table or chunk?
  • Is n the number of usable values?
  • Were all transformations written in code?
  • Does it render after restarting R, in a fresh folder?
  • Is there a change log: issue, correction, rerun?

Remove a redundant printout before you remove a unit label or a limitation.

Summary

Concept Key fact
Structure Question → data and methods → results (table + figure) → interpretation and limitation
Input Name the file; show checks for IDs, labels, missing values; state n (24 plants, 12 per group)
Results Table from code (knitr::kable()), figure with plants and means, caption with n and units
Claims Describe the sample (means 21.5 vs 15.3 mm, overlap, SD); no tested effect yet
Lineage Every number traceable to data and code; inline R for counts and means
Location .Rmd at project root; render from the Console with output_dir = "reports"
Fresh session Restart R and render; test in a new folder; the data travel with the report
New study Adapt the structure; replace every number, caption and sentence

Next (Day 16, comparisons): turn the description into a comparison: state the question, the direction (treated − control) and the independent units before calculating a difference.

Now: open the Day 15 exercises. Leave with descriptive-report.Rmd (or organic-report.Rmd) and its rendered HTML, with the data needed to render it.