source("http://www.uvm.edu/~rsingle/stat221/data/scripts-221.R") dat <- bookdata("ch05q02.txt") head(dat) y.x1x2 <- lm(SBP~QUET+AGE, data=dat) anova(y.x1x2) y.x2x1 <- lm(SBP~AGE+QUET, data=dat) anova(y.x2x1) x.new.df <- data.frame(QUET=3.0, AGE=45) x.new.df predict(y.x1x2, x.new.df, interval="confidence", se.fit=T) 131.6077 - qt(1-.025,29)*sqrt(2.474176^2) #[1] 126.5481 131.6077 + qt(1-.025,29)*sqrt(2.474176^2) #[1] 136.6679 predict(y.x1x2, x.new.df, interval="prediction", se.fit=T) 131.6077 - qt(1-.025,29)*sqrt(79.5 + 2.474176^2) #[1] 112.6828 131.6077 + qt(1-.025,29)*sqrt(79.5 + 2.474176^2) #[1] 150.5326 predict(y.x1x2, x.new.df, se.fit=T) ci <- predict(y.x1x2, x.new.df, interval="confidence", se.fit=T) pi <- predict(y.x1x2, x.new.df, interval="prediction", se.fit=T) ci$se.fit #NOTE: se.fit has the same value for "confidence" & "prediction" pi$se.fit predict(y.x1x2, x.new.df, interval="confidence", se.fit=T) predict(y.x2x1, x.new.df, interval="confidence", se.fit=T) #R is 'smart' about the variable order