Editing covariates for multi-session capture history

questions concerning anlysis/theory using program DENSITY and R package secr. Focus on spatially-explicit analysis.

Editing covariates for multi-session capture history

Postby matobler » Thu Aug 27, 2015 3:05 pm

I am working on a dataset with 12 different sessions and multiple individual covariates (sex, age, disease status). The covariates don't necessarily have the same levels for all sessions (e.g. sometimes only healthy animals are captured) causing secr to return an error. I was hoping to fix this problem by assigning the correct levels to all covariates in R but for some reason I am not able to write to the covariates.

While

Code: Select all
covariates(capthist)[,"sex"]<-newsex


works fine for a single session capture history,

Code: Select all
covariates(capthist)[[1]][,"sex"]<-newsex


does not work. Any suggestions on how to solve this issue without importing each session as a single capture history and them merging them (which would require creating new input files for each session).

Thanks,

Mathias
matobler
 
Posts: 19
Joined: Fri Nov 03, 2006 9:44 pm
Location: Peru

Re: Editing covariates for multi-session capture history

Postby matobler » Thu Aug 27, 2015 3:29 pm

As so often happens, just after hitting the Submit button I realized that this exact question was answered a few posts back and I found the mistake in my code.

Instead of

Code: Select all
covariates(capthist)[[1]][,"sex"]<-newsex


it obviously should be

Code: Select all
covariates(capthist[[1]])[,"sex"]<-newsex


and as Murray pointed out before the levels can easily be set with the following code:

Code: Select all
for (i in 1:length(capthist))
  levels(covariates(capthist[[i]])$sex) <- c('M','F')



All works now.

Mathias
matobler
 
Posts: 19
Joined: Fri Nov 03, 2006 9:44 pm
Location: Peru


Return to analysis help

Who is online

Users browsing this forum: No registered users and 2 guests