###################hw 2###################################### ##prob 1 #regression line library(SDaA) library(survey) data(anthuneq) finger<-anthuneq$finger height<-anthuneq$height prob<-anthuneq$prob weight<-1/prob duneq<-svydesign(id=~1,weight=weight,data=anthuneq) duneq myfit<-svyglm(height~finger,design=duneq) myfit #jackknife fit b_0<-myfit$coef[1] b_1<-myfit$coef[2] slope<-rep(0,200) sum<-0 for(i in 1:200){ data<-anthuneq[-i,] prob<-data$prob wt<-(200/199)*(1/prob) duneq<-svydesign(id=~1,weight=wt,data=anthuneq[-i,]) fit1<-svyglm(height~finger,design=duneq) slope[i]<-fit1$coef[2] sum<-sum+(slope[i]-b_1)^2 } varjk<-(199/200)*sum varjk ##problem 2 library(survey) data(api) dapistrat<-svydesign(id=~1,strata=~stype,weight=~pw,data=apistrat,fpc=~fpc) nrow(apistrat) apistrat[1:2,] svyplot(api00~emer,design=dapistrat,xlab="emer",ylab="api00",style="bubble") myfit<-svyglm(api00~emer,design=dapistrat) summary(myfit) #What confounding variables measuring socioeconomic status of students should #be included in the model? #meals, not.hsg, hsg, some.col, col.grad,grad.sch, avg.ed help(apistrat) #to see the definitions of variables pairs(api00 ~ emer+meals+not.hsg+some.col+col.grad+grad.sch+avg.ed,data=apistrat) ##variable selection