# Loading Libraries
library(ggplot2)
# Simulate the data 
soil.moisture.content <- runif(50, 0.2495, 1.9939)
plant.growth.rate <- 16.815 + 15.134 * soil.moisture.content + rnorm(50, 0, 4.0191)
plant_grow <- data.frame(soil.moisture.content, plant.growth.rate)

# Fit the regression
model1 <- lm(plant.growth.rate ~ soil.moisture.content, data = plant_grow)
# Q1: summary table
summary(model1)
## 
## Call:
## lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant_grow)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.5548  -2.8087   0.1455   2.8597  14.9979 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             14.281      1.624   8.794 1.43e-11 ***
## soil.moisture.content   17.519      1.380  12.696  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.539 on 48 degrees of freedom
## Multiple R-squared:  0.7705, Adjusted R-squared:  0.7658 
## F-statistic: 161.2 on 1 and 48 DF,  p-value: < 2.2e-16
# Q1: anova table
anova(model1)
## Analysis of Variance Table
## 
## Response: plant.growth.rate
##                       Df Sum Sq Mean Sq F value    Pr(>F)    
## soil.moisture.content  1 3321.3  3321.3  161.18 < 2.2e-16 ***
## Residuals             48  989.1    20.6                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Q8: plot with fitted line and confidence band
ggplot(plant_grow, aes(soil.moisture.content, plant.growth.rate)) +
  geom_point() +
  geom_smooth(method = "lm") +
  xlab("Soil moisture content") +
  ylab("Plant growth rate (mm/week)") +
  theme_bw()
## `geom_smooth()` using formula = 'y ~ x'