DSR with precipitation data

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

DSR with precipitation data

Postby chasingbirds » Wed Mar 11, 2020 10:46 am

Hi everyone,
I'm trying to use rMark to analyze DSR over an elevation gradient with precipitation data (which I realize will be correlated). I have nests from 200m-1,200m in elevation, and average daily precipitation data over the course of the season at 200m, 500m, 800m, and 1,200m. I'm trying to figure out how to best use this in my analysis. I have one year of data. Here are some of the main questions I have:
1. Should I bin/categorize the elevations into 4 groups (lowest, low, medium, high) and then bin my nests and the precipitation data in the same way? OR,
2. Since the nests are all found and monitored at different points during the season, how do I match up FirstFound precip data with, say, LastPresent?

Really any help would be great. I've tried to find some guidance from the workbook but have had no luck. Also, I've read through Carl's code a bunch (http://people.stat.sfu.ca/~cschwarz/Sta ... ts-04.html) but again, it seems like my data should be handled/analyzed differently.

Thanks in advance!
chasingbirds
 
Posts: 6
Joined: Wed Dec 11, 2019 1:08 pm

Re: DSR with precipitation data

Postby Rotella » Wed Mar 11, 2020 2:12 pm

I would consider entering the actual elevation of each nest as an individual covariate in your input file.

You could use the design data tools in RMark to bring in the daily precipitation data for each day of your nesting season. To do so, first create the design data with the 'make.design.data' function, then with your precipitation data stored as an object in R, add it to the design data with the 'add.design.data' function.
Rotella
 
Posts: 64
Joined: Mon Jun 09, 2003 11:32 am

Re: DSR with precipitation data

Postby jlaake » Wed Mar 11, 2020 5:51 pm

Add.design.data is only useful for binning certain types of existing design data like age, time and cohort. You want to use merge_design.covariates.
jlaake
 
Posts: 1295
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: DSR with precipitation data

Postby jlaake » Thu Mar 12, 2020 6:57 pm

Here is an example with some randomly generated temp data using the mallard data. If you had more than one variable you would just add it to the dataframe.

Code: Select all
data(mallard)
mallard$habitat <- ifelse(mallard$Native == 1, "Native",
ifelse(mallard$Planted == 1, "Planted",
ifelse(mallard$Roadside == 1, "Roadside",
"Wetland")))
# make the new variable a factor
mallard$habitat <- as.factor(mallard$habitat)
mallard.pr <- process.data(mallard,
nocc=90,
model="Nest",
groups=("habitat"))
mallard.ddl=make.design.data(mallard.pr)
#By time
temp=data.frame(time=1:89,temp=rnorm(89,0,10))
mallard.ddl$S=merge_design.covariates(mallard.ddl$S,temp)
head(mallard.ddl$S[mallard.ddl$S$time%in%1:3,],12)
mallard.ddl$S$temp=NULL
#by time and group
temp=data.frame(time=rep(1:89,4),temp=rnorm(89*4,0,10),group=rep(levels(mallard$habitat),each=89))
mallard.ddl$S=merge_design.covariates(mallard.ddl$S,temp,bygroup=TRUE)
head(mallard.ddl$S)
head(mallard.ddl$S[mallard.ddl$S$time%in%1:3,],12)
# run a dummy model
mark(mallard.pr,mallard.ddl,model.parameters=list(S=list(formula=~temp)))
jlaake
 
Posts: 1295
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: DSR with precipitation data

Postby chasingbirds » Tue Mar 31, 2020 1:44 pm

Great, thanks all for your help!
I'm currently trying to use merge_design.covariates with one dataframe of precipitation data. Again, I have 4 separate elevations that I'm interested in, so I have cumulative precipitation (in mm) for each elevation of interest across the season, collected using rain gauges. The dataframe for my precipitation data looks like this:
Code: Select all
> str(precipit)
'data.frame':   292 obs. of  5 variables:
 $ Date     : Factor w/ 73 levels "5/18/2019","5/19/2019",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ site     : Factor w/ 2 levels "BEF","JEFF": 1 1 1 1 1 1 1 1 1 1 ...
 $ elevation: int  281 281 281 281 281 281 281 281 281 281 ...
 $ precip   : num  1.2 0 19.7 0 0 0 4.2 0 2.2 0 ...
 $ time     : int  1 2 3 4 5 6 7 8 9 10 ...


And for my nest survival data, is as such:

Code: Select all

> str(nestdata1)
'data.frame':   32 obs. of  9 variables:
 $ NestID     : Factor w/ 33 levels "","BEFDK2","BEFHT6",..: 19 4 9 18 32 17 21 13 24 12 ...
 $ FirstFound : int  11 12 8 1 17 13 25 21 21 32 ...
 $ LastPresent: int  19 18 22 24 26 26 30 26 26 32 ...
 $ LastChecked: int  22 24 25 27 28 28 30 31 31 32 ...
 $ Fate       : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 1 2 2 1 ...
 $ Year       : Factor w/ 3 levels "2016","2018",..: 1 3 2 1 3 3 1 3 3 2 ...
 $ elevation  : int  577 329 746 638 730 869 779 567 881 1094 ...
 $ AgeFound   : int  5 5 5 8 2 6 11 18 17 27 ...
 $ NestAge    : int  -6 -7 -3 7 -15 -7 -14 -3 -4 -5 ...


