library(marked)
The data set in this project is from the Oregon Department of Fish and Wildlife. It is observations on a population of North Western Pond Turtles located in one specific pond in The Dalles, Oregon. The data set contains 445 observations on 18 variables.
library(readr)
turtle_data <- read_csv("~/Documents/Math 248/Final Project Data/turtle data.csv")
turtle_data <- read_csv("turtle data.csv")
head(turtle_data)
The data were collected over a time period of 2018 to 2023 with data being collected during trapping events each summer where trapped turtles were marked (for first time captures) or labelled as a recapture (if they had already been captured previously). Various observations were recorded on them at each capture. There are repeat observations of the turtles in the data set because in this data set there were 57 capture events and any turtle alive and in the pond had a (presumably) equal chance of being captured at each of these times. In total there are 74 turtles in this data set that are represented over the 445 observations.
The variables of interest in this data set are the variable PIT_Tag which is a unique microchip type of mark used to identify turtles that are recaptured over the course of this study. The variables Event_Year and Event_Date tell the year and the data of the capture. The variable Sex tells us the sex of the turtle. The variable Annuli is a count of the growth rings on the turtle’s shell and can be a quick way to get an age estimate for the turtle. The value -9999 in this variable means the rings are too worn out to tell the age of the turtle, which is common. Lastly, the variables Carapace_Height, Carapace_Width, Carapace_Length, Plastron_Length, Plastron_Width, and Weight are all measures of size for these turtles. The Carapace is the top or domed part of the turtle’s shell and the plastron is the part of the shell on the underside of the turtle. Measurements of the carapace and plastron are in millimeters and measurements of the weight are in grams.
Looking at this data set, an interesting idea that comes up is
modeling survival of turtles in the population over the years and seeing
if there might be differential survival based on the sex or size of the
turtles. So the research question is this:
does survival differ in North Western Pond Turtle populations based on sex of the individuals or size of the individuals?
In order to answer this question using available modeling methods the data had to be reformatted. For the model, there must be a variable of capture history for each turtle and other variables on the turtles must be categorical. Each observation in the data set was a record of a capture, however in order to model the data we needed capture histories. So the data set was reformatted so that for each turtle, identified by their Pit Tag ID, there was a capture history over the 6 years of sampling represented by a string of six 0’s and 1’s (0 indicating a failure to capture and 1 a success). The variable of sex in this data set, which was desired to be used as a variable to differentiate survival, has the categories of female, male, and also unknown because in young turtles it can be nearly impossible to determine their sex. In order to differentiate turtles based on size, a new variable of size class was created based on the variable of plastron length, which is the most standard measure of size in turtles. There are 4 size classes in this variable, labeled as 1-4. The size classes of 1-4 are based on measurements of plastron length in the data set with 1 being the smallest and 4 the largest size class. The turtles were repeatedly measured over 6 years so size class did vary by year as the turtles grew. However, only 23 of the 74 turtles changed in size class over the 6 years and only 1 was found to change by more than one size class over the 6 years. So for simplicity of the analysis and so turtles could be put into one size class for their capture history, the average of the measurements over the years was used to determine size class. There was also one turtle of unknown size who had to be removed from the size class data. Using these two categorical variables and the capture history allows for a model to be built that can answer the research question.
library(readr)
Turtles_ch_by_Year_Sex <- read_csv("~/Documents/Math 248/Final Project Data/Turtles ch by Year Sex.csv",
col_types = cols(Sex = col_factor(levels = c("M",
"F", "U"))))
Turtles_ch_by_Year_Size <- read_csv("~/Documents/Math 248/Final Project Data/Turtles ch by Year Size.csv",
col_types = cols(`Size Class` = col_factor(levels = c("1",
"2", "3", "4"))))
head(Turtles_ch_by_Year_Sex)
head(Turtles_ch_by_Year_Size)
Mark-recapture methods are a broadly used method of ecological data collection and statistics. Individuals in a population are sampled, by trapping, over multiple capture periods (it must be at least 3). Individuals are marked and released at each capture and individuals who have been previously captured are labelled as a recapture and released. Population size can be estimated using the proportion marked, which is a fairly straightforward calculation using the proportion of those marked initially that are recaptured. The other thing that can be estimated is apparent survival. To estimate apparent survival the number recaptured is added to the number still present but not recaptured, and this sum is divided by the number initially marked. Survival in this model is ‘apparent’ or local because emigration from the area or population cannot be distinguished from death in this calculation. The number of animals still present but not recaptured is a parameter that must be estimated by the model based on data in the data set indicating a failure to capture when the animal is still present (for example, a miss and then a capture indicates they were still alive at the previous capture but failed to be captured).
The specific model used in this analysis is the Cormack Jolly Seber Model. This is a model that can be used to estimate apparent survival and probability of detection for mark recapture data. This model estimates two parameters: \(\phi\) or probability of survival to the next capture event, and \(p\), which is probability of detection or likelihood that if an animal is present it will be captured in the sample. There are many models that can estimate \(\phi\) and \(p\) for mark recapture data sets, however the Cormack Jolly Seber Model was chosen because in addition to analyzing other categorical variables it can also give year specific estimations of \(\phi\) and \(p\) allowing for another variable, which is time, to be analyzed while looking at the data. In this model, the known constant is the number of animals released each year. The parameters are \(\phi\), \(p\), and \(\chi\) (\(\chi\) is the probability that an animal is present but not detected during a capture event and is the compliment of \(p\)). This model is built using a few different parts. A maximum likelihood estimation, which is a method of estimating the parameters of an assumed probability distribution is used with two sub-models. The sub-models are general linear models that use multinomial logistic regression to model \(\phi\) and \(p\), separately (one in each model). Using the general linear models, the maximum likelihood estimation finds the most likely parameters that give the observed frequency of capture history (assuming a probability distribution of the capture histories). The general linear models use a multinomial distribution because the categorical variables used to model \(\phi\) and \(p\) can have more than two categories. The models are logistic regression models because the parameters \(\phi\) and \(p\) are probabilities. The theoretical sub-model then looks something like this for \(\phi\): \[logit(\phi)=\beta_0+\beta_1x_1+\beta_2x_2+..+\beta_nx_n\] and something like this for \(p\): \[logit(p)=\beta_0+\beta_1x_1+\beta_2x_2+..+\beta_nx_n\] The \(x_i\) here represent different variables that are used to predict the parameters of \(\phi\) and \(p\), for example time, sex, size class or any combination of these (including interaction terms). The \(\beta_i\) represent coefficients used for each respective predictor to model the parameters. After the general linear models are built using the desired combination of predictors, the maximum likelihood estimation is used to estimate values for \(\phi\) and \(p\) from each model based on the frequency of capture histories. The Akaike Information Criterion, or AIC which determines the best fitting model using the maximum likelihood criterion, is also calculated for each model and can be used to compare to models with other combinations of predictors. Ultimately this gives the ‘best model’ for the data based on the maximum likelihood estimation and subsequent AIC. The \(\phi\) and \(p\) predictions used from this model are the output of the modeling process. So for our analysis we will use the predictors time, size class, and sex, and look at models that compare different combinations of them, and the AIC these models produce, using R.
This model uses two general linear models and therefore has the assumptions of normality, independence and equal variance. The condition of independence is met in this study because each capture event is a random sample with equal probabilities of capture for each turtle at each time of sample. There are also additional assumptions for this model that come with the mark recapture statistical format. For this model to be valid, every animal present must have the same probability of capture. This assumption may be violated for this data, because smaller turtles likely have an easier time escaping from the traps, and therefore are less likely to be captured using this method. Another assumption that must be valid for this model to work is that marks are not lost between sampling events or misread. This assumption is well met for this study because the marks are applied in the form of a subcutaneous pit tag, or microchip. The likelihood of these coming out of the turtle is very small if properly injected into the turtle. The marks are read using an electronic pit tag reader, so the likelihood of marks being misread is very small. For this model to be valid there is the assumption that emigration from the sampling area is permanent, although in this data set due to the physiology of the turtles and the constraint of living in a pond that is fairly isolated, it is not likely that emigration is not really a factor at all in this model. Another assumption that is important to this model is that marking the animal does not influence survival of the animal. This assumption is fairly reasonable for this model as well, as the microchips are minimally invasive in the turtles and as long as they are injected properly should not affect the turtles chance of survival. The last assumption that is important to this model is that the sampling area is constant, which is satisfied for this data set because the same pond was sampled each year with the same method of using a lobster trap and therefore the sampling area does not change between sample events. We can see that the data seems to satisfy all model conditions fairly well, so the model should be valid to assess the data.
We can start by building a model that simply estimates survival and probability of detection assuming that they do not vary by year, and using no extra predictor variables.
cjs.modelforYear1 <- crm(Turtles_ch_by_Year_Sex)
cjs.modelforYear1 <- cjs.hessian(cjs.modelforYear1)
predict(cjs.modelforYear1,
newdata = data.frame(Sex = c("F", "M", "U")),
se = TRUE)
## $Phi
## occ estimate se lcl ucl
## 1 1 0.9078948 0.02587219 0.8431405 0.9475794
##
## $p
## occ estimate se lcl ucl
## 1 2 0.6908612 0.03831341 0.6112424 0.7605614
We can see, using the predict function, that this gives us an estimate for \(\phi\) of about 0.91 with a confidence interval of 0.84 to 0.95. Then for the parameter of \(p\), we see that the estimate is about 0.69, and the confidence interval is 0.61 to 0.76 for this parameter.
If we want to model \(\phi\) and \(p\) using our predictor variables of time, sex, and size we can create a full set of models for each of the combinations sex and time, and size class and time, and use the AIC to determine the best fit for this data set. Looking first at the variable sex, and the models made allowing \(\phi\) and \(p\) to vary based on sex and time.
Turtles_ch_by_Year_Sex=data.frame(Turtles_ch_by_Year_Sex)
is.factor(Turtles_ch_by_Year_Sex[, "Sex"])
turtleyear.proc <- process.data(Turtles_ch_by_Year_Sex,
group = "Sex") # group variable has to be in the data
# Make design data (from processed data)
turtleyear.ddl <- make.design.data(turtleyear.proc)
fit.turtleyear.cjs.models <- function(){
# Apparent survival (Phi) formula
Phi.sex.time <- list(formula=~Sex*time) # Just like in other linear models "*" includes main effects and an interaction
Phi.time <- list(formula=~time) # differs between discrete times
Phi.sex <- list(formula=~Sex) # differs between males and females
Phi.dot <- list(formula=~1) # constant survival
# Detection probability (p) formula
p.sex <- list(formula=~Sex) # differs between males and females
p.time <- list(formula=~time) # one discrete estimate of p per capture event
p.dot <- list(formula=~1) # constant detection
# Construct all combinations and put into one model table
cml <- create.model.list(c("Phi","p")) # makes all possible combinations of those parameter formulas
results <- crm.wrapper(cml,
data = turtleyear.proc,
ddl = turtleyear.ddl,
external = FALSE,
accumulate = FALSE,
hessian = TRUE)
return(results)
}
# Run function
turtleyear.cjs.models <- fit.turtleyear.cjs.models()
turtleyear.cjs.models
## model npar AIC DeltaAIC weight neg2lnl
## 3 Phi(~1)p(~time) 6 300.4901 0.000000 7.444782e-01 288.4901
## 6 Phi(~Sex)p(~time) 8 302.8254 2.335373 2.315965e-01 286.8254
## 12 Phi(~time)p(~time) 10 307.3927 6.902625 2.360293e-02 287.3927
## 9 Phi(~Sex * time)p(~time) 20 315.9804 15.490332 3.222323e-04 275.9804
## 11 Phi(~time)p(~Sex) 8 331.4992 31.009176 1.374975e-07 315.4992
## 10 Phi(~time)p(~1) 6 339.9493 39.459280 2.010843e-09 327.9493
## 2 Phi(~1)p(~Sex) 4 343.1336 42.643504 4.091974e-10 335.1336
## 8 Phi(~Sex * time)p(~Sex) 18 344.0186 43.528486 2.628823e-10 308.0186
## 5 Phi(~Sex)p(~Sex) 6 346.9883 46.498229 5.955110e-11 334.9883
## 1 Phi(~1)p(~1) 2 350.8048 50.314707 8.833893e-12 346.8048
## 7 Phi(~Sex * time)p(~1) 16 351.2657 50.775680 7.015410e-12 319.2657
## 4 Phi(~Sex)p(~1) 4 352.7172 52.227144 3.395250e-12 344.7172
## convergence
## 3 0
## 6 0
## 12 0
## 9 0
## 11 0
## 10 0
## 2 0
## 8 0
## 5 0
## 1 0
## 7 0
## 4 0
We can then use the AIC to determine the best model for this data, and we see that the best model corresponds to the lowest AIC. Looking at the table we see this model is the model using a constant estimate for \(\phi\), and year specific estimates for \(p\). This tells us that survival and detection do not vary enough by sex to be worth including sex in the model based on the AIC. We see however that the probability of detection, \(p\), does vary by year significantly enough to be worth including in the model. We can look at the predictions of \(\phi\) and \(p\) given by this model:
sextimep.proc <- process.data(Turtles_ch_by_Year_Sex,
group = "Sex") # group variable has to be in the data
# Make design data (from processed data)
sextimep.ddl <- make.design.data(sextimep.proc)
# Outine formulas for each parameter
Phi.dot <- list(formula=~1) # ~1 is always a constant (or single estimate)
Phi.Size.Class <- list(formula=~1) # This formula will have an intercept (for females) and an estimate for the difference between females and males
p.time <- list(formula=~time) # Be careful of case-sensitive names. Use the exact group column that was in data
# Make new model (using design data) with constant survival, but different detection probabilities between sexes
cjs.m4 <- crm(sextimep.proc,
sextimep.ddl,
model.parameters = list(Phi = Phi.dot,
p = p.time),
accumulate = FALSE)
predict(cjs.m4)
## $Phi
## occ estimate
## 1 4 0.9116662
##
## $p
## time occ estimate
## 1 5 5 0.9376058
## 2 6 6 0.4974792
## 3 4 4 0.8026161
## 4 3 3 0.8665938
## 5 2 2 0.2165483
We see that this model predicts about 91% survival for all sexes across all 6 years. The model also predicts the lowest detection probability in 2019 at about 22% and then the next lowest in 2023 at about 50%, and then the other years have higher probabilities from roughly 80-94%.
We can then do this same analysis looking at size class:
Turtles_ch_by_Year_Size=data.frame(Turtles_ch_by_Year_Size)
is.factor(Turtles_ch_by_Year_Size[, "Size.Class"])
## [1] TRUE
turtleyear1.proc <- process.data(Turtles_ch_by_Year_Size,
group = "Size.Class") # group variable has to be in the data
# Make design data (from processed data)
turtleyear1.ddl <- make.design.data(turtleyear1.proc)
fit.turtleyear1.cjs.models <- function(){
# Apparent survival (Phi) formula
Phi.sizeclass.time <- list(formula=~Size.Class*time) # Just like in other linear models "*" includes main effects and an interaction
Phi.time <- list(formula=~time) # differs between discrete times
Phi.size <- list(formula=~Size.Class) # differs between males and females
Phi.dot <- list(formula=~1) # constant survival
# Detection probability (p) formula
p.size <- list(formula=~Size.Class) # differs between males and females
p.time <- list(formula=~time) # one discrete estimate of p per capture event
p.dot <- list(formula=~1) # constant detection
# Construct all combinations and put into one model table
cml <- create.model.list(c("Phi","p")) # makes all possible combinations of those parameter formulas
results <- crm.wrapper(cml,
data = turtleyear1.proc,
ddl = turtleyear1.ddl,
external = FALSE,
accumulate = FALSE,
hessian = TRUE)
return(results)
}
# Run function
turtleyear1.cjs.models <- fit.turtleyear1.cjs.models()
turtleyear1.cjs.models
## model npar AIC DeltaAIC weight
## 6 Phi(~Size.Class)p(~time) 9 296.2526 0.000000 5.504183e-01
## 3 Phi(~1)p(~time) 6 296.7739 0.521232 4.241396e-01
## 9 Phi(~Size.Class * time)p(~time) 25 303.6252 7.372585 1.379610e-02
## 12 Phi(~time)p(~time) 10 303.9641 7.711443 1.164593e-02
## 11 Phi(~time)p(~Size.Class) 9 328.7309 32.478291 4.876649e-08
## 10 Phi(~time)p(~1) 6 336.5208 40.268160 9.921404e-10
## 7 Phi(~Size.Class * time)p(~1) 21 337.7690 41.516406 5.315204e-10
## 2 Phi(~1)p(~Size.Class) 5 339.9153 43.662679 1.817450e-10
## 8 Phi(~Size.Class * time)p(~Size.Class) 24 339.9213 43.668727 1.811963e-10
## 5 Phi(~Size.Class)p(~Size.Class) 8 344.0413 47.788728 2.309417e-11
## 4 Phi(~Size.Class)p(~1) 5 345.5461 49.293472 1.088307e-11
## 1 Phi(~1)p(~1) 2 346.6537 50.401084 6.255134e-12
## neg2lnl convergence
## 6 278.2526 0
## 3 284.7739 0
## 9 253.6252 0
## 12 283.9641 0
## 11 310.7309 0
## 10 324.5208 0
## 7 295.7690 0
## 2 329.9153 0
## 8 291.9213 0
## 5 328.0413 0
## 4 335.5461 0
## 1 342.6537 0
We see in the listings of these models, because their ranks are less than two apart in their AIC’s, that the best model here is undetermined between two models. The models are the model using size class specific estimates for \(\phi\) and year specific estimates for \(p\), and the model with a constant estimate for \(\phi\) and year specific estimates for \(p\). We cannot determine between these two models which is better because they are less than two apart in their AIC values. Therefore we can look at both of these two models and the predictions they produce.
sizevariable.proc <- process.data(Turtles_ch_by_Year_Size,
group = "Size.Class") # group variable has to be in the data
# Make design data (from processed data)
sizevariable.ddl <- make.design.data(sizevariable.proc)
# Outine formulas for each parameter
Phi.dot <- list(formula=~1) # ~1 is always a constant (or single estimate)
Phi.Size.Class <- list(formula=~Size.Class) # This formula will have an intercept (for females) and an estimate for the difference between females and males
p.time <- list(formula=~time) # Be careful of case-sensitive names. Use the exact group column that was in data
# Make new model (using design data) with constant survival, but different detection probabilities between sexes
cjs.m2 <- crm(sizevariable.proc,
sizevariable.ddl,
model.parameters = list(Phi = Phi.Size.Class,
p = p.time),
accumulate = FALSE)
predict(cjs.m2)
## $Phi
## Size.Class occ estimate
## 1 3 4 0.9692671
## 2 2 3 0.9365342
## 3 1 5 0.8030435
## 4 4 4 0.9343293
##
## $p
## time occ estimate
## 1 5 5 0.9325974
## 2 6 6 0.4993684
## 3 4 4 0.8042439
## 4 3 3 0.8687363
## 5 2 2 0.2198600
The predictions here give us that survival is lowest in turtles of the smallest size class, at about 80%, about 94% in class 2, about 97% in class 3, and lastly about 93% in class 4. The survival again is seen to vary a lot by year with the lowest at about 22% in 2019 and the highest at about 93% in 2022. The sixth year, 2023, also has a comparatively low \(p\) at about 50%.
timep.proc <- process.data(Turtles_ch_by_Year_Size,
group = "Size.Class") # group variable has to be in the data
# Make design data (from processed data)
timep.ddl <- make.design.data(timep.proc)
# Outine formulas for each parameter
Phi.dot <- list(formula=~1) # ~1 is always a constant (or single estimate)
Phi.Size.Class <- list(formula=~1) # This formula will have an intercept (for females) and an estimate for the difference between females and males
p.time <- list(formula=~time) # Be careful of case-sensitive names. Use the exact group column that was in data
# Make new model (using design data) with constant survival, but different detection probabilities between sexes
cjs.m3 <- crm(timep.proc,
timep.ddl,
model.parameters = list(Phi = Phi.dot,
p = p.time),
accumulate = FALSE)
predict(cjs.m3)
## $Phi
## occ estimate
## 1 4 0.9172252
##
## $p
## time occ estimate
## 1 5 5 0.9356866
## 2 6 6 0.4935221
## 3 4 4 0.8022563
## 4 3 3 0.8680456
## 5 2 2 0.2201165
This model gives us similar estimates to the previous model for year specific estimates of detection, but gives us an estimate of survival that is constant across all size classes and years, which is about 92%.
We see in the models that we built that survival appears to be fairly constant across years and across sexes as well, but may vary based on size class. In the model where \(\phi\) is differentiated based on size class, it is lowest in turtles of the smallest size class and then goes up and remains pretty constant for the larger size classes. This makes sense from an ecological perspective because smaller and less established animals tend to have a lower chance of survival. In all of the models where \(\phi\) is constant, its value is predicted to be roughly 91-92%. It is interesting how the probability of detection varies so much between years, with 2019 notably having very low rates of detection at about 22% in all models. The year 2023 also has fairly low detection at about 50% in most models explored here. For the other years they are about 87% for 2020, 80% for 2021, and about 94% for 2022. This is interesting when compared to the number of capture days in each of the years: in 2019 there were 11, 2020 had 13, 2021 had 7, 2022 had 13 and 2023 had 6. We see that, though 2019 is the lowest year for detection probability, it had a fairly standard number of capture events. So while a correlation between capture days and detection would make sense, there is likely something else influencing detection in this data set, either in addition to capture days or instead of capture days. It is also interesting to note that sex of the turtles did not have enough of an effect on either survival or detection for these turtles to be worth including in the model.
This modeling method had strengths in that it allows for multiple categorical variables to be looked at as factors in the modeling process, and especially that it allowed for year specific estimates of \(\phi\) and \(p\). A weakness is that this modeling technique could only handle capture events by year, and while this data set had 57 separate capture events recorded, they had to be collapsed down into capture histories by year over the 6 years in which they were carried out. A robust design model might be a better way to handle all of the capture events and could be interesting to look into further with this data set. Another weakness is that the variables of size class and sex could not be put into models together because of the differences in the sizes of these data sets due to the missing data on the turtle of unknown size. Creating a separate class of unknown for this turtle would have led to the model creating a survival probability for this turtle alone, and would have likely introduced unnecessary complication of the model.
Another weakness of this model is that the variable of size based on plastron length had to be made into a categorical variable, size class, for the analysis and therefore could not be looked at as a continuous variable, so some information was lost in the grouping of this variable. This was a constraint of the model only being able to handle categorical variables or groups, however the model may have been more accurate if size was allowed to be a continuous numerical variable. This might be worth looking into models that allow for survival or detection to differ based on quantitative variables that are continuous.