Page 1 of 1

Coding covariates for Epsilon and Gamma in RPresence

PostPosted: 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,

Re: Coding covariates for Epsilon and Gamma in RPresence

PostPosted: Thu Nov 14, 2019 8:56 pm
by jhines
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

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

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

           data=data,type="do.1",outfile='modname'); # run model psi(hab)gam(veg)eps()p()...


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.

Re: Coding covariates for Epsilon and Gamma in RPresence

PostPosted: 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


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,

Re: Coding covariates for Epsilon and Gamma in RPresence

PostPosted: Sat Nov 30, 2019 9:18 am
by jhines
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

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


Re: Coding covariates for Epsilon and Gamma in RPresence

PostPosted: 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,