Occasion-specific covariates in Nest Survival

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

Occasion-specific covariates in Nest Survival

Postby jwarren » Wed Nov 17, 2010 6:44 pm

I have 4 years of nest data that I'm trying to model using an occasion-specific covariate that also differs among years. There are 66 occasions each year. I have coded each year as a dummy variable, and created vectors of values (n=66) for each year's occasions. Where to go from here eludes me, though. Any input would be appreciated.

Thanks,

Jeff
jwarren
 
Posts: 11
Joined: Tue Nov 25, 2008 11:33 am
Location: Lakeview, Montana

Re: Occasion-specific covariates in Nest Survival

Postby jlaake » Wed Nov 17, 2010 7:19 pm

Jeff-

I'm not following your query. Please give a more complete explanation and maybe a few lines of your data. When you say occasion-specific covariates, did you use merge.design.covariates or did you put these with the data? If you did the latter then they are effectively individual nest covariates. If they are truly occasion-specific then they should be in the design data rather than with the nest data.

--jeff
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Occasion-specific covariates in Nest Survival

Postby jwarren » Wed Nov 17, 2010 8:17 pm

They are occasion-specific data that also vary by year (2007-10). I couldn't figure out how to get them into the design data, thus my problem. The data are occasion-specific (i.e., day-specific) small mammal abundances, which increases through the nesting season each year similar to nesting success on the study site.

Here are 2 example nesting success models:
#2. DSR varies by year
year<-mark(lesc, nocc=66, model="Nest", model.parameters=list(S=list(formula=~y2007 + y2008 + y2009 + y2010)))

#3. DSR varies by time
time<-mark(lesc, nocc=66, model="Nest", model.parameters=list(S=list(formula=~Time)))

