-Simple Linear Regression
–Predicting volume of the tree from its girth
–The data set we will be using is “Trees” which is already built into Rstudio
2025-10-19
library(ggplot2) library(plotly)
## ## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2': ## ## last_plot
## The following object is masked from 'package:stats': ## ## filter
## The following object is masked from 'package:graphics': ## ## layout
-Simple Linear Regression
–Predicting volume of the tree from its girth
–The data set we will be using is “Trees” which is already built into Rstudio
\[ y = \beta_0 + \beta_1x + \epsilon \]
Here is the dataset that we will be using
head(trees)
## Girth Height Volume ## 1 8.3 70 10.3 ## 2 8.6 65 10.3 ## 3 8.8 63 10.2 ## 4 10.5 72 16.4 ## 5 10.7 81 18.8 ## 6 10.8 83 19.7
This plot shows how the volume of the tree changes with the girth of the tree.
ggplot(trees, aes(x = Girth, y = Volume)) + geom_point(color = "Green") + labs(title = "Volume Vs Girth of Tree", x = "Girth (Inches)", y = "Volume (Cubic Feet)")
This graph shows the linear regression in our dataset
ggplot(trees, aes(x = Girth, y = Volume)) + geom_point()+ geom_smooth(method = "lm", se = F, color = "red") + labs(title = "Linear regression for volume vs girth", x = "Girth (Inches)", y = "Volume (Cubic feet)")
## `geom_smooth()` using formula = 'y ~ x'
This is a 3D plot that shows how volume, height, and girth are related.
plot_ly(trees, x = ~Girth, y = ~Height, z = ~Volume, type = "scatter3d", mode = "markers", marker = list(color = ~Volume, colorscale = "Blues"))
Here is an example of the R code i used in the previous slides
ggplot(trees, aes(x = Girth, y = Volume)) + geom_point(color = "Green") + labs(title = "Volume Vs Girth of Tree", x = "Girth (Inches)", y = "Volume (Cubic Feet)")
In this presentation i showed a simple linear regression that predicts the volume of a tree by its girth. We accomplished this by using the data set “trees” which is imbeded in rstudio.
This showed me that while girth increases then volume will also increase aswell.
I used a simple linear regression because it shows us how one variable can affect another variable.