Thanks Murray for your recent fix to region.N and suggestions for
obtaining sex-specific abundance estimates.
I have a few questions about estimating abundance with a couple of the
sex-specific models.
1) I have coded sex-specific models both using male/female as a
'session' and using 'sex' as a covariate. The advantage of the 'session'
approach is that region.N gives you sex-specific abundance estimates. Is
there a way to get a total population estimate? I suppose I could use
the delta method to combine the male and female variance estimates, but
is that appropriate if some parameters are in common between sexes (so
the covariance is ^=0; e.g., g0 ~ 1, and sigma ~ sex)? Or at least close
enough?
library(secr)
ov1 <- subset(ovenCH, session = 1)
msk <- make.mask(traps(ov1), buffer = 300, nx = 25, type = 'trapbuffer')
ofit4 <- secr.fit (ov1MF, model = list(D~session, sigma~session), mask = msk,
details = list(contrasts = list(session = contr.sum)))
exp(coef(ofit4)['D',-2]) * 2 # double average for 2 sexes
# beta lcl ucl
# D 0.9835145 0.4710242 2.053611
2) With 'sex' as a covariate I used the derived() function to obtain
sex-specific density estimates. However, it appears the CIs are much
smaller than when I use 'session'. I assume that these derived density
estimates are missing some variance component? Any suggestions? In my
data it is pretty clear that the sex ratio (M:F) is 1:2 so I suspect a
model without a sex effect is going to have smaller variance so I'd
prefer to combine the M and F estimates into a total abundance estimate.
# sex as covariate
ofit <- secr.fit (ov1, CL = TRUE, sigma~Sex, mask = msk)
derived(ofit, groups = 'Sex')
# $`F`
# estimate SE.estimate lcl ucl CVn CVa CVD
# esa 13.7693154 NA NA NA NA NA NA
# D 0.5083768 0.3144909 0.1665909 1.551387 0.3779645 0.4897253 0.6186178
#
# $M
# estimate SE.estimate lcl ucl CVn CVa CVD
# esa 27.3297900 NA NA NA NA NA NA
# D 0.4756714 0.2035574 0.2129357 1.06259 0.2773501 0.3258942 0.427937
# sex as session
ov1MF <- split(ov1, covariates(ov1)$Sex)
ofit2 <- secr.fit (ov1MF, model = list(D~session, sigma~session), mask = msk)
predict(ofit2)
# $`session = F`
# link estimate SE.estimate lcl ucl
# D log 0.50838366 0.347195208 0.15119452 1.70941349
# g0 logit 0.02399149 0.008476867 0.01194642 0.04759607
# sigma log 60.68164425 21.615116367 30.82217364 119.46795161
#
# $`session = M`
# link estimate SE.estimate lcl ucl
# D log 0.47567130 0.213242719 0.20561063 1.10044499
# g0 logit 0.02399149 0.008476867 0.01194642 0.04759607
# sigma log 96.19470928 24.996740460 58.28609125 158.75866601
3) The reason I'd like to use 'sex' as a covariate is that I have
surveys from different years and would like to share some parameters
across years (like having sigma different by sex but the same across
years) and I don't see how to do that using the 'session' approach -
unless I am missing some trick... Suggestions?
sesscovdf <- data.frame(year = factor(rep(2005:2009, each = 2)), sex = rep(c('F','M'), 5))
sesscovdf
# year sex
# 1 2005 F
# 2 2005 M
# 3 2006 F
# 4 2006 M
# 5 2007 F
# 6 2007 M
# 7 2008 F
# 8 2008 M
# 9 2009 F
# 10 2009 M
ofit5 <- secr.fit (ovMF, model = list(D~year, sigma~sex), mask = msk, sessioncov = sesscovdf)
fit.LR=secr.fit(Dat.LR, model= list(D~session,g0~1,sigma~T+session), mask=mask.LR, details=list(contrasts=list(session=contr.sum)))
reals =predict(fit.LR,realnames='D',type="response")
total.D=log(reals[[1]][1,2]+reals[[2]][1,2]) # yields total D on link scale; backtransforming gives same estimate as derived(CL model).
#
delta.mo = function(se) {
vr=se^2
mean.vr=sum(vr) / length(vr)
mean.se=sqrt(mean.vr)
return(mean.se)
}
#
betas=predict(fit.LR, realnames='D', type="link")
mean.se = delta.mo(se=c(betas[[1]][1,3],betas[[2]][1,3]))
CI = c(mean.d - (1.96*mean.se), mean.d + (1.96*mean.se))
#
real.D.CI = c(exp(mean.d), exp(CI))
real.D.CI
# 0.0015536801 0.0006751119 0.0035755877
# where "der" is the data frame created when one applies derived() to a fitted model,
# such that der[2,1] and der[2,2] are the estimated density and it's SE on the real scale, respectively:
#
SE.derived.D= function(der) {
se.D.link = sqrt(log(1+(der[2,2] / der[2,1])^2))
return(se.D.link)
}