Here is what my nest data look like (I don't have small mammal data for 2006, so am just using 2007-10 for this analysis):
FirstFound LastPresent LastChecked Fate NestYear NestNumber Init CS y2006 y2007 y2008 y2009 y2010
1 1 19 19 0 2006 1 142 8 1 0 0 0 0
2 10 10 17 1 2006 2 159 NA 1 0 0 0 0
3 14 35 35 0 2006 3 158 8 1 0 0 0 0
4 15 15 22 1 2006 4 165 9 1 0 0 0 0
5 15 22 29 1 2006 5 159 4 1 0 0 0 0
6 15 22 31 1 2006 6 153 NA 1 0 0 0 0

My small mammal abundance data are from 2007-10. I've predicted daily small mammal abundance for each year based on another project that runs concurrent to our nest monitoring. For each year I've created a vector (n=66 for each year) of small mammal abundances by day, for example here is 2007's occasion-specific abundances:
> Sm.ab.07
[1] 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997
[16] 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997 90.18997
[31] 90.18997 90.18997 90.18997 90.12000 106.89000 123.66000 140.43000 157.20000 173.97000 190.74000 207.51000 224.28000 241.05000 257.82000 274.59000
[46] 291.36000 308.13000 324.90000 341.65000 355.21000 368.77000 382.33000 395.89000 409.45000 423.01000 436.57000 450.13000 463.69000 477.25000 490.81000
[61] 504.37000 517.93000 531.49000 545.05000 558.61000 572.17000

I hope this makes sense. Thanks for your assistance.

Jeff
jwarren
 
Posts: 11
Joined: Tue Nov 25, 2008 11:33 am
Location: Lakeview, Montana

Re: Occasion-specific covariates in Nest Survival

Postby jlaake » Wed Nov 17, 2010 11:40 pm

If you make NestYear a factor variable and use it to define groups (eg groups="NestYear" in process.data) then you can use ~NestYear in place of the dummy variables you created. Also, then you can create a database of the small mammal abundances with a field group which contains the year value and then time for each occasion and a field called smabundance (or whatever you call it). Then with merge.design.covariates you can merge those values based on group and time into your design data. Then you should be able to use ~smabundance to fit that model. Make sure to read the help file for ?merge.design.covariates as I'm doing some of this from memory on the fly. It has an example and I think this may be covered in the workshop notes posted on the RMark web page on phidot.

Hope that helps.

--jeff
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Occasion-specific covariates in Nest Survival

Postby jwarren » Thu Nov 18, 2010 1:25 pm

Thanks - I was able to modify the design data as you described so that I have occasion-specific data. However, I'm back to my original problem (post from No. 11th that you replied to) of getting the following error:

Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 238, 0

This seems to happen whenever I use "NestYear" as a grouping variable (or any other group, for that matter). I was able to get around it earlier with dummy coded years (as numeric, not factors) instead of a group covariate. This doesn't seem to be an issue when I run the mallard example, so there must be something specific to my dataframe that is causing the problem. What is particularly confusing is that I can run Jay's mallard example with his dummy coded habitats as factors (as he does), but I have to run my dummy coded years as numeric or I get the same error above. I've tried both data sets and models on older and the newest versions of R and RMark.

Perhaps the following error will be telling. When I run a model with "NestYear" as a variable I get this error:
Error in make.mark.model(data.proc, title = title, covariates = covariates, :
The following individual covariates are not allowed because they are factor variables: NestYear

I have specified "NestYear" as a group in the process.data statement:
lesc.process<-process.data(lesc, model="Nest", begin.time=1, nocc=66, groups="NestYear")
lesc.ddl<-make.design.data(lesc.process)

And a model with a time trend runs fine:
time.trend<-mark(lesc, nocc=66, model="Nest", model.parameters=list(S=list(formula=~Time)))

Thanks,

Jeff
jwarren
 
Posts: 11
Joined: Tue Nov 25, 2008 11:33 am
Location: Lakeview, Montana

Re: Occasion-specific covariates in Nest Survival

Postby jlaake » Fri Nov 19, 2010 6:51 pm

Jeff and I worked this out offlist. There was an issue with the code in using groups with the Nest survival model. I've patched the code and sent him an updated version. I'll post the new version after I've done some more testing. However, if anyone else has been experiencing the same problem, let me know and I'll send you the interim patch.
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Occasion-specific covariates in Nest Survival

Postby mikeak » Thu Oct 20, 2011 3:55 pm

Hi,
I came across these posts, and I'm having a similar problem. I have a similar dataset as Jeff with 4 years of nest survival data that I am trying to model with occasion (time) specific covariates (as well as other nest covariates such as nest height). The time specific variables I'm dealing with are daily mean temperatures, precepitation, and vegetation leaf lengths, which should be grouped for nests (like in Jeff's example) by year. I recently downloaded the lastest version of RMark. Has the code been fixed to use groups (without using dummy variables - which seems to work) in the nest survival model?

I am getting a similar error as Jeff had (note I don't have 2011 data here):

Code: Select all
> z$year<-as.factor(z$year)
> Year=mark(z,nocc=78,model="Nest", model.parameters=list(S=list(formula=~year)),
+ groups=c("year2008","year2009","year2010"))
Error in make.mark.model(data.proc, title = title, covariates = covariates,  :
  The following individual covariates are not allowed because they are factor variables:  year


Also, after following your post, I was able to use merge_design.covariates to merge the weather data with the z.ddl$S (design data?), to group the precip and temperature covariates by year.

Code: Select all
 
z$year<-as.factor(z$year)
> z.process<-process.data(z, model="Nest", nocc=78, groups="year")
> z.ddl<-make.design.data(z.process)
>
> zz<-merge_design.covariates(z.ddl$S,weather, bygroup=TRUE)
> tail(zz)
    group time age Age Time year         X precip maxtemp meantemp mintemp
226  2010   72  71  71   71 2010 25-Jul-10      0    88.2 76.33750    64.4
227  2010   73  72  72   72 2010 26-Jul-10      0    83.7 66.56667    47.8
228  2010   74  73  73   73 2010 27-Jul-10      0    91.6 69.48750    48.2
229  2010   75  74  74   74 2010 28-Jul-10      0    90.7 73.02083    50.9
230  2010   76  75  75   75 2010 29-Jul-10      0    88.9 77.24167    64.2
231  2010   77  76  76   76 2010 30-Jul-10      0    83.8 64.94583    47.1
>


Now I am confused about how to run the model with zz, as this is the weather data grouped by year, and time is matched up, however this does not contain the nest survival data. Is this possible using the mark() function, or do I need to use the other functions (i.e. make.mark.model() ). I am relatively new to Mark and RMark, although I have been able to follow the mallard example and run other models with my data that work with Time, nest age, and nest-specific covariates. I tried to follow the RMARK appendix dealing with this (starting p.73), and I also looked at the RMark workshop notes-- However, if I create a vector of precipitation covariates for every time (with a prefix), i.e. precip1, precip2, etc. to put into the model, I don't see how these covariates can then be grouped by year?

Please let me know if you have any suggestions about this. I really appreciate any help. Thanks!

Mike
mikeak
 
Posts: 2
Joined: Wed Oct 19, 2011 2:23 pm

Re: Occasion-specific covariates in Nest Survival

Postby jlaake » Thu Oct 20, 2011 5:51 pm

Mike-

You don't yet understand how to use groups or the difference between your data -- capture histories etc and design data. The variable you use for groups= should be a factor variable like you did with

Code: Select all
z.process<-process.data(z, model="Nest", nocc=78, groups="year")


and not
Code: Select all
groups=c("year2008","year2009","year2010"))


When you did that and used ~year it tried to treat year as an individual covariate but it was a factor variable which cannot be used as an individual covariate. It would have worked if you did the following:
Code: Select all
 
mark(z,nocc=78,model="Nest", model.parameters=list(S=list(formula=~year)), groups="year")


With regard to your further query about merging occasion data, you should have done the following:
Code: Select all
z.process<-process.data(z, model="Nest", nocc=78, groups="year")
 z.ddl<-make.design.data(z.process)
 z.ddl$S <-merge_design.covariates(z.ddl$S,weather, bygroup=TRUE)
 mark(z.process,z.ddl,model.parameters=list(S=list(formula=~...)))


where you fill in the ... with a formula. Go back and re-read the sections that tell you how to use the mark function. There are 2 basic ways
1) mark(data,model="Nest",...)
2) mark(data.process, ddl,...)

In the first, you give it the data frame and arguments and it processes the data, creates the design data and runs the model. In the second more useful way, you create the processed data and the design data and call it with those arguments and the formulas etc. That is what you need to do when you use anthing other than the default design data.

--jeff
jlaake
 
Posts: 1479
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Occasion-specific covariates in Nest Survival

Postby mikeak » Sun Oct 23, 2011 2:09 pm

Hi Jeff,
After reading the manual again this makes more sense now. I got the model to run with your suggestions. Thanks!

Mike
mikeak
 
Posts: 2
Joined: Wed Oct 19, 2011 2:23 pm


Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest