Introduction

This report investigates the relationship between plant growth rate and soil moisture content using simulated data.

The simulation uses the baseline parameters from the Week 5 linear regression demonstration. A student-number seed ensures that all results are reproducible.

Set Seed

Simulate Plant Growth Data

# Define baseline parameters from Week 5
alpha <- 2.348       # Population intercept
beta1 <- 20.750      # Population slope
n_plants <- 200      # Number of observations
rse <- 8.019         # Residual standard deviation

# Define the range of soil moisture content
# Based on the original plant growth dataset
min_moisture <- 0.249525236
max_moisture <- 1.993908374

# Simulate soil moisture content
soil.moisture <- runif(
  n_plants,
  min = min_moisture,
  max = max_moisture
)

# Generate random normally distributed errors
e <- rnorm(
  n_plants,
  mean = 0,
  sd = rse
)

# Simulate plant growth rate
growth.rate <- alpha + beta1 * soil.moisture + e

# Combine variables into a data frame
data1 <- data.frame(
  soil.moisture,
  e,
  growth.rate
)

# Display the first six observations
head(data1)
##   soil.moisture          e growth.rate
## 1     0.5067831  -2.813414  10.0503346
## 2     1.8704386   2.315172  43.4747737
## 3     0.5664239   3.270562  17.3718574
## 4     1.7485486  -5.811556  32.8188277
## 5     1.1876020   1.923038  28.9137786
## 6     0.4187498 -10.377003   0.6600547

Question 1: Regression Summary and ANOVA

Question 1a: Regression Summary

# Fit a simple linear regression model
# Plant growth rate is the response variable
# Soil moisture is the explanatory variable

fit <- lm(
  growth.rate ~ soil.moisture,
  data = data1
)

# Display the regression summary
summary(fit)
## 
## Call:
## lm(formula = growth.rate ~ soil.moisture, data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -24.8891  -6.0398  -0.1061   5.2126  25.1376 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.8542     1.3880   0.615    0.539    
## soil.moisture  21.3341     1.1597  18.397   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.188 on 198 degrees of freedom
## Multiple R-squared:  0.6309, Adjusted R-squared:  0.629 
## F-statistic: 338.4 on 1 and 198 DF,  p-value: < 2.2e-16

Question 1b: ANOVA Table

# Display the ANOVA table
# This tests whether soil moisture explains
# a significant amount of variation in growth rate

anova(fit)
## Analysis of Variance Table
## 
## Response: growth.rate
##                Df Sum Sq Mean Sq F value    Pr(>F)    
## soil.moisture   1  22692   22692  338.44 < 2.2e-16 ***
## Residuals     198  13276      67                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Calculate Regression Statistics

Question 2: Equation for the Observed Value

The observed response is modeled using the intercept, slope, explanatory variable, and residual error.

\[ y_i = \hat{\beta}_0 + \hat{\beta}_1 x_i + e_i \]

Using the estimated coefficients from the fitted regression:

\[ y_i = 0.8542 + (21.3341)x_i + e_i \]

Where:

  • \(y_i\) represents the observed plant growth rate.
  • \(x_i\) represents soil moisture content.
  • \(\hat{\beta}_0\) is the estimated intercept.
  • \(\hat{\beta}_1\) is the estimated slope.
  • \(e_i\) represents the residual error.

Question 3: Equation for the Predicted Value

The predicted plant growth rate is calculated using the fitted intercept and slope, without the residual error.

\[ \hat{y}_i = \hat{\beta}_0 + \hat{\beta}_1 x_i \]

Using the estimated coefficients:

\[ \hat{y}_i = 0.8542 + (21.3341)x_i \]

This equation predicts plant growth rate for a given soil moisture content.

Question 4: Equation for Calculating F

The F-statistic is calculated as the ratio of the regression mean square to the residual mean square.

\[ F = \frac{MSR}{MSE} \]

For simple linear regression:

\[ F = \frac{SSR/1}{SSE/(n-2)} \]

Using the regression results:

\[ F = \frac{2.2692398\times 10^{4}/1}{1.3275771\times 10^{4}/198} = 338.4432 \]

# Display the calculated F-statistic
F_value
## [1] 338.4432

Question 5: Equation for Calculating MSE

Mean squared error measures the residual variation around the fitted regression line.

\[ MSE = \frac{SSE}{n-2} \]

Using the regression results:

\[ MSE = \frac{1.3275771\times 10^{4}}{198} = 67.0493 \]

# Display the mean squared error
MSE
## [1] 67.04935

Question 6: Equation for Calculating SST

Total sum of squares measures the total variation in observed plant growth rates around their mean.

\[ SST = \sum_{i=1}^{n}(y_i-\bar{y})^2 \]

Alternatively:

\[ SST = SSR + SSE \]

Using the regression results:

\[ SST = 2.2692398\times 10^{4} + 1.3275771\times 10^{4} = 3.5968169\times 10^{4} \]

# Display total sum of squares
SST
## [1] 35968.17

Question 7: Equation for Calculating R-Squared

The coefficient of determination measures the proportion of variation in plant growth rate explained by soil moisture content.

\[ R^2 = \frac{SSR}{SST} \]

Alternatively:

\[ R^2 = 1-\frac{SSE}{SST} \]

Using the regression results:

\[ R^2 = 1-\frac{1.3275771\times 10^{4}}{3.5968169\times 10^{4}} = 0.6309 \]

# Display the coefficient of determination
R_squared
## [1] 0.6309022
# Verify against the regression summary
summary(fit)$r.squared
## [1] 0.6309022

Approximately 63.1% of the variation in simulated plant growth rate is explained by soil moisture content.

Question 8: Statistical Interpretation

A simple linear regression was used to test whether soil moisture content affects plant growth rate using 200 simulated observations. The results showed a significant positive relationship between soil moisture and plant growth rate (F(1, 198) = 338.44, p < 0.001, R² = 0.631).

The estimated slope was 21.334 (SE = 1.16, 95% CI [19.047, 23.621]), indicating that plant growth rate increased as soil moisture content increased. Soil moisture explained approximately 63.1% of the variation in plant growth rate.

Overall, the results suggest that soil moisture content is a significant predictor of plant growth rate in the simulated dataset.

Question 9: Regression Plot

The following scatterplot shows the relationship between soil moisture content and plant growth rate, including the fitted regression line and a 95% confidence band.

# Create a scatterplot of the simulated observations
ggplot(
  data1,
  aes(x = soil.moisture, y = growth.rate)
) +
  # Plot the individual simulated observations
  geom_point(
    size = 1.7,
    alpha = 0.7
  ) +
  # Add the fitted regression line
  # Include a 95% confidence band
  geom_smooth(
    method = "lm",
    formula = y ~ x,
    se = TRUE,
    level = 0.95
  ) +
  # Add informative axis labels and a title
  labs(
    x = "Soil Moisture Content",
    y = "Plant Growth Rate (mm/week)",
    title = "Plant Growth Rate vs. Soil Moisture Content",
    subtitle = "Linear regression with 95% confidence band"
  ) +
  # Apply a clean plotting theme
  theme_bw()

Question 10: Reproducible R Markdown Report

The simulation was performed using the Week 5 baseline parameters and a fixed random seed corresponding to my student number.

Week 5 linear regression teaching demonstration:

https://rstudio-pubs-static.s3.amazonaws.com/1352986_77a36109364541ca9c6443333f54a842.html

Original plant growth dataset used for simulation bounds:

https://github.com/R4All/datasets/blob/master/plant.growth.rate.csv