This report was automatically generated with the R package knitr (version 1.5).

library(faraway)
data(fat, package = "faraway")
lmod <- lm(brozek ~ age + weight + height + neck + chest + abdom + hip + thigh + 
    knee + ankle + biceps + forearm + wrist, data = fat)
x <- model.matrix(lmod)
(x0 <- apply(x, 2, median))
(Intercept)         age      weight      height        neck       chest 
       1.00       43.00      176.50       70.00       38.00       99.65 
      abdom         hip       thigh        knee       ankle      biceps 
      90.95       99.30       59.00       38.50       22.80       32.05 
    forearm       wrist 
      28.70       18.30 
(y0 <- sum(x0 * coef(lmod)))
[1] 17.49
predict(lmod, new = data.frame(t(x0)))
    1 
17.49 
predict(lmod, new = data.frame(t(x0)), interval = "prediction")
    fit   lwr   upr
1 17.49 9.618 25.37
predict(lmod, new = data.frame(t(x0)), interval = "confidence")
    fit   lwr   upr
1 17.49 16.94 18.04
(x1 <- apply(x, 2, function(x) quantile(x, 0.95)))
(Intercept)         age      weight      height        neck       chest 
       1.00       67.00      225.65       74.50       41.84      116.34 
      abdom         hip       thigh        knee       ankle      biceps 
     110.76      112.12       68.54       42.65       25.45       37.20 
    forearm       wrist 
      31.74       19.80 
predict(lmod, new = data.frame(t(x1)), interval = "prediction")
    fit   lwr   upr
1 30.02 21.92 38.11
predict(lmod, new = data.frame(t(x1)), interval = "confidence")
    fit   lwr   upr
1 30.02 28.07 31.97
data(airpass, package = "faraway")
plot(pass ~ year, airpass, type = "l", ylab = "Log(Passengers)")
lmod <- lm(log(pass) ~ year, airpass)
lines(exp(predict(lmod)) ~ year, airpass)

plot of chunk unnamed-chunk-1

lagdf <- embed(log(airpass$pass), 14)
colnames(lagdf) <- c("y", paste0("lag", 1:13))
lagdf <- data.frame(lagdf)
armod <- lm(y ~ lag1 + lag12 + lag13, data.frame(lagdf))
sumary(armod)
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   0.1385     0.0536    2.58    0.011
lag1          0.6923     0.0619   11.19  < 2e-16
lag12         0.9215     0.0347   26.53  < 2e-16
lag13        -0.6321     0.0677   -9.34  4.2e-16

n = 131, p = 4, Residual SE = 0.04, R-Squared = 0.99
plot(pass ~ year, airpass, type = "l")
lines(airpass$year[14:144], exp(predict(armod)), lty = 2)

plot of chunk unnamed-chunk-1

lagdf[nrow(lagdf), ]
        y  lag1  lag2 lag3  lag4  lag5  lag6  lag7  lag8  lag9 lag10 lag11
131 6.068 5.966 6.133 6.23 6.407 6.433 6.282 6.157 6.133 6.038 5.969 6.033
    lag12 lag13
131 6.004 5.892
predict(armod, data.frame(lag1 = 6.0684, lag12 = 6.0331, lag13 = 6.0039), interval = "prediction")
    fit   lwr   upr
1 6.104 6.021 6.187

The R session information (including the OS info, R version and all packages used):

sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] graphics  grDevices utils     datasets  methods   stats     base     

other attached packages:
[1] faraway_1.0.6   knitr_1.5       ggplot2_0.9.3.1

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4   dichromat_2.0-0    digest_0.6.4      
 [4] evaluate_0.5.3     formatR_0.10       grid_3.1.0        
 [7] gtable_0.1.2       labeling_0.2       MASS_7.3-31       
[10] munsell_0.4.2      plyr_1.8.1         proto_0.3-10      
[13] RColorBrewer_1.0-5 Rcpp_0.11.1        reshape2_1.2.2    
[16] scales_0.2.3       stringr_0.6.2      tools_3.1.0       
Sys.time()
[1] "2014-06-16 14:01:24 BST"