# # EPage 215 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- #install.packages("MPV") library(lattice) # needed for xyplot library(DAAG) library(MPV) set.seed(0) n_pts = 10000 x1 = runif(n_pts) #x2 = rbinom(n_pts, 1, 1-x1) #x2 = rbinom(n_pts, 1, x1) x2 = rbinom(n_pts, 1, 0.5) y = 5 * x1 + x2 + rnorm(n_pts, sd=0.1) y.lm = lm( y ~ factor(x2) ) coef(y.lm) y.lm2 = lm( y ~ x1 + factor(x2) ) coef(y.lm2)