Splus handout #1 S-PLUS : Copyright (c) 1988, 1996 MathSoft, Inc. S : Copyright AT&T. Version 3.4 Release 1 for Sun SPARC, SunOS 5.3 : 1996 Working data will be in /home/fac/d/jah/.Data Warning: Cannot open audit file > #ANALYSIS OF BOILING POINT DATA > #X=boiling point (degrees F) > #Y=log(barometric pressure) (inches of mercury) > #17 locations in the Alps and in Scotland > #_________________________________________________________________________ > > bp<-read.table("alr.3",header=T) > bp$pressure<-bp$pressure*100 > bp boil pressure 1 194.5 131.79 2 194.3 131.79 3 197.9 135.02 4 198.4 135.55 5 199.4 136.46 6 199.9 136.83 7 200.9 137.82 8 201.1 138.00 9 201.4 138.06 10 201.3 138.05 11 203.6 140.04 12 204.6 142.44 13 209.5 145.47 14 208.6 144.34 15 210.7 146.30 16 211.9 147.54 17 212.2 147.80 > motif() > par(mfrow=c(2,2)) > plot(bp$boil,bp$pressure,xlab="boiling point, degrees F", + ylab="log(pressure)*100") > title("Boiling point versus log pressure") > #_________________________________________________________________________ > bp.lm<-lm(pressure~boil,bp) > bp.lm Call: lm(formula = pressure ~ boil, data = bp) Coefficients: (Intercept) boil -42.13087 0.8954625 Degrees of freedom: 17 total; 15 residual Residual standard error: 0.378886 > #_________________________________________________________________________ > coef(bp.lm) (Intercept) boil -42.13087 0.8954625 >#_________________________________________________________________________ > summary(bp.lm) Call: lm(formula = pressure ~ boil, data = bp) Residuals: Min 1Q Median 3Q Max -0.3226 -0.1453 -0.0675 0.02111 1.359 Coefficients: Value Std. Error t value Pr(>|t|) (Intercept) -42.1309 3.3390 -12.6180 0.0000 boil 0.8955 0.0164 54.4499 0.0000 Residual standard error: 0.3789 on 15 degrees of freedom Multiple R-Squared: 0.995 F-statistic: 2965 on 1 and 15 degrees of freedom, the p-value is 0 Correlation of Coefficients: (Intercept) boil -0.9996 > #_________________________________________________________________________ > anova(bp.lm) Analysis of Variance Table Response: pressure Terms added sequentially (first to last) Df Sum of Sq Mean Sq F Value Pr(F) boil 1 425.6095 425.6095 2964.792 0 Residuals 15 2.1533 0.1436 > #_________________________________________________________________________ > resid(bp.lm) 1 2 3 4 5 6 -0.2465903 -0.0674978 -0.06116289 0.02110585 0.03564332 -0.04208794 7 8 9 10 11 12 13 0.05244954 0.05335703 -0.1552817 -0.07573547 -0.1452993 1.359238 0.001471823 14 15 16 17 -0.3226119 -0.2430832 -0.07763824 -0.08627699 > #_________________________________________________________________________ > #CONFIDENCE INTERVAL FOR BETA_1 > > a<-qt(.975,15)*0.0164 #read std error from output > #for better accuracy, compute standard error directly > a<-qt(.975,15)*sqrt((sum(bp.lm$resid^2)/15)/sum((bp$boil-mean(bp$boil))^2)) > #for even more accuracy, see appendix of Weisberg, "Applied Linear > # Regression" > > #95% C.I. > c(bp.lm$coef[2]-a,bp.lm$coef[2]+a) boil boil 0.8604095 0.9305155 > #_________________________________________________________________________ > #PREDICTION/ESTIMATION > fitted(bp.lm) 1 2 3 4 5 6 7 8 132.0366 131.8575 135.0812 135.5289 136.4244 136.8721 137.7676 137.9466 9 10 11 12 13 14 15 16 138.2153 138.1257 140.1853 141.0808 145.4685 144.6626 146.5431 147.6176 17 147.8863 > #Prediction for a new value of X: > > predict(bp.lm,newdata=data.frame(boil=200)) 1 136.9616 >