4 Working with R in Quarto
A clinic manager asks an analyst to prepare a monthly report on waiting times. The analyst calculates averages in R, copies a chart into a word processor, and types the results into a paragraph. When a missing record is corrected, the chart changes but the paragraph does not. The problem is not a difficult statistical calculation; it is the separation of calculation from communication. A computational document addresses this problem by retaining the instructions that generate its results alongside the explanation of those results.
4.1 Learning objectives
After completing this chapter, readers should be able to configure the knitr engine, control executable cells, import and validate data, construct summaries and graphics, insert inline results, build parameterized reports, and explain the limits of caching and dependency management.
4.2 The computational publishing model
R is a language and environment for statistical computing. Quarto coordinates the production of a publication; it does not replace R. For an R document using knitr, the engine evaluates code and captures selected outputs. Pandoc then converts the resulting intermediate document into the requested publication format. This separation allows the same statistical work to support several forms of communication.
A useful mental model is source, execution, conversion, and inspection. Source includes prose, code, metadata and input files. Execution produces numerical results and graphics. Conversion organizes those results into a publication. Inspection checks both the statistical conclusions and the appearance of the output. A successful render does not guarantee a correct analysis: a perfectly formatted report may still use the wrong denominator or omit important limitations.
4.2.1 Preparing the environment
Install R and Quarto using their official installation instructions. In the R console, install the packages required by the examples once, rather than installing them during every render.
install.packages(c("knitr", "rmarkdown", "ggplot2", "renv"))In a terminal, run quarto check knitr. This checks the R execution environment. If the terminal cannot find Quarto, resolve that installation problem before debugging R code. If Quarto is found but knitr is unavailable, verify which R installation Quarto is using. Installing a package into a different R library may not resolve the error.
4.3 Executable cells and evaluation order
An executable R cell begins with a fenced opening containing {r}. A regular fence containing only r displays code without executing it. The distinction is especially useful in a textbook, where an intentionally incorrect example should be visible without interrupting the render.
```{r}
#| label: calculate-mean
wait <- c(12, 18, 15, 25, 10)
mean(wait)
```
The expected result is 16 minutes. During an ordinary uncached render, cells execute in document order. An object created in an earlier cell can be used later, but an object that exists only in the interactive R console should not be assumed to exist during rendering. This is why running individual cells successfully is not sufficient evidence that the whole report is reproducible.
4.3.1 Controlling the output
| Option | Effect | Typical purpose |
|---|---|---|
echo: false |
Hides source code | Reader-facing report |
eval: false |
Does not execute the cell | Demonstrating an example |
include: false |
Runs cell but omits its code and output | Setup |
warning: false |
Hides warnings | Reviewed, understood warnings only |
message: false |
Hides messages | Reduce package startup clutter |
error: false |
Stops rendering on errors | Production reports |
cache: true |
Reuses eligible cached results | Expensive calculations |
Set document-wide defaults under execute in YAML and override them using #| cell options. Use unique labels. A label beginning with fig- or tbl- has a special role when creating cross-referenced output.
Suppressing a warning does not correct its cause. Investigate missing observations, convergence problems, and invalid calculations before hiding diagnostic output.
4.4 Worked investigation: clinic waiting times
The accompanying CSV contains eleven synthetic appointment records from two clinics. Waiting time is measured in minutes from arrival to the start of the appointment. One record has no recorded waiting time. The question is descriptive: how do observed waiting times differ between the clinics? The data are not a randomized experiment and cannot establish that one clinic causes shorter waits.
4.4.1 Import and validation
In a standalone report saved at the project root, the following code reads the supplied file. The companion example in examples/ch04 instead uses a path relative to that example’s directory.
clinic <- read.csv("data/clinic-ch04.csv", na.strings = c("", "NA"))
stopifnot(!anyDuplicated(clinic$id))
stopifnot(all(clinic$clinic %in% c("A", "B")))
stopifnot(all(is.na(clinic$wait_min) | clinic$wait_min >= 0))
str(clinic)The checks express assumptions as executable statements. Unique identifiers help detect duplicated records. The allowed clinic labels prevent misspelled groups from silently entering the analysis. Nonnegative waiting times are required by the measurement definition. These checks cannot establish that a recorded value is accurate, but they catch several common structural errors.
A relative path makes the report portable when the entire project is moved. An absolute path tied to a particular user’s desktop will usually fail on another computer. When diagnosing a file error, inspect getwd() and file.exists() during rendering. Avoid changing the working directory inside cells as a general solution; instead establish a clear project convention.
4.4.2 Missing observations and denominators
n_total <- nrow(clinic)
n_observed <- sum(!is.na(clinic$wait_min))
n_missing <- sum(is.na(clinic$wait_min))
c(total = n_total, observed = n_observed, missing = n_missing)There are eleven records, ten observed waiting times and one missing value. Missing is not zero. Replacing the missing value with zero would falsely indicate that the patient received immediate attention. Removing missing observations from a calculation is appropriate for describing observed values, but it does not eliminate possible bias if missingness is related to waiting time.
4.4.3 Constructing group summaries
summarize_wait <- function(d) {
x <- d$wait_min[!is.na(d$wait_min)]
data.frame(clinic = d$clinic[1], total = nrow(d),
observed = length(x), missing = sum(is.na(d$wait_min)),
mean_min = if (length(x)) mean(x) else NA_real_,
median_min = if (length(x)) median(x) else NA_real_)
}
summary_table <- do.call(rbind, lapply(split(clinic, clinic$clinic), summarize_wait))
rownames(summary_table) <- NULL
summary_tableThe function accepts a data frame for one clinic and returns a single summary row. Separating the calculation into a function avoids duplicating formulas for each clinic. The conditional expressions also handle a group with no observed waiting times: its mean and median are undefined rather than zero.
| Clinic | Total | Observed | Missing | Mean (min) | Median (min) |
|---|---|---|---|---|---|
| A | 5 | 5 | 0 | 16 | 15 |
| B | 6 | 5 | 1 | 12 | 11 |
The observed mean difference, A minus B, is four minutes. The median difference is also four minutes. These results describe the supplied observations only. Appointment complexity, staffing, arrival patterns and the missing record may influence the comparison.
4.5 Inline R expressions
Inline code embeds a computed value within a sentence. In a knitr document, the following source connects the prose to the object created earlier.
The dataset contains `r n_total` records, of which
`r n_observed` have observed waiting times.For a report that must display a fixed number of decimal places, use sprintf("%.1f", value) in the inline expression. Keep unrounded values in calculation objects and round only for presentation. Rounding group means before computing their difference can introduce unnecessary numerical error.
Dynamic prose still requires editorial judgment. If the sign of a difference changes after a data update, a hard-coded sentence saying that clinic A has longer waits may become false. A safer general sentence reports the signed difference and defines its direction, or uses conditional language generated from the result. Never let a dynamic sentence imply a causal conclusion that the study design cannot support.
4.6 Tables generated from data
The knitr::kable() function converts a data frame into a publication table. It is a useful starting point for documents targeting several formats.
```{r}
#| label: tbl-wait-summary
#| tbl-cap: "Observed waiting times by clinic."
knitr::kable(summary_table, digits = 1,
col.names = c("Clinic", "Total", "Observed", "Missing",
"Mean (min)", "Median (min)"))
```
Reference the table using @tbl-wait-summary in the surrounding text. Automatic numbering reduces maintenance when sections are rearranged. The caption should describe what the table contains; interpretation belongs in the narrative. Include units in column headings and distinguish total records from analyzed records.
4.7 Statistical graphics
A mean alone conceals variation. For a small dataset, displaying individual observations makes the distribution visible. A dot plot can show both the separation between clinics and the overlap of their waiting times.
library(ggplot2)
observed <- subset(clinic, !is.na(wait_min))
ggplot(observed, aes(x = wait_min, y = clinic)) +
geom_point(size = 3, alpha = 0.8) +
labs(x = "Waiting time (minutes)", y = "Clinic") +
theme_minimal(base_size = 12)
The supplied illustration shows the observed values without hiding the overlap between groups. In a live computational report, use fig-cap, fig-alt, fig-width and fig-height to control the generated figure. Alternative text should communicate the main visual information to readers who cannot see the graphic. A caption and alternative text serve related but distinct purposes.
When a graphic will be printed, avoid relying solely on color. Use clear labels, adequate font sizes, and distinguishable symbols. Inspect the final PDF or Word document because a figure that looks readable in an interactive viewer may be too small on a printed page.
4.8 Parameterized reports
A parameter is an input that changes the behavior of a report without requiring the analyst to edit its calculations. For example, a clinic manager may request separate reports for clinics A and B. A standalone knitr document can define a parameter in YAML:
---
title: "Clinic waiting-time report"
engine: knitr
format: html
params:
clinic: "A"
---Inside the document, validate the parameter before using it.
stopifnot(params$clinic %in% c("A", "B"))
selected <- subset(clinic, clinic == params$clinic)From the terminal, render a separate report for clinic B:
quarto render parameterized.qmd -P clinic:B --output clinic-b.htmlRun this command from the companion example directory. Separate output filenames prevent accidental overwriting. Parameterization does not provide access control: sensitive records should not be embedded in public HTML, even if the visible report is filtered. The examples in this book use synthetic data.
4.9 Caching and computational cost
Caching can save time when a calculation is expensive. However, cached results can become stale when an external data file changes. A code cell that reads a CSV may have identical source code even though the CSV contents have changed. For this reason, the introductory examples deliberately avoid caching. In advanced projects, explicitly track external dependencies or invalidate the cache when inputs change. A fresh render is an important final check before publication.
Quarto’s project-level freeze feature is distinct from knitr caching. Freeze can reuse computational results during project rendering; it is not a guarantee that results are current. Choose a strategy based on how often data and code change, and document how to regenerate all outputs from scratch.
4.10 Managing dependencies with renv
A report may depend on a particular version of a package. Installing the newest package on another computer can change behavior. The R package renv records project dependencies in a lockfile and supports restoring those versions.
# Run interactively in the project directory.
renv::init()
renv::snapshot()
# On another machine with renv installed:
renv::restore()Commit the lockfile and relevant project activation files to version control. Do not commit a large local package library. Record the R version and any external system requirements separately. A lockfile does not capture every aspect of the operating system, external data source or Quarto installation. Include sessionInfo() in a diagnostic appendix when useful, and record quarto --version in the project documentation.
4.11 Guided practice
4.11.1 Activity 1: From console to publication
Create a new Quarto document with the knitr engine. Define five waiting times in one cell, calculate the mean in a second cell, and insert the result in a sentence using inline R. Render the report, change one observation, and render again. Explain which outputs update automatically and which sentences still require review.
4.11.2 Activity 2: Missingness audit
Use the supplied clinic dataset. Report the number of total, observed and missing records for each clinic. Calculate the mean with and without na.rm = TRUE. Explain why the default result for clinic B is missing and why replacing the missing value with zero is inappropriate.
4.11.3 Activity 3: Audience-specific reporting
Render the same report with echo: true and echo: false. Compare the two outputs from the perspective of a statistical reviewer and a clinic administrator. Decide which version should be distributed to each audience, while preserving the source for verification.
4.11.4 Activity 4: Parameterized publication
Render the companion parameterized report for each clinic. Confirm that the title or narrative identifies the selected clinic and that the filenames differ. Try an invalid clinic parameter and explain the resulting error.
4.12 Troubleshooting
| Symptom | Diagnostic action |
|---|---|
| Object not found | Check earlier cells and render from a clean session. |
| Package not found | Check the R installation and library paths. |
| File not found | Inspect the rendering directory and relative path. |
| Mean is NA | Count missing values and define the analysis denominator. |
| Figure absent | Check evaluation and inclusion options. |
| Results unexpectedly unchanged | Disable or invalidate caching and check the input file. |
| Duplicate label | Give each cell a unique label. |
4.13 Extended laboratory: from raw records to an analysis-ready dataset
A reproducible analysis begins with a measurement definition, not a statistical function. In the clinic dataset, each row represents an appointment, the identifier distinguishes records, and the waiting time measures elapsed minutes. The clinic code identifies the location, not a treatment assignment. A missing waiting time is a record for which the outcome is unknown; it does not imply that the patient was seen immediately. Before computing a summary, write down the population represented by the records, the unit of observation, and the inclusion rule. In this laboratory the analysis includes all observed waiting times and reports missingness separately. This is an available-case descriptive analysis, not a claim that missingness is harmless.
4.13.1 Building an explicit validation contract
A validation contract specifies the structure that a dataset must satisfy before downstream calculations are allowed. Checking only whether a file exists is insufficient: a spreadsheet export may contain an extra header, repeated identifiers, or a different unit. The following function returns the validated data rather than silently modifying questionable records. Save it in a script and call it from the first computational cell of a report.
validate <- function(d) {
stopifnot(all(c("id", "clinic", "wait_min") %in% names(d)))
stopifnot(!anyNA(d$id), !anyDuplicated(d$id))
stopifnot(all(d$clinic %in% c("A", "B")))
stopifnot(is.numeric(d$wait_min))
stopifnot(all(is.na(d$wait_min) |
(is.finite(d$wait_min) & d$wait_min >= 0)))
d
}The function deliberately stops rather than removing invalid rows. This is an important distinction between validation and cleaning. A cleaning decision should be recorded in a separate transformation step, ideally with a reason and a count of affected observations. If an appointment has a negative delay because the clinic defines delay relative to scheduled time, the validation contract must change to reflect that different measurement. Do not change the contract merely to make a problematic dataset pass.
4.13.2 Constructing an audit table
The following function calculates the number of records, the observed denominator, missing count, mean, and standard deviation. It handles groups with no observed outcomes and groups with only one observed outcome explicitly. The sample standard deviation is undefined for fewer than two observations.
summarize_wait <- function(x) {
observed <- x[!is.na(x)]
n <- length(observed)
data.frame(total = length(x), observed = n,
missing = length(x) - n,
mean = if (n > 0) mean(observed) else NA_real_,
sd = if (n > 1) sd(observed) else NA_real_)
}
clinic <- validate(read.csv("clinic.csv"))
audit <- do.call(rbind, lapply(split(clinic$wait_min, clinic$clinic),
summarize_wait))
auditNotice that the function receives a vector, not a particular clinic. It can be tested independently and reused when additional clinics are added. In a report, retain the full precision of the audit object and round only a copy for presentation. Rounding intermediate values can introduce avoidable differences between a table and an inline calculation.
| Clinic | Records | Observed | Missing | Mean (min) | SD (min) |
|---|---|---|---|---|---|
| A | 5 | 5 | 0 | 16.00 | 5.87 |
| B | 6 | 5 | 1 | 12.00 | 3.54 |
The observed mean difference is four minutes in favor of clinic B. The missing fraction in clinic B is one sixth, or 16.7 percent. Reporting five observed records without mentioning the sixth would conceal an important limitation. Reporting six observations in the denominator of the mean would implicitly treat the missing value as zero. Neither practice is appropriate here.
4.13.3 Guided practice: testing the contract
Make a disposable copy of the dataset in memory. Change the first identifier to match the second, then call validate(). Restore the original copy and change the first waiting time to a negative number. Predict the result before running the function. Finally, replace a valid waiting time with NA and repeat the audit. Explain why this third change is accepted but changes the observed denominator. Do not edit the original CSV for these tests.
4.14 Statistical inference as a publishing example
The descriptive comparison can be extended to illustrate a Welch two-sample confidence interval. This example assumes independent observations within and between clinics and a sampling process for which the interval is meaningful. With only five observed values per group, distributional assumptions cannot be assessed reliably. The records are synthetic and no population inference or causal conclusion should be drawn from them. The purpose is to demonstrate how a report can preserve the connection between a statistical method and its output.
Let the parameter of interest be the difference in population means, B minus A. The estimated difference is
\[ \widehat{\Delta}=\bar{x}_B-\bar{x}_A. \]
The estimated standard error is
\[ SE=\sqrt{\frac{s_B^2}{n_B}+\frac{s_A^2}{n_A}}. \]
Welch’s method uses an approximate degrees of freedom rather than assuming equal population variances. The confidence interval is the estimated difference plus or minus the appropriate t critical value multiplied by the standard error. The calculation is available directly in R, so the report does not need to copy a critical value from a separate table.
A <- na.omit(clinic$wait_min[clinic$clinic == "A"])
B <- na.omit(clinic$wait_min[clinic$clinic == "B"])
fit <- t.test(B, A, var.equal = FALSE)
fit$estimate
fit$conf.int
fit$p.valueThe order of the arguments determines the direction of the difference. Reversing the arguments changes the signs of the estimate and interval endpoints but not the two-sided p-value. A report should explicitly identify this direction in the methods and in the caption of any effect plot. Avoid describing a nonsignificant result as proof that the clinics have identical waiting times. The interval describes uncertainty under the specified model, and a wide interval can be compatible with several substantively different effects.
4.14.1 Dynamic interpretation without overclaiming
Inline R expressions can insert the observed difference and interval endpoints into prose. For example, the following source uses objects defined earlier in the report.
The observed difference (B minus A) was
`r sprintf("%.1f", mean(B) - mean(A))` minutes.
The 95% Welch interval was
`r sprintf("%.2f to %.2f", fit$conf.int[1], fit$conf.int[2])` minutes.
This approach prevents transcription errors but cannot automatically guarantee an appropriate interpretation. A change in data may invalidate a method’s assumptions even when all expressions update correctly. Review the narrative after every substantial data revision. In particular, do not automate causal language or claims of clinical importance from a p-value threshold.
4.15 Professional statistical graphics: two approaches
A small dataset is best displayed with individual observations rather than only a bar representing the mean. A dot plot reveals overlap, sample size and unusual values. The group mean can be added as a secondary mark. The figure should identify units and groups and avoid visual effects that imply greater precision than the data support.
4.15.1 Base R implementation
stripchart(wait_min ~ clinic, data = clinic,
method = "stack", pch = 19,
col = "#214e70", xlab = "Waiting time (minutes)",
ylab = "Clinic")
points(c(mean(A), mean(B)), 1:2, pch = 18,
col = "#26766a", cex = 1.5)Base R is useful for portable reports because the graphics system is part of the standard R distribution. The plot displays observed values only; the caption should therefore report the missing record. The diamond represents the mean and must be explained in the caption or legend. For larger datasets, stacking or transparency may be needed to reveal overlapping observations.
4.15.2 ggplot2 implementation
library(ggplot2)
ggplot(subset(clinic, !is.na(wait_min)),
aes(x = wait_min, y = clinic)) +
geom_point(position = position_jitter(height = 0.06,
width = 0, seed = 42), colour = "#214e70", size = 3) +
stat_summary(fun = mean, geom = "point", shape = 18,
colour = "#26766a", size = 4, orientation = "y") +
labs(x = "Waiting time (minutes)", y = "Clinic") +
theme_classic(base_size = 12)Jitter changes only the vertical display position, not the measured waiting time. The seed makes the jitter reproducible. The summary layer computes the mean directly from the plotted data. A theme with a white background and restrained axes is suitable for a textbook or scientific report. Use shape as well as color to distinguish the summary from observations.
4.15.3 Figure cell options
```{r}
#| label: fig-waits
#| fig-cap: "Observed waiting times by clinic."
#| fig-alt: "Dot plot comparing observed waiting times."
#| fig-width: 7
#| fig-height: 3
#| echo: false
stripchart(wait_min ~ clinic, data = clinic, pch = 19)
```
Refer to this figure using @fig-waits in the same report. A label is an identifier, not a caption. Keep labels stable when revising the wording of captions. In a book, choose labels that are unique across chapters. Figure dimensions are specified in inches; the rendered display size may also depend on the output format. Inspect the final figure at its actual reading size rather than relying on the appearance in the R graphics pane.
4.16 Simulation laboratory: sampling variability
A simulation makes it possible to investigate how an estimator varies across repeated samples. Suppose a hypothetical waiting-time model has mean 20 minutes and standard deviation 6 minutes. For independent observations from a normal model, the sample mean has standard error \(6/\sqrt{n}\). This model is a mathematical teaching device; actual waiting times may be skewed and nonnegative.
set.seed(2026)
n <- 25
means <- replicate(5000, mean(rnorm(n, mean = 20, sd = 6)))
mean(means)
sd(means)
6 / sqrt(n)
hist(means, breaks = 30, col = "#214e70", border = "white",
main = "", xlab = "Simulated sample mean (minutes)")The theoretical standard error is 1.2 minutes. The simulated standard deviation should be close to this value, not exactly equal. Increase the sample size to 100 and repeat. The theoretical standard error becomes 0.6 minutes. Increasing the number of simulated samples reduces Monte Carlo variability in the estimated standard error; increasing the size of each sample changes the sampling distribution itself. These two operations answer different questions.
A random seed should be set before the simulation, not repeatedly inside each replicate. Resetting the seed within each replicate would generate identical samples and destroy the intended investigation. Record the R version and random-number generator settings if exact replication of a simulation is essential. A seed alone is not a complete description of the computational environment.
4.17 Reusable reports and dependency discipline
When a report is produced every month, separate the data validation, summary functions, and narrative. A parameter can select a clinic or reporting period, but should be validated before any calculations occur. A parameterized report is not an interactive application: the parameter is normally supplied before rendering and the resulting document is a snapshot. Use distinct output names and preserve the input version associated with each publication.
For a new isolated project, renv::init() can establish a project library. After installing and testing the required packages, renv::snapshot() records package dependencies. A collaborator can use renv::restore() to reconstruct the recorded library. These commands should be run deliberately, outside the report’s computational cells. The lockfile does not capture the operating system, Quarto version, external system libraries, confidential data, or every aspect of the runtime environment. Record these separately as appropriate.
A practical release test is to copy the report and its documented inputs into a clean directory, restore dependencies, and render without relying on objects from an interactive session. Compare the resulting audit table and figures with the expected outputs. If a cache is used, perform at least one uncached validation render. Do not publish a report merely because the cached version looks correct.
4.18 Extended review and applied laboratory
- Explain why a validation function should stop on a duplicated identifier rather than automatically deleting a row.
- Calculate the missing fraction for each clinic and explain which denominator is used.
- Compute the standard error for the B-minus-A difference by hand and compare with R.
- Reverse the arguments to
t.test()and explain the changes to the interval and p-value. - Explain why the two-sided test cannot establish equivalence between clinics.
- Design an accessible caption for the dot plot that reports missingness and identifies the mean marker.
- Compare the theoretical sampling standard errors for sample sizes 25 and 100.
- Explain why resetting a seed inside each simulation replicate is inappropriate.
- Describe what must accompany an renv lockfile for another researcher to reproduce the report.
- Create a second report for an administrator with code hidden but the same computed results and limitations.
4.18.1 Extended project: a reproducible clinic comparison
Use the standalone report in examples/ch04/extended/ as a starting point. Submit a validated dataset, an audit table, a descriptive figure, a Welch interval with explicit assumptions, a simulation investigation, and a short noncausal interpretation. Include a README describing how to reproduce the output and an evidence log showing that a second person attempted a fresh render. Treat the statistical inference as a demonstration, not evidence about real clinics. If a dependency prevents rendering, record the exact error and the attempted correction rather than claiming success.
| Criterion | Points |
|---|---|
| Validation and missingness accounting | 6 |
| Statistical calculations and interpretation | 8 |
| Accessible figure and dynamic narrative | 6 |
| Simulation design and explanation | 5 |
| Reproduction instructions and evidence | 5 |
| Total | 30 |
4.19 Chapter summary
An R-based Quarto report connects data, executable instructions, results and interpretation. Cell options determine what readers see, not whether a statistical conclusion is justified. Inline expressions reduce transcription errors; generated tables and graphics keep outputs aligned with calculations. Parameters support repeated reporting, while dependency records and fresh renders improve reproducibility. The author remains responsible for data quality, appropriate methods and accurate interpretation.
4.20 Review exercises
- Explain the roles of R, knitr, Quarto and Pandoc.
- Distinguish an executable cell from a displayed code listing.
- Explain why a console object may be unavailable during rendering.
- Compare
echo: falsewithinclude: false. - Explain why hiding warnings is not a correction.
- Write a check for negative waiting times that permits missing values.
- Calculate the observed proportion of missing records in clinic B.
- Calculate the overall observed mean waiting time.
- Explain why the group comparison is not causal.
- Write an inline expression that displays a mean to one decimal place.
- Explain the purpose of a table label beginning with
tbl-. - Describe two accessibility improvements for a statistical figure.
- Explain why a parameterized report needs distinct output filenames.
- Describe a situation in which a cached result becomes stale.
- Explain what an renv lockfile does and does not capture.
- Propose a reproducibility check before distributing a report.
4.21 Applied project: clinic service quality report
Prepare a standalone Quarto report for a clinic quality-improvement committee. Use the synthetic dataset supplied with this chapter. Define the question and measurement units, validate the data, report missingness, generate a group summary table and a labeled graphic, and incorporate at least two inline numerical results. Include a limitation paragraph and render to HTML. Also attempt a second format supported by your installation. Submit the source, input data, output, and a short README describing dependencies and rendering commands.
| Criterion | Points |
|---|---|
| Clear question and data validation | 5 |
| Correct summaries and missingness accounting | 5 |
| Dynamic narrative and reproducible code | 5 |
| Professional table and accessible figure | 5 |
| Interpretation, limitations and documentation | 5 |
| Total | 25 |
4.22 Further reading
4.23 Supplemental assessment
- Conceptual (4 points). Explain why missing waits must not be replaced with zero without justification.
- Technical (8 points). In R calculate observed mean, median and strict exceedance of 15 for c(10,12,15,18,25,NA).
- Applied (8 points). Write a clinic report with a generated summary and a missingness statement.
See the student assessment packet in the source package for submission guidance and any required datasets.
4.24 Looking ahead
Compare the R workflow with Python in Chapter 5.
4.25 Interactive learning lab
Explore the activity below, then explain what changed and why.