First let’s read in the packages we’ll need, which are just RMark and ggplot2. Then we’ll read in the dipper data.
- Code: Select all
library(RMark)
library(ggplot2)
data(dipper)
Then, per standard procedure, we’ll process the data and create a .ddl. In this case we also create a simple model of Phi ~ time.
- Code: Select all
dp=process.data(dipper,model="CJS")
ddl=make.design.data(dp)
model=mark(dp,ddl,model.parameters = list(Phi=list(formula=~time)))
Now is where I realized that the best way to graph Phi (or any time varying parameter of interest) is to pull the estimated real values from the model. In this case the real values of phi correspond to rows 1:6 of the model$results$real, so we pull those rows. Note that for your own data you will need to determine which rows to use.
I also added in a dummy variable which is used for time (1:6 for 6 different sessions). If we then check the object we’ve created we see that it has the 6 values of phi corresponding to the 6 different sessions, and we have labeled time 1:6.
- Code: Select all
phi <- model$results$real[1:6,]
phi$time <- 1:6
View(phi)
We can then plot it using the code below:
- Code: Select all
phiXtime <- ggplot(data = phi, aes(x = time, y = estimate))+
geom_line(linewidth = 1.5)+
geom_errorbar(aes(ymin = lcl, ymax = ucl), width = 0.2) +
scale_colour_brewer(palette = "Set1") +
theme(legend.position = c(0.15, 0.8),
legend.justification = c(1, 0)) +
xlab("Year") +
ylab("Extinction probability")+
ggtitle("Extinction probability by year")+
theme_classic()+
ylim(c(0,1))
phiXtime