Creating .inp file in R with groups/covariates

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

Creating .inp file in R with groups/covariates

Postby Dumetella_c » Mon Mar 13, 2023 8:00 pm

Hello!
I am analyzing a set of MAPS (Monitoring Avian Population and Survivorship) banding data of Gray Catbirds spanning the years of 2009-2021, with approximately 369 birds total in the dataset. I would like to use RMark to perform CJS analysis, but before I can do that I first need to create the .inp file.
I created a vertical. csv file with the Banding Number (Tag), year of capture, sex (M, F, or U), and adult status (adult or juvenile). I have used the R code in the addendum to chapter 2 to create .inp files, but said files only include the commented tag number, the capture history and the frequency for the individual at the end, but not any information on sex and adult/juvenile status.
I am trying to modify the R code in the addendum to chapter 2 of the Gentle Guide that will include sex and year so that they are included in the .inp file that I will then use with RMark in a manner similar to the dipper example. So far I have tried several methods to try to get the columns to be added to no avail.
Does anyone have any suggestions, and/or has tried something similar?
Thank you for your help in advance!
Dumetella_c
 
Posts: 1
Joined: Fri Mar 10, 2023 12:35 pm

Re: Creating .inp file in R with groups/covariates

Postby jlaake » Thu Mar 16, 2023 7:40 pm

I had Camila contact me offlist. Below is some code that would work if sex was always known and unchanging. However, that was not the case here. Many of these birds were initially marked as hatch year and the sex was unknown. In that case, you can't use a simple CJS model and need to consider a Hidden Markov model or a multistate model with state uncertainty because sex will be initially unknown and then can be determined if the bird is seen as an adult. But for simpler situations the code below should work. Note that the resulting dataframe is ready for RMark and is not a .inp file which is the MARK format with ; at end etc.

Code: Select all
# read in data; Tag and Year are factor variables
data = read.csv("grca_bbbo_for_rmark_attempt.csv", colClasses=rep("factor",5))
# create capture history matrix and ch string
chmat=table(data$Tag,data$Year)
# if sighted multiple times in the year change this to a 1
chmat[chmat>1]=1
ch=apply(chmat,1,paste,collapse="")
# sort by tag and year
data=data[order(data$Tag,data$Year),]
# find which are duplicates for Tag #
dups=duplicated(data[,"Tag"])
# use the non duplicated values which should be the first year sighted
sexage=data[!dups,]
#bind into a single dataframe
data=cbind(ch,sexage)
# this is then ready for RMark
str(data)

jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: Google [Bot] and 9 guests

cron