Page 1 of 2
converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:24 am
by Bryan Hamilton
I'm switching from MARK to secr. I worked very hard to get my capture histories coded for MARK with '0's and '1's
- Code: Select all
AOU_Code AnimalID StartYear CaptureHistory Gender Trap_Number
5203 PETR 004 2004 1011 F D4
10931 PEMA 004 2004 1011 F G3
11520 PETR 004 2004 1011 F E5
3942 PEMA 005 2004 1000 F D1
2861 PETR 006 2004 1111 M A5
4353 PEMA 006 2004 1111 M D6
Now I need to switch to a line based capture history where each individual capture occasion is represented by a line.
- Code: Select all
AOU_Code AnimalID StartYear CaptureHistory Gender Trap_Number occasion
5203 PETR 004 2004 1011 F D4 1
10931 PEMA 004 2004 1011 F G3 3
11520 PETR 004 2004 1011 F E5 4
3942 PEMA 005 2004 1000 F D1 1
2861 PETR 006 2004 1111 M A5 1
4353 PEMA 006 2004 1111 M D6 2
I'm hoping that I don't have to add the capture occasion line by line in Excel since I have nearly 6,000 captures. Are there some strategies or R code for adding the capture occasion to these data?
Thank you.
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:33 am
by murray.efford
I'm hoping that I don't have to add the capture occasion line by line in Excel ...
That might be painful, and shouldn't be necessary if you have the data already in R.
I cannot offer a complete solution right off. The problem is that your data don't seem to include occasion-specific trap numbers, so how do we know where each capture happened?
secr has a function 'unRMarkInput' but it doesn't solve your problem.
Do you have multiple sessions (years)?
Murray
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:40 am
by Bryan Hamilton
I do have multiple years. so there is alot of redundancy with animal id and trap id.
I can add occasion specific trap numbers pretty easily in R and probably get unique animal ids by combining year and animal id.
edit- I have the trap dates too so that may be the easiest way to code the capture occastion.
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:47 am
by murray.efford
I don't follow. For example, the first row of your data represents 3 capture events, but there is only one trap number.
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:49 am
by Bryan Hamilton
I think that is a typo. That animal (004) was caught in trap D4, G3 then E5.
edit- In the example data, each capture already has its own row associated with it. I just need to add the capture occasion.
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:53 am
by murray.efford
I understand now. The 'PEMA' threw me.
So for any one animal the successive rows give the trap number corresponding to the successive detections in the (shared) capture history. I think it should be easy to attach occasion numbers - I'll look at it.
Murray
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 1:57 am
by Bryan Hamilton
The PEMA threw me too... Its always worrisome to find errors in your carefully checked dataset. Especially on the first random sample.
Thanks for your help. I'm getting closer with the dates.
Re: converting capture history from MARK to secr

Posted:
Thu May 07, 2015 2:21 am
by murray.efford
Here's my way of doing it - there may be better
- Code: Select all
addOccasion <- function (df, IDfield = 'AnimalID', Yearfield = 'StartYear', CHfield = 'CaptureHistory') {
df$ID <- paste(df[,IDfield], df[,Yearfield], sep='.')
dflist <- split(df, df$ID)
dflist <- lapply(dflist, function (oneanimal) {
occs <- strsplit(oneanimal[1,CHfield], '')[[1]]
oneanimal$Occasion <- which(occs=='1')
oneanimal
})
do.call(rbind, dflist)
}
newdf <- addOccasion(mydf)
head(newdf)
AOU_Code AnimalID StartYear CaptureHistory Gender Trap_Number ID Occasion
4.2004.1 PETR 4 2004 1011 FALSE D4 4.2004 1
4.2004.2 PEMA 4 2004 1011 FALSE G3 4.2004 3
4.2004.3 PETR 4 2004 1011 FALSE E5 4.2004 4
5.2004 PEMA 5 2004 1000 FALSE D1 5.2004 1
This assumes CaptureHistory has character values (to allow for 0 on first occasion).
Murray
Re: converting capture history from MARK to secr

Posted:
Sat May 09, 2015 6:30 pm
by Bryan Hamilton
Thanks for this. I will give it a try. I ended up just recoding each sampling date, which worked but was not nearly as elegant as your code.
Re: converting capture history from MARK to secr

Posted:
Sat May 09, 2015 8:17 pm
by murray.efford
So why did you ask if you weren't going to use the answer?