Day 15 — A short descriptive report

Lecture slides · Quiz · Weekly revision

Today’s question

You send your supervisor a figure and the line “treated plants grew more”. The replies come back: which data file, how many plants, what are the dots, and can I rerun it? Today you write one short report that answers all of these: it states the question, shows the data checks, the summary table and the figure, says in words what they show, and rebuilds itself from the saved data.

Save a new file, descriptive-report.Rmd, in the project root, next to data/. You may copy the structure of your day 10 report and then rewrite its text. The study is described in the data dictionary; the data are simulated, and the nutrient formulation is not specified.

Make one report today. If your teacher chooses the organic-yield context below, make organic-report.Rmd instead.

Save today: descriptive-report.Rmd (or organic-report.Rmd) and its HTML.

The parts of the report

A short report needs four parts, in this order:

  1. Question: one or two sentences on what you want to find out.
  2. Data and methods: the input file, what one row is (one plant), the outcome and its unit, the checks you made, and how growth was calculated.
  3. Results: a table with n, mean, median and SD per group, and a figure of the individual plants with the group means.
  4. Interpretation: what the numbers show, in plain words, and what they cannot show yet.

Use the complete file data/seedlings.csv. If your teacher asks you to use the repaired day 11 data instead, include the repair code, say so in the methods, and use 23 usable growth values in every count.

Data and methods

Use anyDuplicated(), count() and sum(is.na()) to find out, inside the report, whether the file has one row per plant, two groups and complete lengths:

library(readr)
library(dplyr)
seedlings <- read_csv("data/seedlings.csv", show_col_types = FALSE)
anyDuplicated(seedlings$plant_id)
seedlings |> count(treatment)
sum(is.na(seedlings$initial_mm))
sum(is.na(seedlings$final_mm))
seedlings <- mutate(seedlings, growth_mm = final_mm - initial_mm)

anyDuplicated() gives 0 when no ID is repeated (a positive number would be the position of the first repeat). You should find 12 plants per group and no missing lengths, so the methods can say: “24 plants, 12 per group, no missing lengths; growth is final minus initial length in mm.”

Results

Reuse the day 13 summary, printed as a neat table with knitr::kable():

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,
             caption = "Observed growth and variation by treatment; lengths in mm.")

The table is calculated when the report renders, so if the data change, the table changes with them. Below it, add the day 13 figure of individual plants with red diamonds for the means, with a caption that names the unit, the symbols and n. The SD in the table describes how plants vary; this report has no confidence intervals.

Writing the interpretation

Describe three things: how the group means differ, how much plants vary within each group, and how much the groups overlap. For the complete data:

Treated seedlings grew a mean of 21.5 mm and controls 15.3 mm (12 plants each). Treated plants also varied more (SD 4.9 mm against 3.2 mm), and the two groups overlap: the smallest treated plant grew 12.2 mm, less than most controls.

Check each number against your table before you write it. “Every treated plant grew more” would be false, as the figure shows. How uncertain the 6 mm difference is, and whether chance could produce it, is the question of week 4, so end with that as the limitation.

Rendering from a fresh session

Restart R (Session → Restart R) and run this in the R Console, not in a chunk inside the report:

rmarkdown::render("descriptive-report.Rmd", output_dir = "reports")

The report must then load its own packages, read its own data and create every object, because nothing from your earlier session is available. Because the .Rmd is in the project root, data/seedlings.csv points to the right file, and output_dir = "reports" puts the HTML in reports/. A report must never contain its own render command.

“Object not found” means the report uses something that only existed in your Console; add the code that creates it to the report. “File not found” usually means the .Rmd is not in the project root or the path points to a personal folder such as Downloads. Read the first error message and the chunk name it gives.

Another lab: percentage yield

Use this instead of the seedling report if your teacher chooses it. Twelve independent synthesis runs in data/organic-recovery.csv were randomly assigned to a standard or a modified protocol, six each. The question is: what percentage of the possible product was collected in each run, and how does that differ between protocols? Calculate yield_percent = 100 * isolated_mass_g / theoretical_mass_g (Y01 gives 62%) and summarise by protocol:

organic <- read_csv("data/organic-recovery.csv", show_col_types = FALSE) |>
  mutate(yield_percent = 100 * isolated_mass_g / theoretical_mass_g)
organic_summary <- organic |>
  group_by(protocol) |>
  summarise(n_runs = n(), mean_yield_percent = mean(yield_percent),
            sd_percentage_points = sd(yield_percent), .groups = "drop")
organic_summary

Follow the same four parts, with checks of run IDs, protocol labels, missing values and positive theoretical masses. You should find mean yields of 68.67% and 77.00%, with SDs of 4.32 and 3.74 percentage points (standard and modified). Plot one point per run with the y-axis “Isolated product yield (%)”. In the limitation, say that the product is assumed pure, so yield says nothing about purity. Render with "organic-report.Rmd" in the command above.

Revising your report

  1. Close RStudio, open the HTML in a browser, and find out whether a reader can find the question, the input file, the unit, the outcome with its unit, the meaning of the symbols, and the main limitation. Add a sentence or a label for anything missing.
  2. Replace two numbers in your results text with inline R, so they are calculated when the report renders: for example We measured `r nrow(seedlings)` plants. renders as “We measured 24 plants.” Render to find out whether they appear; the object must be created earlier in the report.
  3. Rewrite these weak sentences if your draft has anything like them: “The results were good” (name the pattern and its size), “The treated group had more error” (“treated plants varied more, SD 4.9 mm”), “The computer removed the bad values” (say which value changed and which record supported it).
  4. Copy the project folder to a new location and render there to find out whether the report depends on anything outside it. Record what failed, what you changed and the result of the rerun in reports/day15-revision.txt.

A second class’s data

Write a second, shorter report, transfer-description.Rmd, in the project root, about the 18 plants in data/seedlings-transfer.csv. Start from your report’s structure, but replace the import, every object name, number, caption and sentence, because the new data tell a different story.

  1. Use the same checks to find out whether the file is complete: 18 rows, 9 per group, no missing lengths.
  2. Make the table and figure. You should get control: mean 13.66 mm, median 12.9 mm, SD 2.53 mm; treated: mean 17.87 mm, median 17.1 mm, SD 1.94 mm.
  3. Write the interpretation. This time the treated plants varied less than the controls, so a sentence copied from your first report would be wrong. Render from a fresh session and note in reports/day15-revision.txt where the HTML ended up.

Check your understanding

It is specific. “The sample is small” says little. “Each group has 12 plants, the groups overlap, and this report describes the sample without estimating how uncertain the difference between the means is” tells the reader what to be careful about.

The report uses objects created in the Console. Put the code that creates them in the report, restart R and render again.

Keep: descriptive-report.Rmd or organic-report.Rmd, its HTML, and the data it needs to render. Next: from description to a comparison.