# # MATH3330 Section B October 2001 # Week5b_Coffee_Part1 # # coffee <- read.table('coffee.dat', header = T, row.names = NULL, skip = 2) # Beware: this is 'artificial' data. Don't draw any conclusions from it summary(coffee) plot( coffee , ask = F) pairs( coffee ) xyplot( Heart ~ Coffee , coffee, panel = function(x,y,...) { panel.xyplot(x,y,...) panel.lmline(x,y,...) }) occupation <- c(rep('Student',8), rep('Professor',12)) identify( xyplot( Heart ~ Coffee , coffee, panel = function(x,y,...) { panel.xyplot(x,y,...) panel.lmline(x,y,...) }), labels = occupation ) fit.c <- lm( Heart ~ Coffee, coffee) summary(fit.c) # very strong positive relationship between Heart Damage and Coffee drinking # How about stress fit.s <- lm( Heart ~ Stress, coffee) summary(fit.s) # very strong positive relationship between Heart Damage and Stress # So if we use both we would expect to see a strong relationship with BOTH! fit.cs <- lm( Heart ~ Coffee + Stress, coffee) summary(fit.cs) # BUT the relationship with coffee is negative!! summary( coffee ) pred <- expand.grid ( Coffee = seq( 25, 150, by = 5), Stress = seq( 15, 200, by=5 )) pred.c <- pred pred.c$Heart <- predict(fit.c, newdata = pred) pred.s <- pred pred.s$Heart <- predict(fit.s, newdata = pred) pred.cs <- pred pred.cs$Heart <- predict(fit.cs, newdata = pred) pred <- stack( coffee, pred.c, pred.s, pred.cs, Type. = c('Data','Coffee only','Stress only','Stress+Coffee')) cloud( Heart ~ Coffee + Stress | Type. , pred)