I'm getting an error when I'm running the code that was given in the example in the last post:

Code: Select all
> nestdata1.pr<- process.data(nestdata1, nocc=59, model="Nest")
> nestdata.ddl=make.design.data(nestdata1.pr)
> #by precip
> nestdata.ddl$S=merge_design.covariates(nestdata.ddl$S, precipit) #getting errors
Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length


I'm thinking this is because of the way I have my precipitation dataframe organized/structured. I'm unsure of how to proceed. I thought I should make each elevation its own column, because currently, this is how my data is loaded in the dataframe:

Date site elevation precip time
5/18/2019 BEF 281 1.2 1
5/19/2019 BEF 281 0.0 2
5/20/2019 BEF 281 19.7 3
5/21/2019 BEF 281 0.0 4
5/22/2019 BEF 281 0.0 5
5/23/2019 BEF 281 0.0 6
5/24/2019 BEF 281 4.2 7
5/25/2019 BEF 281 0.0 8
5/26/2019 BEF 281 2.2 9
5/27/2019 BEF 281 0.0 10
5/28/2019 BEF 281 0.1 11
5/29/2019 BEF 281 0.0 12
5/30/2019 BEF 281 0.0 13
5/31/2019 BEF 281 0.0 14
6/1/2019 BEF 281 0.0 15
6/2/2019 BEF 281 0.6 16
6/3/2019 BEF 281 3.6 17
6/4/2019 BEF 281 0.0 18
6/5/2019 BEF 281 4.3 19
6/6/2019 BEF 281 13.1 20
6/7/2019 BEF 281 0.0 21
6/8/2019 BEF 281 0.0 22
6/9/2019 BEF 281 0.0 23
6/10/2019 BEF 281 0.0 24
6/11/2019 BEF 281 24.5 25
6/12/2019 BEF 281 0.0 26
6/13/2019 BEF 281 4.3 27
6/14/2019 BEF 281 0.7 28
6/15/2019 BEF 281 0.0 29
6/16/2019 BEF 281 0.0 30
6/17/2019 BEF 281 0.0 31
6/18/2019 BEF 281 0.0 32
6/19/2019 BEF 281 0.0 33
6/20/2019 BEF 281 27.1 34
6/21/2019 BEF 281 2.1 35
6/22/2019 BEF 281 0.0 36
6/23/2019 BEF 281 0.0 37
6/24/2019 BEF 281 0.0 38
6/25/2019 BEF 281 14.8 39
6/26/2019 BEF 281 6.0 40
6/27/2019 BEF 281 2.4 41
6/28/2019 BEF 281 0.0 42
6/29/2019 BEF 281 0.0 43
6/30/2019 BEF 281 6.9 44
7/1/2019 BEF 281 0.1 45
7/2/2019 BEF 281 0.0 46
7/3/2019 BEF 281 0.0 47
7/4/2019 BEF 281 0.0 48
7/5/2019 BEF 281 0.0 49
7/6/2019 BEF 281 12.8 50
7/7/2019 BEF 281 0.1 51
7/8/2019 BEF 281 0.0 52
7/9/2019 BEF 281 0.0 53
7/10/2019 BEF 281 0.0 54
7/11/2019 BEF 281 27.6 55
7/12/2019 BEF 281 29.7 56
7/13/2019 BEF 281 0.0 57
7/14/2019 BEF 281 0.0 58
7/15/2019 BEF 281 0.0 59
7/16/2019 BEF 281 0.0 60
7/17/2019 BEF 281 0.0 61
7/18/2019 BEF 281 0.0 62
7/19/2019 BEF 281 0.0 63
7/20/2019 BEF 281 0.0 64
7/21/2019 BEF 281 0.0 65
7/22/2019 BEF 281 1.7 66
7/23/2019 BEF 281 11.6 67
7/24/2019 BEF 281 0.0 68
7/25/2019 BEF 281 0.0 69
7/26/2019 BEF 281 0.0 70
7/27/2019 BEF 281 0.0 71
7/28/2019 BEF 281 0.0 72
7/29/2019 BEF 281 1.4 73
5/18/2019 JEFF 528 0 1
5/19/2019 JEFF 528 6.1 2
5/20/2019 JEFF 528 4.7 3
5/21/2019 JEFF 528 0.7 4
5/22/2019 JEFF 528 0 5
5/23/2019 JEFF 528 0.4 6
5/24/2019 JEFF 528 1.1 7
5/25/2019 JEFF 528 1.1 8
5/26/2019 JEFF 528 6.4 9
5/27/2019 JEFF 528 0 10
5/28/2019 JEFF 528 8.3 11
5/29/2019 JEFF 528 0 12
5/30/2019 JEFF 528 0 13
5/31/2019 JEFF 528 0 14
6/1/2019 JEFF 528 0 15
6/2/2019 JEFF 528 1.9 16
6/3/2019 JEFF 528 0.3 17
6/4/2019 JEFF 528 0 18
6/5/2019 JEFF 528 7.9 19
6/6/2019 JEFF 528 8.3 20
6/7/2019 JEFF 528 0 21
6/8/2019 JEFF 528 0 22
6/9/2019 JEFF 528 0 23
6/10/2019 JEFF 528 0 24
6/11/2019 JEFF 528 5.2 25
6/12/2019 JEFF 528 0 26
6/13/2019 JEFF 528 0.8 27
6/14/2019 JEFF 528 0.2 28
6/15/2019 JEFF 528 0 29
6/16/2019 JEFF 528 0.2 30
6/17/2019 JEFF 528 0 31
6/18/2019 JEFF 528 0 32
6/19/2019 JEFF 528 0 33
6/20/2019 JEFF 528 10.2 34
6/21/2019 JEFF 528 1 35
6/22/2019 JEFF 528 0 36
6/23/2019 JEFF 528 0 37
6/24/2019 JEFF 528 0 38
6/25/2019 JEFF 528 5.2 39
6/26/2019 JEFF 528 2.3 40
6/27/2019 JEFF 528 0.1 41
6/28/2019 JEFF 528 0 42
6/29/2019 JEFF 528 1.6 43
6/30/2019 JEFF 528 6.9 44
7/1/2019 JEFF 528 0 45
7/2/2019 JEFF 528 0 46
7/3/2019 JEFF 528 0 47
7/4/2019 JEFF 528 0 48
7/5/2019 JEFF 528 0 49
7/6/2019 JEFF 528 8.7 50
7/7/2019 JEFF 528 0 51
7/8/2019 JEFF 528 0 52
7/9/2019 JEFF 528 0 53
7/10/2019 JEFF 528 0 54
7/11/2019 JEFF 528 13.8 55
7/12/2019 JEFF 528 4.5 56
7/13/2019 JEFF 528 2.1 57
7/14/2019 JEFF 528 0.3 58
7/15/2019 JEFF 528 0 59
7/16/2019 JEFF 528 0 60
7/17/2019 JEFF 528 2.1 61
7/18/2019 JEFF 528 0 62
7/19/2019 JEFF 528 0 63
7/20/2019 JEFF 528 0 64
7/21/2019 JEFF 528 0 65
7/22/2019 JEFF 528 2.2 66
7/23/2019 JEFF 528 1.9 67
7/24/2019 JEFF 528 0 68
7/25/2019 JEFF 528 0 69
7/26/2019 JEFF 528 0 70
7/27/2019 JEFF 528 0 71
7/28/2019 JEFF 528 5.6 72
7/29/2019 JEFF 528 0.1 73


