## First example -- 3 passes
ct3 <- c(77,50,37)
# Carle Strub (default) method
p1 <- removal(ct3)
summary(p1)
summary(p1,verbose=TRUE)
summary(p1,parm="No")
summary(p1,parm="p")
confint(p1)
confint(p1,parm="No")
confint(p1,parm="p")
# Moran method
p2 <- removal(ct3,method="Moran")
summary(p2,verbose=TRUE)
confint(p2,verbose=TRUE)
#'
# Schnute method
p3 <- removal(ct3,method="Schnute")
summary(p3,verbose=TRUE)
confint(p3,verbose=TRUE)
# Burnham method
p4 <- removal(ct3,method="Burnham")
summary(p4)
summary(p4,verbose=TRUE)
summary(p4,parm="No")
summary(p4,parm="p")
confint(p4)
confint(p4,parm="No")
confint(p4,parm="p")
## Second example -- 2 passes
ct2 <- c(77,37)
# Seber method
p4 <- removal(ct2,method="Seber2")
summary(p4,verbose=TRUE)
confint(p4)
## Use formula with a data.frame
d <- data.frame(ct=ct3)
p1a <- removal(~ct,data=d)
summary(p1a,verbose=TRUE)
confint(p1a,incl.est=TRUE)
### Test if catchability differs between first sample and the other samples
# chi-square test statistic from negative log-likelihoods
# from Moran and Schnute fits (from above)
chi2.val <- 2*(p2$min.nlogLH-p3$min.nlogLH)
# p-value ... no significant difference
pchisq(chi2.val,df=1,lower.tail=FALSE)
# Another LRT example ... sample 1 from Schnute (1983)
ct4 <- c(45,11,18,8)
p2a <- removal(ct4,method="Moran")
p3a <- removal(ct4,method="Schnute")
chi2.val <- 2*(p2a$min.nlogLH-p3a$min.nlogLH) # 4.74 in Schnute(1983)
pchisq(chi2.val,df=1,lower.tail=FALSE) # sig diff (catchability differs)
summary(p3a)
# Demonstrate multiple groups ... data in long format
## create a dummy data frame
d <- data.frame(lake=factor(rep(c("Ash Tree","Bark","Clay"),each=5)),
year=factor(rep(c("2010","2011","2010","2011","2010","2011"),
times=c(2,3,3,2,2,3))),
pass=factor(c(1,2,1,2,3,1,2,3,1,2,1,2,1,2,3)),
catch=c(57,34,65,34,12,54,26,9,54,27,67,34,68,35,12))
d
## note use of confint with incl.est= and as.df=
if (require(dplyr) & require(tidyr)) {
res <- d %>%
dplyr::group_by(interaction(lake,year)) %>%
dplyr::group_modify(~confint(removal(~catch,data=.x),
incl.est=TRUE,as.df=TRUE)) %>%
tidyr::separate_wider_delim(1,names=c("lake","year"),delim=".") %>%
as.data.frame() # removes tibble and grouping structure
res
}
# Demonstrate multiple groups ... data in wide format
## create a dummy data frame ... same data as previous ... note that this is
## not an efficient way to enter data, used here just for simple example
d2w <- rbind(data.frame(lake="Ash Tree",year=2011,pass1=65,pass2=34,pass3=12),
data.frame(lake="Bark",year=2010,pass1=54,pass2=26,pass3=9),
data.frame(lake="Bark",year=2011,pass1=54,pass2=27,pass3=NA),
data.frame(lake="Clay",year=2010,pass1=67,pass2=34,pass3=NA),
data.frame(lake="Clay",year=2011,pass1=68,pass2=35,pass3=12))
d2w
## convert to long format first
d2l <- tidyr::pivot_longer(d2w,cols=c("pass1","pass2","pass3"),
names_to="pass",values_to="catch")
d2l
## then same process as previous example
if (require(dplyr)) {
res2 <- d2l %>%
dplyr::group_by(interaction(lake,year)) %>%
dplyr::group_modify(~confint(removal(~catch,data=.x),
incl.est=TRUE,as.df=TRUE)) %>%
tidyr::separate_wider_delim(1,names=c("lake","year"),delim=".") %>%
as.data.frame() # removes tibble and grouping structure
res2
}
Run the code above in your browser using DataLab