← Teaching resources

Regression practice

How does plant growth vary with soil moisture?

Kris Wild · 15-minute teaching session

Use keywords or a short sentence as we go. These are your own notes, not graded answers. Leave a gap if you need to keep listening; the expandable reminders are there for revision.

Slide numbers refer to the accompanying 15-minute lesson. Pause the video whenever you need more time to write or try the activity.

Blue monospace = R codeGreen = commentsTeal, bold and underlined = interpreted values

Notes are kept on this device. Download a copy before leaving.

Slides 3–8

1. The biological question and model

Model reminder

X is soil moisture content and Y is plant growth in mm/week. The soil-moisture measurement units are not supplied. The intercept is predicted mean growth at X = 0. The slope is the change in predicted mean growth for one unit of X.

Slides 5 and 9–10

2. Residuals and least squares

Open the least-squares activity. Scroll to the second graph, with hand size (X), height (Y), and two grey dials. Keep the points unchanged. Adjust slope and intercept to make the total coloured square area as small as possible. Spend about one minute.

Check after trying

A residual is observed Y minus predicted Y, measured vertically. Least squares minimises the sum of squared residuals. The slide animation shows the first two gaps slowly and then the remaining gaps together. Some squares can grow while others shrink: it is their total area that matters.

The website example has a fit near intercept 5.00 and slope 0.81. These values describe hand size and height, not the plant model.

Slides 11–12

3. The hypotheses

Intercept and slope reminder

Intercept
H₀: β₀ = 0
H₁: β₀ ≠ 0

Slope
H₀: β₁ = 0
H₁: β₁ ≠ 0

A zero slope means mean growth does not change linearly with soil moisture. The slope answers how mean growth changes as moisture increases. Zero moisture lies outside the observed data here, limiting interpretation of the intercept.

Slides 13–14

4. The model in R

R code from the slides
# Read the data
plant_gr <- read.csv("plant.growth.rate.csv")

# Fit the model
model_pgr <- lm(plant.growth.rate ~
  soil.moisture.content, data = plant_gr)
# Plot the data and fitted line
library(ggplot2)
ggplot(plant_gr,
  aes(soil.moisture.content, plant.growth.rate)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE)

Blue monospace is code to enter. Green lines beginning with # are comments. Put the CSV in your working folder before running this code.

Download the plant CSV

Slides 15–17

5. Checking assumptions

Diagnostic reminders
# Check the diagnostic plots
library(ggfortify)
autoplot(model_pgr, smooth.colour = NA)

The overview on slide 15 introduces four assumptions. Use the plots on slides 16–17 and the sampling design to assess them:

  • Linearity: mean growth follows a straight line as moisture changes. In residuals versus fitted, look for points around zero without a systematic curve.
  • Independence: errors do not depend on one another. Assess this from the sampling design, including whether the same plant was measured repeatedly. These plots alone cannot establish independence.
  • Constant variance: error spread is similar across fitted values. In the scale-location plot, look for a roughly even spread rather than a widening or narrowing pattern.
  • Normality: errors are approximately normal for the usual tests and confidence intervals. In the normal Q-Q plot, points should roughly follow the reference line.

Normality concerns the errors, not the raw moisture or growth values. Residuals help us assess those errors.

The residuals-versus-leverage plot is an additional check for influential observations. Investigate unusual points before deciding how to handle them. Influence is a diagnostic check, not a fifth assumption.

These are visual checks, not a formal pass-or-fail test. The plant dataset does not document the sampling design, so independence needs further information.

Slides 18–19

6. Reading summary() and reporting results

Walk through the output and reporting sentence

The same values appear in the R output and the reporting sentence. Choose each step in order.

Choose a step to match the R output to the reporting sentence.

Each unit increase in soil moisture was associated with 12.75 mm/week higher mean growth (t(48) = 12.49, p < 0.001, R² = 0.765).

# Check summary
summary(model_pgr)
Call:
lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_gr)

Residuals:
    Min      1Q  Median      3Q     Max 
-8.9089 -3.0747  0.2261  2.6567  8.9406 

Coefficients:
                      Estimate Std. Error t value Pr(>|t|)    
(Intercept)             19.348      1.283   15.08   <2e-16 ***
soil.moisture.content   12.750      1.021   12.49   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 4.019 on 48 degrees of freedom
Multiple R-squared:  0.7648,    Adjusted R-squared:  0.7599 
F-statistic: 156.1 on 1 and 48 DF,  p-value: < 2.2e-16

The intercept and slope have separate coefficient tests. In this biological report we focus on the slope. The design is not documented, so this sentence describes an association.

Before you finish

7. One question to revisit

Slide 20 · after the lesson

Extra practice

Apply what you have learned to iris, penguins and US-state data. Use R or RStudio and record your answers here. The code below is a starting point; the web page does not run R.

Format each response as you would a results statement in a journal publication. Identify the predictor and response, interpret the slope with units, report the test statistic with its degrees of freedom, p-value and R². Check the model assumptions before interpreting your results.

1. Iris: petal length and width

Using the built-in iris dataset, use petal length to predict petal width, with all species combined. Both measurements are in centimetres.

Starter code: iris
# Fit one line across all iris species
iris_model <- lm(Petal.Width ~ Petal.Length, data = iris)

# Inspect the model
summary(iris_model)

# Inspect the data and fitted line
plot(Petal.Width ~ Petal.Length, data = iris)
abline(iris_model)

2. Penguins: flipper and bill length

Using penguins from the palmerpenguins package, use flipper length to predict bill length, with all species combined. Both measurements are in millimetres.

Starter code: penguins
# Install once if needed, then load the package
# install.packages("palmerpenguins")
library(palmerpenguins)

# Keep complete measurements for these two variables
penguin_data <- penguins[complete.cases(penguins[,
  c("flipper_length_mm", "bill_length_mm")]), ]

# Fit one line across all penguin species
penguin_model <- lm(bill_length_mm ~ flipper_length_mm,
  data = penguin_data)
summary(penguin_model)

The code omits only rows missing flipper or bill length. It keeps all species.

Optional reflection for iris and penguins: colour the scatterplot by species. How might combining species affect your interpretation of the single fitted line?

3. US states: choose two relationships

Using the built-in state.x77 dataset, create and interpret two simple regression analyses that describe meaningful predictive relationships.

# Convert the built-in matrix to a data frame
state.x77 <- data.frame(state.x77)

# Read the variable descriptions and inspect the names
?state.x77
names(state.x77)

state.x77 starts as a matrix. data.frame() converts it to a data frame and changes spaces in column names to dots, for example Life Exp becomes Life.Exp. Use the help page for variable definitions and units.

Optional examples if you need a starting point

Two possible pairs are murder rate and life expectancy, and high-school graduation rate and income. You can choose different relationships if you can explain why they are meaningful. These are state-level associations.

# Example 1: murder rate predicts life expectancy
state_model_1 <- lm(Life.Exp ~ Murder, data = state.x77)
summary(state_model_1)

# Example 2: high-school graduation rate predicts income
state_model_2 <- lm(Income ~ HS.Grad, data = state.x77)
summary(state_model_2)
Results-statement checklist

State the relationship in words, include the slope and its units, then give the statistical evidence. Explain any important limitation identified when checking the model.

Across [observations], a one-[unit] increase in [X] was associated with a [slope]-[unit] change in mean [Y] (t([df]) = [value], p = [value], R² = [value]).

Describe an association unless the study design supports a causal claim.

Notes stay in this browser on this device when browser storage is available. They are not submitted automatically. Download a copy before switching devices.

After class: revisit the expandable reminders and download your notes to keep. Bring your final question to the next discussion.