Page 1 of 1
Loop to run combinations of single-season models
Posted:
Thu Apr 16, 2020 3:18 pm
by BT_nwt
Has anyone developed a loop in RPresence to run different combinations of covariates for a single-season model (i.e., equivalent of dredge)?
If yes, it would be great if you could share this code or provide advice. I can run models in RPresence but because I have not written loops before in R I'm struggling to figure this out.
Thanks
Re: Loop to run combinations of single-season models
Posted:
Thu Apr 16, 2020 4:30 pm
by jhines
- Code: Select all
# load a PRESENCE data file...
# This is a file created by Presence and saved as a "pao" file
#
# The file contains the detection-history data, a habitat covariate (Browsed),
# and 3 observer survey covariates (obs1, obs2, obs3). The site covariate
# (Browsed) is an indicator covariate indicating if the site was browsed by goats,
# which would affect the shrubbery where the weta reside. The observer covariates
# are indicator covariates (1 or 0) indicating which observer collected the data
# for that site/survey.
filename<-system.file("extdata/weta.pao",package="RPresence")
weta.data<-readPao(filename)
## fit some models
modelset=list(); modelcount=0 # initialize list of models
# loop for psi models... ~1=psi(.), ~Browsed=psi(Browsed)
for (psi in c(psi~1, psi~Browsed)) {
# loop for p models... Intercept, Observer, Survey, Survey+observer
for (p in c(p~1, p~Obs2+Obs3, p~SURVEY, p~SURVEY+Obs2+Obs3)) {
modelcount=modelcount+1
modelset[[modelcount]] <- occMod(model=list(psi, p),data=weta.data,type="so")
}
}
## create AIC table
results<-createAicTable(modelset)
print(summary(results))
Re: Loop to run combinations of single-season models
Posted:
Thu Apr 16, 2020 4:38 pm
by jhines
I've provided some example code to loop through possible combinations of models for psi and p, but keep in mind that if you try a lot of covariates, you can end up with a model with significant effects by random chance. So, it's important to have a hypothesis about each covariate you include in your model-set and not "dredge" to see what comes out on top.
Re: Loop to run combinations of single-season models
Posted:
Thu Apr 16, 2020 6:35 pm
by BT_nwt
Thanks, jhines. I certainly appreciate the code and understand your warning regarding "dredging" for the top model. I am using a subset of my broader covariate set, based on hypotheses to run my models. This loop should help make the process a little faster. If I run into problems I'll let you know.
Thanks again,
BT_nwt