I'm unsure if I should put each rain gauge (with its respective elevation) into its own column so that this clears up the confusion R is having with my data.

Thanks so much for your time & patience!! I'm teaching myself this and trying to learn, so your help is always appreciated.
chasingbirds
 
Posts: 6
Joined: Wed Dec 11, 2019 1:08 pm

Re: DSR with precipitation data

Postby jlaake » Thu Apr 02, 2020 8:38 am

I believe the problem is that you have 2 sites but did not specify groups="site" in process.data and you would need to set bygroup=TRUE in merge function.
jlaake
 
Posts: 1295
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: DSR with precipitation data

Postby chasingbirds » Thu Apr 02, 2020 10:31 am

jlaake wrote:I believe the problem is that you have 2 sites but did not specify groups="site" in process.data and you would need to set bygroup=TRUE in merge function.


I ran the process.data code again with groups="site" but got the same error when trying to use the merge function. I then removed the column "site" and tried it again, but still getting the error above:

Code: Select all
 Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length


Note: the data I pasted above is only the first half of the dataframe...I have more rows of data that I just didn't paste into this forum. I have daily average precipitation for elevations 281, 528, 812 and 1,143m. Not sure if this helps....
chasingbirds
 
Posts: 6
Joined: Wed Dec 11, 2019 1:08 pm

Re: DSR with precipitation data

Postby jlaake » Thu Apr 02, 2020 12:35 pm

So I re-read your initial post and it sounds like you have multiple elevations per site and the elevation is nest specific rather than site-specific. I assumed the latter with my last suggestion. If precipitation is the same across nests at an elevation for a particular time then you should also use elevation in groups. What you are trying to do is have a single row in the dataframe to be matched to the design data. Right now you have more rows in precipit than in your design data.

Now with nest data, merge_design.covariates will work but isn't entirely necessary because you can easily construct a dataframe that matches the structure of ddl$S and then cbind them together. merge_design.covariates was created mostly for more models that create more complex ddl structures like cjs etc which have cohorts as well as times. For a single group with T times, the ddl$S only contains T records. If you have G groups then there are G*T records. Look at your ddl$S to see what it looks like when you use no groups and groups="site" and hopefully this will make more sense. If you still can't get it to work then send me your data and code to jefflaake@gmail.com and I'll show you what to do but please provide a more detailed explanation of your data in the email.
jlaake
 
Posts: 1295
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 1 guest

cron