Ah-ha, I finally know how to ask what I'm trying to figure out (and huge thanks for your patience).
The design data have animals that don't exist in my data. I have a yet another dipper example below. In it, I have 2 age-9 animals, which are only encountered in later occasions. But in the dll data, there are age-9 animals starting from occasion 1, which extends the range of ages (compared to the real observed ages). This creates a problem for me, because it "whips" that end of the spline up, where ages are higher than anything observed in the data proper. Toy example below, then an image from my actual data - I only have animals up to age 25, but the model is estimating effects up to age 37, and that end of the spline is useless to me. How do I deal with that? Just to clarify - I can easily just grab the ages I need from the estimates, but does the modeling of the right-hand tail not affect the estimates in the intermediate age range?
- Code: Select all
library(RMark)
library(dplyr)
library(stringr)
library(splines)
data(dipper)
set.seed(0)
dipper <- dipper[sample(1:nrow(dipper), 30, replace = FALSE),]
dipper$age <- sample(1:10, nrow(dipper), replace = TRUE)
begin.time=1980
dipper <- arrange(dipper, age)
dipper$ageFac <- as.factor(dipper$age)
dipper.processed=process.data(dipper,begin.time=begin.time, groups = c("sex", "ageFac"), age.var = 2, initial.age = unique(dipper$age))
dipper.ddl=make.design.data(dipper.processed)
data1.analysis=function(){
Phi.dot=list(formula=~1)
p.age.spline=list(formula=~bs(Age))
cml=create.model.list("CJS")
mark.wrapper(cml,data=dipper.processed, ddl=dipper.ddl, delete = FALSE)
}
data1.results <- data1.analysis()
data1.results
predp <- summary(data1.results[[1]], se=TRUE)$real$p %>%
select(Age, estimate, lcl, ucl) %>%
unique()
Compare observed ages (calculate the maximum age all animals attain by end of sampling) and ages from the dll.
- Code: Select all
dipper$FirstYear <- begin.time + as.data.frame(str_locate(dipper$ch, "1"))$start - 1 # first year animal is recorded
dipper$MaxAge <- 1986 - dipper$FirstYear + dipper$age
max(dipper$MaxAge) # 13
max(predp$Age) # 15 - a wider range of ages than actually observed
dipper.ddl$p %>% filter(Age == 15) # look at which dll animals reach age 15 - these have ageFac of 9 and belong to cohort 1980
dipper %>% filter(ageFac == 9) # check the data - all ageFac 9 animals were caught in late sessions
