> source("http://www.utstat.utoronto.ca/reid/sta442f/ExGdata.R") > ls() [1] "nuclear" > nuclear[1:3,] cost date T1 T2 cap PR NE CT BW N PT 1 460.05 68.58 14 46 687 0 1 0 0 14 0 2 452.99 67.33 10 73 1065 0 0 1 0 1 0 3 443.22 67.33 10 85 1065 1 0 1 0 1 0 > ## note the names are a little different than in the handout > # if a file has ".R" at the end then it is in "R-speak" > nuclear$cost[1] [1] 460.05 > cost[1] Error: object "cost" not found > attach(nuclear) # easier to use variable names, although not necesssary > cost[1] [1] 460.05 > nuclear10.lm = lm(log(cost) ~ date+log(T1)+log(T2)+log(cap)+PR+NE+CT+BW+log(N)+PT, data=nuclear) > # the "data = "nuclear" is not needed, because nuclear is attached > # but if nuclear was not attached, it would be handy > detach(nuclear) > nuclear10.lm = lm(log(cost) ~ date+log(T1)+log(T2)+log(cap)+PR+NE+CT+BW+log(N)+PT) Error in eval(expr, envir, enclos) : object "cost" not found > nuclear10.lm = lm(log(cost) ~ date+log(T1)+log(T2)+log(cap)+PR+NE+CT+BW+log(N)+PT, data = nuclear) > summary(nuclear10.lm) Call: lm(formula = log(cost) ~ date + log(T1) + log(T2) + log(cap) + PR + NE + CT + BW + log(N) + PT, data = nuclear) Residuals: Min 1Q Median 3Q Max -0.28574 -0.10408 0.02784 0.09512 0.25031 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -14.24198 4.22880 -3.368 0.00291 ** date 0.20922 0.06526 3.206 0.00425 ** log(T1) 0.09187 0.24396 0.377 0.71025 log(T2) 0.28553 0.27289 1.046 0.30731 log(cap) 0.69373 0.13605 5.099 4.75e-05 *** PR -0.09237 0.07730 -1.195 0.24542 NE 0.25807 0.07693 3.355 0.00300 ** CT 0.12040 0.06632 1.815 0.08376 . BW 0.03303 0.10112 0.327 0.74715 log(N) -0.08020 0.04596 -1.745 0.09562 . PT -0.22429 0.12246 -1.832 0.08125 . --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: 0.1645 on 21 degrees of freedom Multiple R-squared: 0.8717, Adjusted R-squared: 0.8106 F-statistic: 14.27 on 10 and 21 DF, p-value: 3.081e-07 > nuclear6.lm = update(nuclear10.lm, .~. - BW - log(T1)-log(T2)-PR) > anova(nuclear6.lm) Analysis of Variance Table Response: log(cost) Df Sum Sq Mean Sq F value Pr(>F) date 1 1.75252 1.75252 69.134 1.155e-08 *** log(cap) 1 0.74469 0.74469 29.377 1.262e-05 *** NE 1 0.46471 0.46471 18.332 0.0002398 *** CT 1 0.29566 0.29566 11.663 0.0021827 ** log(N) 1 0.43624 0.43624 17.209 0.0003382 *** PT 1 0.10051 0.10051 3.965 0.0574895 . Residuals 25 0.63374 0.02535 --- > plot(nuclear6.lm, which=1:4) Hit to see next plot: Hit to see next plot: Hit to see next plot: Hit to see next plot: > plot(nuclear6.lm) Hit to see next plot: Hit to see next plot: Hit to see next plot: Hit to see next plot: > ?plot.lm > plot(nuclear6.lm, which=1:6) Hit to see next plot: Hit to see next plot: Hit to see next plot: Hit to see next plot: Hit to see next plot: Hit to see next plot: