if (FALSE) {
## house mouse dataset, morning trap clearances
## 81 female, 78 male, 1 unknown
morning <- subset(housemouse, occ = c(1,3,5,7,9))
summary(covariates(morning))
## speedy model fitting with coarse mask
mmask <- make.mask(traps(morning), buffer = 20, nx = 32)
## assuming equal detection of males and females
## fitted sex ratio p(female) = 0.509434 = 81 / (81 + 78)
fit.0 <- secr.fit(morning, hcov = "sex", mask = mmask, trace = FALSE)
predict(fit.0)
## allowing sex-specific detection parameters
## this leads to new estimate of sex ratio
fit.h2 <- secr.fit(morning, hcov = "sex", mask = mmask, trace = FALSE,
model = list(g0 ~ h2, sigma ~ h2))
predict(fit.h2)
## specifying newdata for h2 - equivalent to predict(fit.h2)
predict(fit.h2, newdata = data.frame(h2 = factor(c('f','m'))))
## conditional likelihood fit of preceding model
## estimate of sex ratio does not change
fit.CL.h2 <- secr.fit(morning, hcov = "sex", mask = mmask, trace = FALSE,
CL = TRUE, model = list(g0 ~ h2, sigma ~ h2))
predict(fit.CL.h2)
## did sexes differ in detection parameters?
fit.CL.0 <- secr.fit(morning, hcov = "sex", mask = mmask, trace = FALSE,
CL = TRUE, model = list(g0 ~ 1, sigma ~ 1))
LR.test(fit.CL.h2, fit.CL.0)
## did sex ratio deviate from 1:1?
fit.CL.h2.50 <- secr.fit(morning, hcov = "sex", mask = mmask, trace = FALSE,
CL = TRUE, model = list(g0 ~ h2, sigma ~ h2), fixed = list(pmix = 0.5))
LR.test(fit.CL.h2, fit.CL.h2.50)
## did sexes show extra-compensatory variation in lambda0?
## (Efford and Mowat 2014)
fit.CL.a0 <- secr.fit(morning, hcov = "sex", mask = mmask, trace = FALSE,
CL = TRUE, model = list(a0 ~ 1, sigma ~ h2))
LR.test(fit.CL.h2, fit.CL.a0)
## trend in ovenbird sex ratio, assuming sex-specific detection
omask <- make.mask(traps(ovenCH), buffer = 300, nx = 32)
fit.sextrend <- secr.fit(ovenCH, model = list(g0~h2, sigma~h2, pmix~Session),
hcov = "Sex", CL = TRUE, mask = omask, trace = FALSE)
predict(fit.sextrend)[1:5]
}
Run the code above in your browser using DataLab