R code used at VAPMS Selected Applications of Mathematical Statistics, summer semester 2018/2019.

Class 7 (Apr 4 2019)

Building and testing a simple linear model:
attach (cars)
plot (cars)
L <- lm (dist ~ speed)
abline (L)
sd (resid (L))
plot (L)
The slope of the line computed in two different ways:
L
cor (speed, dist) * sd(dist)/sd(speed)
Variations of the above:
M <- lm (dist ~ 0 + speed)
abline (M)
M <- lm (dist ~ speed + I(speed^2))
curve (M$coeff[1] + M$coeff[2]*x + M$coeff[3]*x^2, add=T)
M <- lm (dist ~ speed + I(speed^2) + I(speed^3))
curve (M$coeff[1] + M$coeff[2]*x + M$coeff[3]*x^2 + M$coeff[4]*x^3, add=T)
Linear regression of air pollution against temperature and wind speed (temp and pm25 data are from Class 1):
wind <- c(4.1, 4.1, 5.1, 4.6, 5.1, 5.7, 4.6, 4.1, 2.1, 3.6, 2.6, 0.5, 1.5, 0.5, 0.5, 1.5, 1.5, 2.1, 1.0, 1.5, 1.0, 1.5, 1.5, 2.6)
A <- lm (pm25 ~ temp + wind)

Created: Tue Nov 24 2015
Last modified: Thu Apr 4 10:57:52 CEST 2019