# week 4 exercises # perform AIC on data from previous week # class data h <- c( 5*12+11 , 69 , 5*12+8 , 62,5*12+11,72,5*12+8,69,75,71,61,61,62,5*12+11 , 68,70,74,5*12+2,67,65.75 , 76 , 69 , 65 , 67 , 5*12+4 , 5*12+8 , 68 , 75 ) w <- c( 135,165,165,120,220,170,150,165,245,160,110,136,112,195,150,155,200,137,160,150,225,140,128,150,130,140,145,210 ) d <- data.frame( height=h , weight=w ) library(bbmle) m0 <- lm( d$height ~ 1 ) m1 <- lm( d$height ~ d$weight ) plot( d$height ~ d$weight ) abline(m1) abline(m0,col="red") fakew <- sample( min(d$weight):max(d$weight) , 100 , replace=TRUE ) k0 <- coef(m0) sd0 <- sd(residuals(m0)) hm0 <- rnorm( 100 , mean=k0["(Intercept)"] , sd=sd0 ) k1 <- coef(m1) sd1 <- sd(residuals(m1)) hm1 <- rnorm( 100 , mean=k1["(Intercept)"] + k1["d$weight"] * fakew , sd=sd1 ) plot( hm1 ~ fakew , xlab="weight" , ylab="height" , pch=16 ) points( fakew , hm0 ) AICtab( m0 , m1 , base=TRUE , weights=TRUE ) AICctab( m0 , m1 , base=TRUE , weights=TRUE , nobs=28 )