Hi Murray,
Thanks so much for getting back to me, I realize I probably should have explained my analysis and study design more to avoid confusion. I am working with four years of data that I split up into 3 sessions per year (representing 3 different ecologically relevant periods). Because we are using full likelihood and would like to evaluate covariates on the spatial distribution of density we could not use individual covariates (such as age) so we further split Adult Males, Adult Females, Juveniles, and Neonates into separate sessions. That is why gravidness applies to the whole session (still varying by occasion), because it is the percent of all captures in an Adult Female session that were gravid instead of saying whether or not an individual is. Our effort (searchmin) information is also not trap varying, but is occasion varying. Each trap is actually the center of a cell in a sampling grid, in which the entire grid was visually surveyed at least once an occasion. However while most of the time searches were conducted by one or two people, some weeks/occasions had influxes of volunteers to help with visual surveys, causing the extreme variation in search effort. That is one reason we scaled effort in the first place.
The post I was referring to in which you used NAs to add a time varying covariate to a multisession model with different occasions per session is here (
https://groups.google.com/g/secrgroup/c/i7EQZ-cTrjE/m/r8CYDSUNAgAJ). I made a simple example of my current problem specifying multiple occasion varying covariates, with examples of solutions I have already tried. I did discover that the method I used in my original post would not work. The file shows fitting a null model, as well as my steps to successfully fit a model with a single time varying covariate. However as I mentioned I am still stuck on specifying multiple time varying covariates? The example code is copied below and also attached as a txt file (along with the necessary files for the edf, tdfs, and masks). There are three sessions with varying number of occasions but the same mask. One additional but related question is does secr internally standardize covariates? I could not find any info on it but I know some other programs/packages do. Thank you so much for all your time and help, I appreciate both your help on this and contributions to all the previous posts on the group that I have learned a lot from.
library(secr)
#Load files and make secr objects
edf <- read.csv("testofedf.csv")
mask <- read.csv("testofmask.csv")
tdf1 <- read.traps(file = "testoftdf.txt", detector = "count")
tdf2 <- read.traps(file = "testoftdf.txt", detector = "count")
tdf3 <- read.traps(file = "testoftdf.txt", detector = "count")
tdflist <- list(tdf1, tdf2, tdf3)
mask1 <- read.mask(data=mask, spacing = 20, header = TRUE)
mask2 <- read.mask(data=mask, spacing = 20, header = TRUE)
mask3 <- read.mask(data=mask, spacing = 20, header = TRUE)
masklist <- list(mask1, mask2, mask3)
#Make Capture history
CH <- make.capthist(captures = edf, traps = tdflist,
fmt = "trapID", noccasions = c(4, 5, 4),
bysession = TRUE)
verify(CH)
#Fit initial null model, this works
fit <- secr.fit(CH, mask = masklist,
model = c(D ~ 1, g0 ~ 1, sigma ~ 1),
trace = NULL, verify = TRUE, start = c(2, -3, 4))
summary(fit)
#Use NAs to add a single occassion varying covariate and fit model (this works)
var1 <- list(c(1, 4, 3, 3, NA), #Session 1
c(3, 2, 1, 1, 4),#Session 2
c(4, 1, 4, 2, NA))# Session 3
sapply(var1, round, 1)
fit.2 <- secr.fit(CH, mask = masklist, timecov = var1,
model = c(D ~ 1, g0 ~ tcov, sigma ~ 1),
trace = NULL, verify = TRUE, start = c(2, -3, 0, 4))
summary(fit.2)
#Try to add two different occassion varying covariates (var1 and var2) to the model
#These are some of the different methods I have tried, but does not run
timevary <- list(data.frame(var1 = c(1, 2, 3, 3, NA), var2 = c(10, 12, 13, 10, NA)), #Session 1
data.frame(var1 = c(3, 2, 1, 1, 4), var2 = c(15, 9, 11, 12, 13)), #Session 2
data.frame(var1 = c(4, 1, 4, 2, NA), var2 = c(13, 13, 12, 12, NA))) #Session 3
#timevary <- list(list(var1 = c(1, 2, 3, 3, NA), var2 = c(10, 12, 13, 10, NA)), #Session 1
#list(var1 = c(3, 2, 1, 1, 4), var2 = c(15, 9, 11, 12, 13)), #Session 2
#list(var1 = c(4, 1, 4, 2, NA), var2 = c(3, 13, 12, 12, NA))) #Session 3
#timevary <- list(var1 = list(c(1, 2, 3, 3, NA), c(3, 2, 1, 1, 4), c(4, 1, 4, 2, NA)),
# var2 = list(c(10, 12, 13, 10, NA), c(15, 9, 11, 12, 13), c(3, 13, 12, 12, NA)))
fit.3 <- secr.fit(CH, mask = masklist, timecov = timevary,
model = c(D ~ 1, g0 ~ var1, sigma ~ 1),
trace = NULL, verify = TRUE, start = c(2, -3, 0, 4))
Best,
James