Using the mallard example, I first created a code that ran successfully for nest survival estimates for a shorebird species. The nocc = 129. The sample size was 96 nests.
Then I wanted to look at cumulative chick survival from the time that nests were found until they fledged or failed. This used a subset of my nests including only those that hatched (n =). Nocc = 145 (from my season start date when we started monitoring nests on April 1 until the last nest check date on August 8.
However, when I run the equivalent of mallard.results, the daily survival rate estimate for every single day for the 145 days = 1. Not sure why this occurred? I'm using the same code structure as the previous with nest survival, and just changed the nocc.
Does this have to deal with such a lengthy nocc?
- Code: Select all
```{r}
library(RMark)
library(dplyr)
setwd("C://Users//lbrow//Documents//Trent University//AMOY//Data Analysis//2022 Data Analysis//2022 nest survival analysis//2022 cumulative chick survival analysis")
NestSurvivalData = read.csv("2022 cumulative chick survival data.csv")
metadata = read.csv("2022 nest data c Jan 1 2023.csv")
#Add metadata columns to RMark data
NestSurvivalData$Island = metadata$Island[match(NestSurvivalData$NestID, metadata$NestID)]
#rename columns in RMark format
NestSurvivalData = NestSurvivalData %>%
rename("ID" = "UniqueID",
"LastPresent" = "ChickLastPresent",
"LastChecked" = "ChickLastChecked",
"Fate" = "FledgeFate")
#convert to numeric format
NestSurvivalData = NestSurvivalData %>%
mutate(FirstFound = as.numeric(FirstFound)) %>%
mutate(AgeFound = as.numeric(AgeFound)) %>%
mutate(AgeDay1 = as.numeric(AgeDay1)) %>%
mutate(LastPresent = as.numeric(LastPresent)) %>%
mutate(LastChecked = as.numeric(LastChecked))
#convert to factor format
NestSurvivalData = NestSurvivalData %>%
mutate(Island = as.factor(Island))
#check what levels exist in a factor variable
levels(NestSurvivalData$Island)
#Note: Quirks! RMark Does not like cells labeled as NA. It will automatically ignore cells with blank values. Thus it is best to leave the blank cells.DO NOT replace blank cells with NA values, otherwise get issues later on in the code.
summary(NestSurvivalData)
```
```{r}
#### Model Stage 1 - temporal predictor variables ####
#Specify parameters including the number of occasions, model type, grouping variables (factor variables)
amoy.process = process.data(NestSurvivalData, nocc = 225, model = "Nest", groups = "Island")
#this is where we start into RMark and making multiple models, so first we make the function
run.amoy=function()
{
# model of constant daily survival rate (DSR) (ie intercept-only model)
Null=list(formula=~1)
# model checking if Nest Age affects DSR
S.NestAge=list(formula=~NestAge)
# model checking if Island affects DSR - treats islands as factors
# and the output provides S-hats for each habitat type
S.Island=list(formula=~Island)
#DSR varies with nest age & island
S.NestAgeandIsland = list(formula = ~NestAge + Island)
#DSR varies with nest age & island
S.NestAgexIsland = list(formula = ~NestAge + Island + NestAge:Island)
# Return model table and list of models
amoy.model.list = create.model.list("Nest")
amoy.results = mark.wrapper(amoy.model.list,
data = amoy.process,
adjust = FALSE,delete=TRUE)
}
amoy.results=run.amoy() #this can take a minute or two to run, just go with it
amoy.results #shows the AICc table of your models you made above