############################################## # HOW TO USE THIS FILE # This file (ex5wt.R) can just be sourced # into the R program. But it is really intended to be used interactively # ######### ANY TEXT AFTER THE # CHARACTER ARE TREATED AS COMMENTS # # data stored in c:/GR/aprojects/peas/web/exemp3/data/ex5wt.Rdata # this file is c:/GR/aprojects/peas/web/exemp3/program_code/ex5wt_R.html # ############################################## # # data are in a data frame data # to get the names of the variables # names(data) # # look at the first 5 rows data[1:5,] # # now a logistic regression of response rates # only the final model is shown here though the other could readily be explored # resp<-glm(cbind(AyrA_num,npop)~agegrp+gender+agegrp*agegrp+agegrp*gender+agegrp*agegrp*gender+sinc+sacc+ agegrp*sinc+agegrp*agegrp*sinc,data=data,family=binomial) print(summary(resp)) # # we now get the linear predictor # lp<-predict(resp) # # and make it into a predicted probability # phat<-1/(1+exp(-lp)) # # and get the grossing weight and add to the data frame # data$gweight<-1/phat # # this can then be merged back to the main file #