### Comments formatted to end before margin line to improve legibility. Comments
### not separated by lines (lines 27-28 for example) should be treated as one comment.
### Importing relevant libraries and .csv files
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggfortify)
## Loading required package: ggplot2
library(ggplot2)
plant <- read.csv("~/Desktop/Year 5/BIO4259A/datasets-master/plant.growth.rate.csv")
### Creating a simple linear regression using the plant.growth.rate.csv.
### This model states that plant.growth.rate is a function of soil.moisture.content
model_plant <- lm(plant.growth.rate ~ soil.moisture.content, data = plant)
### Creating the summary table of the linear regression generated from the plant.growth.rate
### dataset
summary(model_plant)
##
## Call:
## lm(formula = plant.growth.rate ~ soil.moisture.content, data = plant)
##
## 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
### Generated an ANOVA based on the data from the linear regression
anova(model_plant)
## Analysis of Variance Table
##
## Response: plant.growth.rate
## Df Sum Sq Mean Sq F value Pr(>F)
## soil.moisture.content 1 2521.15 2521.15 156.08 < 2.2e-16 ***
## Residuals 48 775.35 16.15
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
### Visualization of the plant growth rate compared to the soil moisture content
### based on the plant.growth.rate.csv dataset. Colors have been changed to aid
### visibility and a fitted regression line along with the confidence band has
### been added as a layer overtop the points. The confidence interval highlighted
### in the figure is 95% as was not specified in the function. The geom smooth()
### function operates using a linear model taking plant.growth.rate ~ soil.moisture.content
ggplot(plant, aes(x = soil.moisture.content, y = plant.growth.rate)) +
geom_point(fill = "orange", color = 'black', shape = 21) +
geom_smooth(method = lm, color = 'blue', size = 0.5) +
labs(x = "Soil Moisture Content", y = "Plant Growth Rate", title = "Relationship
between Soil Moisture Content and Plant Growth Rate") +
theme_bw()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
