11/9/2025

Dataset trees; Height vs Girth; Linear Regression

model: \(\text{Height} = \beta_0 + \beta_1 \cdot \text{Girth} + \varepsilon; \hspace{1cm} \varepsilon \sim N(0; \sigma^2)\)
  fitted: \(\text{Height} = \hat{\beta}_0 + \hat{\beta}_1 \cdot \text{Girth}\)               \(\hat{\beta}_0 = b_0\) – estimate of \(\beta_0\); \(\hat{\beta}_1 = b_1\) – estimate of \(\beta_1\)

Simple linear regression is a statistical method used to model the relationship between two variables (in this case Height and Girth of trees) by fitting a straight line through the data. The goal is to find the best fitting line that predicts y based on x. It is important to note that linear regression only provides a good estimation based on the provided data.

Dataset movies; Budget vs Rating (2000 - 2005); Linear Regression

Dataset movies; Budget vs Rating (2000 - 2005); Linear Regression CONTD.

model: \(\text{Budget} = \beta_0 + \beta_1 \cdot \text{Rating} + \varepsilon; \hspace{1cm} \varepsilon \sim N(0; \sigma^2)\)
  fitted: \(\text{Budget} = \hat{\beta}_0 + \hat{\beta}_1 \cdot \text{Rating}\)               \(\hat{\beta}_0 = b_0\) – estimate of \(\beta_0\); \(\hat{\beta}_1 = b_1\) – estimate of \(\beta_1\)
  Since \(\hat{\beta}_1 < 0\), this means that we have a negative trending linear regression line. In this example that means that higher ratings are associated with lower budgets.
 

Again, it is important to keep the given data sample in mind. For example, it is worth noting that a lot of budgets in this data are not available.

Also, the view of the graph of this relationship does not show a linear progression, therefore it might not be a good fit to use linear regression on. The points on the y axis have too much variance.

Dataset trees; Volume vs Girth; Linear Regression.

model: \(\text{Volume} = \beta_0 + \beta_1 \cdot \text{Girth} + \varepsilon; \hspace{1cm} \varepsilon \sim N(0; \sigma^2)\)
  fitted: \(\text{Volume} = \hat{\beta}_0 + \hat{\beta}_1 \cdot \text{Girth}\)               \(\hat{\beta}_0 = b_0\) – estimate of \(\beta_0\); \(\hat{\beta}_1 = b_1\) – estimate of \(\beta_1\)

Dataset trees; Volume vs Girth; Linear Regression. CONTD.

The previous slide details a plot that has a linear trend. Therefore, making it a good candidate for linear regression. We know that \(\varepsilon \sim N(0; \sigma^2)\) this so called “noise” or “random term” is assumed to be normally distributed. It is important to know that this random term is normally distributed with constant variance, \(\sigma^2\). It is also important to note that these random errors are independent of one another and independent of the variable \(x\). Without these assumptions analysis would not be valid.

(Intercept)       Girth 
 -36.943459    5.065856 

\(\beta_0\) is -36.94 and it represents the estimate of the y intercept
\(\beta_1\) is 5.07 and is the estimate of the slope
\(\text{Volume} = \hat{\beta}_0 + \hat{\beta}_1 \cdot \text{Girth}\)

Dataset trees; Volume vs Girth; Linear Regression plotly code

model: \(\text{Volume} = \beta_0 + \beta_1 \cdot \text{Girth} + \varepsilon; \hspace{1cm} \varepsilon \sim N(0; \sigma^2)\)
  fitted: \(\text{Volume} = \hat{\beta}_0 + \hat{\beta}_1 \cdot \text{Girth}\)               \(\hat{\beta}_0 = b_0\) – estimate of \(\beta_0\); \(\hat{\beta}_1 = b_1\) – estimate of \(\beta_1\)

mod = lm(Volume ~ Girth, data=trees)
x= trees$Girth; y= trees$Volume

xax <- list(
  title= "Girth",
  titlefont= list(family="Modern Computer Roman"))
yax <- list(
  title = "Volume",
  titlefont= list(family="Modern Computer Roman"), range = c(0, 100)
)

fig <- plot_ly(x=x, y=y, type = "scatter", mode= "markers", name="data",
   width=800, height=330) %>%
  add_lines(x = x, y=fitted(mod), name="fitted") %>%
  layout(xaxis = xax, yaxis = yax) %>%
  layout(margin=list(l=150, r=10, b=70, t=40))
config(fig, displaylogo=FALSE)

Dataset trees; Volume vs Girth; Linear Regression plotly code CONTD

The previous slide details code that gives you a plotly linear regression scatter plot. Using the y axis (Volume) to be \(\beta_0\) and the x axis (Girth) to be \(\beta_1\), represents the “fitted” line.

Dataset trees; Volume vs Girth; Residuals Plot

\(\text{Residual}_i = \text{Volume}_i - \hat{\text{Volume}}_i\)

Residuals show the difference between observed and predicted values. Small residuals indicate a better fit.