{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw5 code - halfnormalplot(2*coef(g2-1 label=T n=3 Dantzig...

This preview shows pages 1–3. Sign up to view the full content.

dat=read.table("http://www.stat.ucla.edu/~hqxu/stat201A/data/asat2.dat", h=T) g=lm(Asat ~ A+B+C+D+E+F+G+H+K, dat); summary(g) #only D is significant, C is significant at 10% g=lm(Asat ~ D, dat); summary(g) #R^2 = 0.3638, does not fit well g=lm(Asat ~ C+D, dat); summary(g) #R^2 = .5236, does not fit well g2=lm(Asat ~ .^2, dat); g2 # use all 11 columns to get the correct aliasing alias(g2) # complex aliasing #[A]--> A+2(BK+CH+DF+EG) g2=lm(Asat ~ C+D+F, dat); summary(g2) #R^2= 64% g2=lm(Asat ~ C+D+F+E+H, dat); summary(g2) #R^2= 74% g2=lm(Asat ~ B:K+C:H+D:F+E:G, dat); summary(g2) source("http://www.stat.ucla.edu/~hqxu/stat201A/R/halfnormal.R") normalplot(2*coef(g2)[-1], l=T, n=5, ylim=c(-20, 25)) halfnormalplot(2*coef(g2)[-1], l=T, n=5)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
par(mfrow=c(1,2))
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: halfnormalplot(2*coef(g2)[-1], label=T, n=3) # Dantzig selector library(lpSolve) # require the package(lpSolve) source("http://www.stat.ucla.edu/~hqxu/stat201A/R/DS.R") # if online Asat=dat\$Asat; Asatc = Asat-mean(Asat); X1=dat[,1:9]; dim(X1) # main effects model b= DS(X1, Asatc, seq(0, 8, .1) ); b # X1 is not normalized b= DS(X1/sqrt(16), Asatc, seq(0, 2, .1) ); # normalized to length 1 g=lm(Asat ~ .^2-1, dat[,1:9]) X2 = model.matrix(g); dim(X2) # main effects plus 2-factor interactions model b = DS(X2, Asatc, seq(0, 8, .1) ); b g2=lm(Asat ~ C+D+A:B+A:C+A:E+A:K+B:C+B:G+B:H+B:K, dat); summary(g2) #r^2=98% #final model g2=lm(Asat ~ D+A:B+A:C+A:E+B:G+B:H+B:K, dat); summary(g2) # AE is signficant at 5% #r^2=94% #2...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

hw5 code - halfnormalplot(2*coef(g2-1 label=T n=3 Dantzig...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online