Coding covariates for Epsilon and Gamma in RPresence

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

Coding covariates for Epsilon and Gamma in RPresence

Postby chadbera@gmail.com » Wed Nov 13, 2019 10:36 pm

Hi guys,

I have been looking everywhere on how to add in covariates to model against Epsilon and Gamma in a multi-season model, and haven't found anything yet.

From my understanding, site specific co-variates can vary from year to year.

In my study I have 148 sites which are surveyed 5 times a year for 8 years. I have 4 site covariates which are central to the hypothesis I am testing, and they vary from year to year at each site. An example is vegetation cover. I would like to model such variables against Epsilon and Gamma.

In the createPao function, it says "data frame for unit-specific covariates (e.g., habitat, elevation, etc.) with 1 row per unit (so nrow(unitcov) == nrow(data))". It doesn't say how to treat Epsilon and Gamma covariates so I have assumed it would be supplied as one variable for each column, and therefore with 148 sites over 8 years, each column for each variable would contain 1,184 rows, just like in covariates for detection probability, each row is a variable, and in this instance it is 148*5*8 = 5,920 rows for each covariate.

However, I cannot get any models to run with a Pao object where the site covariates are included in the way I have described above.

Any ideas on what I am missing? Any help or advice would be hugely appreciated!

Thanks in advanced.

Kind regards,
Chad
chadbera@gmail.com
 
Posts: 3
Joined: Sat Jul 27, 2019 5:06 am

Re: Coding covariates for Epsilon and Gamma in RPresence

Postby jhines » Thu Nov 14, 2019 8:56 pm

Here's an example of how to add seasonal covariates to a multi-season model:

Code: Select all
#===========================================================
#  test multi-season model using "Skinks" data
library(RPresence)

data<-readPao(system.file('extdata/skinks.pao',package="RPresence")) # read pao object (created w/ PRESENCE)
data$unitcov$habitat[data$unitcov$Tussock==1]<-"tussock"             # create "habitat" covariate
data$unitcov$habitat[data$unitcov$Pasture==1]<-"pasture"

m0<-occMod(model=list(psi~1,gamma~1,epsilon~1,p~1),data=data,type="do.1");  #  run model (psi()gam()eps()p())

  #  make up seasonal, site-specific covariate to be used for estimation of gamma's

vegcov1=runif(data$nunits) # veg cover for season 1
vegcov2=runif(data$nunits) # veg cover for season 2
vegcov3=runif(data$nunits) # veg cover for season 3
vegcov4=runif(data$nunits) # veg cover for season 4
newcov=data.frame(veg=c(vegcov1,vegcov2,vegcov3,vegcov4))

m3<-occMod(model=list(psi~habitat,gamma~veg,epsilon~1,p~1),
           cov.list=list(gamma.cov=newcov),
           data=data,type="do.1",outfile='modname'); # run model psi(hab)gam(veg)eps()p()...

modtbl=createAicTable(list(m0,m1,m2,m3))
print(modtbl$table)


Another way to do it would be to create a survey covariate where the first N*S values correspond to the seasonal covariate (N=number of sites, S=number of seasons-1). The rest of the survey covariate should be 0's. If done this way, you don't need to create a new data-frame as the covariate will be included in the survey-covariate data-frame. Presence will only use the first N*S values for the estimation of gamma's.
jhines
 
Posts: 471
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA

Re: Coding covariates for Epsilon and Gamma in RPresence

Postby chadbera@gmail.com » Fri Nov 29, 2019 11:46 pm

Thanks Jim!

I was able to run your example successfully, however when I try to use the same approach with my own data, I get an error. I have double-checked carefully that the unit covariates line up with my detection data, and I have used the variable from seasons 2 - 8 and I understand season 1 gets modeled with Psi.

Code: Select all
###Upload unit covariates###

ephem.cov<-read.csv(file="ephem_unitcovar.csv",header=FALSE, na.strings="NA")

ephemcov2=ephem.cov[2] #  season 2
ephemcov3=ephem.cov[3] #  season 3
ephemcov4=ephem.cov[4] #  season 4
ephemcov5=ephem.cov[5] #  season 5
ephemcov6=ephem.cov[6] #  season 6
ephemcov7=ephem.cov[7] #  season 7
ephemcov8=ephem.cov[8] #  season 8
ephemcov=data.frame(ephem=c(ephemcov2,ephemcov3,ephemcov4,ephemcov5,ephemcov6,ephemcov7,ephemcov8))

testm1<-occMod(model=list(psi~1,gamma~ephemcov$ephem,epsilon~1,p~1),
                 data=ggbfcall,cov.list=list(ephemcov),type="do.1",outfile='modname')



The error is:
Code: Select all
Error in model.frame.default(object, data, xlev = xlev) :
  invalid type (NULL) for variable 'ephemcov$ephem'


Is there perhaps something I need to do regarding incorporating the new dataframe (which I have called "ephemcov"), into the pao (which I have called "ggbfcall")?

Once again, I really appreciate the help, thanks Jim.

Kind regards,
Chad
chadbera@gmail.com
 
Posts: 3
Joined: Sat Jul 27, 2019 5:06 am

Re: Coding covariates for Epsilon and Gamma in RPresence

Postby jhines » Sat Nov 30, 2019 9:18 am

From the message, my guess is that the covariate is being read in as a 'character' variable with the read.csv function. You can test for this by using the R function, 'str'. After the read.csv command, add 'str(ephem.cov)' to see the data type of the variable. If any of the values in the csv file are not numeric, read.csv will treat it as character. For example, if you have "-" or "." to indicate missing data, that will cause read.csv to treat them as character. If that's the case, you can modify the read.csv command to:

Code: Select all
ephem.cov<-read.csv(file="ephem_unitcovar.csv",header=FALSE, na.strings="-")


If you have more than one value in the data indicating missing data, you can convert to numeric by changing the code to:

Code: Select all
ephemcov=data.frame(ephem=as.numeric(c(ephemcov2,ephemcov3,ephemcov4,ephemcov5,ephemcov6,ephemcov7,ephemcov8)))


If that doesn't solve the problem, send me the code and data files.

Jim
jhines
 
Posts: 471
Joined: Fri May 16, 2003 9:24 am
Location: Laurel, MD, USA

Re: Coding covariates for Epsilon and Gamma in RPresence

Postby chadbera@gmail.com » Sat Nov 30, 2019 10:44 pm

Hey Jim,

I got the code to work, and as you said, the problem was due to one of the seasons being read in as a character. Thanks for clarifying that!

One last thing I wanted to ask about, when using an external dataframe for adding covariates against epsilon/gamma, what is the best way to produce a graph of the response, say in the example below, ephem vs epsilon (probability of local extinction)?

I have seen in other posts of a similar topic, that you can only graph epsilon/gamma from season to season, and therefore in my situation, I could have potentially 7 graphs for each. However, I was wondering if it would be valid to somehow incorporate the response of all 7 and produce some kind of average response, so I can present just one graph? Furthermore, I know in my dataset, there are some seasons with quite a bit more missing data then others, so perhaps the seasons with more data would be more informative and a weighted model averaging approach might suit?

I have seen in some papers (a limited amount), that they have produced one graph that shows the response of a certain variable to epsilon/gamma. I would be very keen to hear of your opinions on if this is valid and how one might go about doing it.

Kind regards,
Chad
chadbera@gmail.com
 
Posts: 3
Joined: Sat Jul 27, 2019 5:06 am


Return to RPresence

Who is online

Users browsing this forum: No registered users and 1 guest

cron