2025-11-09

Introduction

  • Topic: Simple Linear Regression
  • Definition: A statistical representation of the relationship between two variables.
  • Parameters: Must include a dependent and an independent variable.
  • Equation y = mx+b

Equation Definition

We model a response \(Y\) as a linear function of a single predictor \(X\): \[ Y_i = \beta_0 + \beta_1 X_i + \varepsilon_i,\quad i=1,\ldots,n \] with random errors \(\varepsilon_i\) that satisfy: \[ \mathbb{E}[\varepsilon_i]=0,\quad \mathrm{Var}(\varepsilon_i)=\sigma^2,\quad \text{and the } \varepsilon_i \text{ are independent.} \]

Equation Assumptions

  • y is a linear function of changing variable, x.
  • Statistical Assumptions Include
  1. Linearity: \(\mathbb{E}[Y\mid X=x] = \beta_0 + \beta_1 x\).
  2. Independence: observations are independent.
  3. Homoscedasticity: \(\mathrm{Var}(Y\mid X=x) = \sigma^2\) is constant.
  4. Normality of Errors: \(\varepsilon_i \sim \mathcal{N}(0,\sigma^2)\) for inference.

R code(CO2 Updake to Concentration to Type 3D Plot)

  • Code CO2 Updake to Concentration to Type Plot
plot_ly(CO2, 
        x = ~conc,
        y = ~uptake,
        z = ~as.numeric(Type),
        type = "scatter3d",
        mode = "markers",
        color = ~Treatment,
        symbol = ~Type,
        text = ~paste("Plant:", Plant, "<br>Type:", 
                      Type, "<br>Treatment:", Treatment)
        ) %>%
  layout(title = "3D CO2 Uptake vs Concentation and Type", 
         width = 600, height = 400, scene = list(
    xaxis = list(title = "CO2 Concentration"), 
    yaxis = list(title = "Uptake"), zaxis = list(title = "Plant Type")
  )
  )

Ploty Plot CO2 Uptake to Concentration to Type(3D)

R code(Gas and Car Weight Plot)

  • Code for Gas and Car Weight Plot
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "steelblue", size = 2) +
geom_smooth(method = "lm", se = TRUE, color = "darkred") +
labs(title = "Miles per Gallon vs Car Weight", 
     x = "Weight (1000 lbs)", y = "MPG") +
theme_minimal(base_size = 16)

Gas and Car Weight ggplot

R code(CO2 Linear Scatter Plot)

  • Code for CO2 Uptake vs CO2 Concentration Plot
ggplot(CO2, aes(x = conc, y = uptake)) + geom_point(alpha = 0.8) +
  geom_smooth(method = "lm", se = TRUE) +
  labs(title = "CO2 Uptake vs CO2 Concentration", 
       x = "CO2 Concentration", y = "Uptake") +
  theme_minimal(base_size = 16)

CO2 Uptake and Concentration ggplot