by jlaake » Fri Nov 13, 2009 1:45 am
You need to spend some time working through the Appendix and the workshop material and learning some more R. But in the meantime,here is an example that uses the weta example for occupancy model. Only the code below the #### row is relevant to your question. Everything above that is from the weta example.
data(weta)
# Create function to fit the 18 models in the book
fit.weta.models=function()
{
# use make.time.factor to create time-varying dummy variables Obs1 and Obs2
# observer 3 is used as the intercept
weta=make.time.factor(weta,"Obs",1:5,intercept=3)
# Process data and use Browse covariate to group sites; it could have also
# been used an individual covariate because it is a 0/1 variable.
weta.process=process.data(weta,model="Occupancy",groups="Browse")
weta.ddl=make.design.data(weta.process)
# time factor variable copied to Day to match names used in book
weta.ddl$p$Day=weta.ddl$p$time
# Define p models
p.dot=list(formula=~1)
p.day=list(formula=~Day)
p.obs=list(formula=~Obs1+Obs2)
p.browse=list(formula=~Browse)
p.day.obs=list(formula=~Day+Obs1+Obs2)
p.day.browse=list(formula=~Day+Browse)
p.obs.browse=list(formula=~Obs1+Obs2+Browse)
p.day.obs.browse=list(formula=~Day+Obs1+Obs2+Browse)
# Define Psi models
Psi.dot=list(formula=~1)
Psi.browse=list(formula=~Browse)
# Create model list
cml=create.model.list("Occupancy")
# Run and return marklist of models
return(mark.wrapper(cml,data=weta.process,ddl=weta.ddl))
}
weta.models=fit.weta.models()
##################################################################################
# create dataframe of real estimates for all weta models
estimates=sapply(weta.models[1:nrow(weta.models$model.table)],function(x)
c(summary(x,se=T)$real$p$estimate,summary(x,se=T)$real$Psi$estimate))
estimates=t(estimates)
colnames(estimates)=c(row.names(summary(weta.models[[1]],se=T)$real$p),row.names(summary(weta.models[[1]],se=T)$real$Psi))
# create dataframe of std error of real estimates for all weta models
se.estimates=sapply(weta.models[1:nrow(weta.models$model.table)],function(x)
c(summary(x,se=T)$real$p$se,summary(x,se=T)$real$Psi$se))
se.estimates=t(se.estimates)
colnames(se.estimates)=c(row.names(summary(weta.models[[1]],se=T)$real$p),row.names(summary(weta.models[[1]],se=T)$real$Psi))