Loop to run combinations of single-season models

posts related to the RPresence library, which may not be of general interest to users of 'classic' PRESENCE.

Loop to run combinations of single-season models

Postby BT_nwt » Thu Apr 16, 2020 3:18 pm

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
BT_nwt
 
Posts: 2
Joined: Thu Apr 16, 2020 2:49 pm

Re: Loop to run combinations of single-season models

Postby jhines » Thu Apr 16, 2020 4:30 pm

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))
jhines
 
Posts: 506
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA

Re: Loop to run combinations of single-season models

Postby jhines » Thu Apr 16, 2020 4:38 pm

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.
jhines
 
Posts: 506
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA

Re: Loop to run combinations of single-season models

Postby BT_nwt » Thu Apr 16, 2020 6:35 pm

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
BT_nwt
 
Posts: 2
Joined: Thu Apr 16, 2020 2:49 pm


Return to RPresence

Who is online

Users browsing this forum: No registered users and 2 guests