This website is out of date. The new site is at http://learnche.mcmaster.ca/4C3

Least squares modelling (2012)

From Statistics for Engineering

Jump to: navigation, search
Class date(s): 09 February, 01 March 2012
Video material (part 1)
Download video: Link (plays in Google Chrome) [243 Mb]


Video material(part 2)
Download video: Link (plays in Google Chrome) [236 Mb]


Video material (part 3)
Download video: Link (plays in Google Chrome) [275 Mb]


Video material (part 4)
Download video: Link (plays in Google Chrome) [224 Mb]


Video material (part 5)
Download video: Link (plays in Google Chrome) [260 Mb]

[edit] Materials

Class date: 09 February 2012 (only slides 1 to 62)
01 March 2012 (slides 63 to the end)
I want my notes with:  

  pages per physical page

Use page frames?

[edit] Code used in class

Thermocouple data (09 February)

V <- c(0.01, 0.12, 0.24, 0.38, 0.51, 0.67, 0.84, 1.01, 1.15, 1.31)
T <- c(273, 293, 313, 333, 353, 373, 393, 413, 433, 453)
plot(V, T)
model <- lm(T ~ V)
summary(model)
coef(model)
 
plot(V, T)
v.new <- seq(0, 1.5, 0.1)
t.pred <- coef(model)[1] + coef(model)[2]*v.new
lines(v.new, t.pred, type="l", col="blue")


Thermocouple data (01 March)

V <- c(0.01, 0.12, 0.24, 0.38, 0.51, 0.67, 0.84, 1.01, 1.15, 1.31)
T <- c(273, 293, 313, 333, 353, 373, 393, 413, 433, 453)
plot(V, T)
model <- lm(T ~ V)
summary(model)
confint(model)   # get the coefficient confidence intervals
resid(model)     # model residuals
qqPlot(resid(model)) # q-q plot of the residuals to check normality
 
# Plot x against the residuals to check for non-linearity
plot(V, resid(model))
abline(h=0)
 
# Plot the raw data and the regression line in red
plot(V, T)
abline(model, col="red")


Example from the notes on multiple linear regression (MLR) (01 March)

# Calculate the model manually
x1.raw <- c(1,3,4,7,9,9)
x2.raw <- c(9,9,6,3,1,2)
y.raw  <- c(3,5,6,8,7,10)
n <- length(x1.raw)
 
x1 <- x1.raw - mean(x1.raw)
x2 <- x2.raw - mean(x2.raw)
y <- y.raw - mean(y.raw)
 
X <- cbind(x1, x2)
 
# Calculate:  b = inv(X'X) X'y
XTX <- t(X) %*% X    # compare this to cov(X)*(n-1)
XTY <- t(X) %*% y
XTX.inv <- solve(XTX)
b <- XTX.inv %*% XTY
b
 
# Let R calculate the model:
model <- lm(y.raw ~ x1.raw + x2.raw)
summary(model)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox