2024-04-03

Types of relations

  • In a deterministic relation, complete knowledge of the values of independent variables specifies the values of dependent variables
  • In a nondeterministic (or, probabilistic) relation, complete knowledge of the values of the independent variables does not specify, but can help predict, the values of dependent variables

A generalizing model

\(y = β_0 + β_1x\)

  • a linear deterministic relation used to generalize a linear probabilistic relation
  • has response variable \(y\), y-intercept \(β_0\), slope \(β_1\), and predictor variable \(y\)
  • does not address randomness inherent to a probabilistic relation

A generalizing model with randomness

\(Y = β_0 + β_1x + ϵ\)

  • has error \(ϵ\), with expected value (or, mean) \(E(ϵ) = 0\) and variance \(V(ϵ) = σ^2\)
  • \(Y\) differs from expected value by random amount \(ϵ\)
  • addresses randomness inherent to a probabilistic relation

Values in a population

\(x_1, x_2, ..., x_n\)

  • set of predictor values corresponding to a set of observations numbering \(n\)

\(y_1, y_2, ..., y_n\)

  • set of response values corresponding to a set of observations numbering \(n\)

\((x_1, y_1), (x_2, y_2), ..., (x_n, y_n)\)

  • set of observations numbering \(n\)

A scatterplot represents each observation as a point on the \(x-y\) plane.

Implications

  • error \(ϵ\) permits observations to be plotted above or below the line, \(y = β_0 + β_1x\) (or, the regression line)
  • \(E(Y|x*)\) represents mean of \(Y\) when \(x\) has value \(x*\)
  • \(V(Y|x*)\) represents variance of \(Y\) when \(x\) has value \(x*\)
  • \(E(β_0 + β_1x + ϵ) = E(β_0 + β_1x) + E(ϵ) = E(β_0 + β_1x) = y\)
  • \(V(β_0 + β_1x + ϵ) = V(β_0 + β_1x) + V(ϵ) = V(ϵ) = σ^2\)

Example dataset

ggplot2::mpg is a dataset, describing fuel economy from 1999 to 2008 for 38 models of cars, used to demonstrate a scatterplot with regression line.

parameters used: displ (engine displacement, in litres); cyl (number of cylinders); cty (city miles per gallon); hwy (highway miles per gallon), class (car type)

summary(mpg[, c('displ', 'cyl', 'hwy', 'cty')])
##      displ            cyl             hwy             cty       
##  Min.   :1.600   Min.   :4.000   Min.   :12.00   Min.   : 9.00  
##  1st Qu.:2.400   1st Qu.:4.000   1st Qu.:18.00   1st Qu.:14.00  
##  Median :3.300   Median :6.000   Median :24.00   Median :17.00  
##  Mean   :3.472   Mean   :5.889   Mean   :23.44   Mean   :16.86  
##  3rd Qu.:4.600   3rd Qu.:8.000   3rd Qu.:27.00   3rd Qu.:19.00  
##  Max.   :7.000   Max.   :8.000   Max.   :44.00   Max.   :35.00

Scatterplot using ggplot

Faceted scatterplots using ggplot

3D scatterplot using plotly

mod = lm((hwy+cty)/2 ~ displ, data=mpg)
x = mpg$displ; y = (mpg$hwy + mpg$cty)/2
plot_ly(mpg, x=x, y=y, z=cyl, mode='markers', type='scatter3d', 
        color=as.factor(cyl), width=600, height=350) %>% 
  add_lines(x = x, y = fitted(mod), name="fitted")