estimatePopsize
first fits appropriate (v)glm model and
then estimates full (observed and unobserved) population size.
In this types of models it is assumed that the response vector
(i.e. the dependent variable) corresponds to the number of times a given unit
was observed in the source.
Population size is then usually estimated by Horvitz-Thompson type estimator:
N = _k=1^NI_kP(Y_k>0) = _k=1^N_obs11-P(Y_k=0)
where I_k=I_Y_k > 0 are indicator variables, with value 1 if kth unit was observed at least once and 0 otherwise.
estimatePopsize(formula, ...)# S3 method for default
estimatePopsize(
formula,
data,
model = c("ztpoisson", "ztnegbin", "ztgeom", "zotpoisson", "ztoipoisson",
"oiztpoisson", "ztHurdlepoisson", "Hurdleztpoisson", "zotnegbin", "ztoinegbin",
"oiztnegbin", "ztHurdlenegbin", "Hurdleztnegbin", "zotgeom", "ztoigeom", "oiztgeom",
"ztHurdlegeom", "ztHurdlegeom", "zelterman", "chao"),
weights = NULL,
subset = NULL,
naAction = NULL,
method = c("optim", "IRLS"),
popVar = c("analytic", "bootstrap", "noEst"),
controlMethod = NULL,
controlModel = NULL,
controlPopVar = NULL,
modelFrame = TRUE,
x = FALSE,
y = TRUE,
contrasts = NULL,
ratioReg = FALSE,
offset,
...
)
Returns an object of class c("singleRStaticCountData", "singleR", "glm", "lm")
with type list
containing:
y
-- Vector of dependent variable if specified at function call.
X
-- Model matrix if specified at function call.
formula
-- A list with formula provided on call and additional formulas specified in controlModel
.
call
-- Call matching original input.
coefficients
-- A vector of fitted coefficients of regression.
control
-- A list of control parameters for controlMethod
and controlModel
, controlPopVar
is included in populationSize.
model
-- Model which estimation of population size and regression was built, object of class family.
deviance
-- Deviance for the model.
priorWeights
-- Prior weight provided on call.
weights
-- If IRLS
method of estimation was chosen weights returned by IRLS
, otherwise same as priorWeights
.
residuals
-- Vector of raw residuals.
logL
-- Logarithm likelihood obtained at final iteration.
iter
-- Numbers of iterations performed in fitting or if stats::optim
was used number of call to loglikelihood function.
dfResiduals
-- Residual degrees of freedom.
dfNull
-- Null degrees of freedom.
fittValues
-- Data frame of fitted values for both mu (the expected value) and lambda (Poisson parameter).
populationSize
-- A list containing information of population size estimate.
modelFrame
-- Model frame if specified at call.
linearPredictors
-- Vector of fitted linear predictors.
sizeObserved
-- Number of observations in original model frame.
terms
-- terms attribute of model frame used.
contrasts
-- contrasts specified in function call.
naAction
-- naAction used.
which
-- list indicating which observations were used in regression/population size estimation.
fittingLog
-- log of fitting information for "IRLS"
fitting if specified in controlMethod
.
a formula for the model to be fitted, only applied to the "main" linear predictor. Only single response models are available.
additional optional arguments passed to other methods eg.
estimatePopsizeFit
.
a data frame or object coercible to data.frame class containing data for the regression and population size estimation.
a model for regression and population estimate full description in singleRmodels()
.
an optional object of prior weights used in fitting the model.
Can be used to specify number of occurrences of rows in data see controlModel()
a logical vector indicating which observations should be used
in regression and population size estimation. It will be evaluated on data
argument provided on call.
Not yet implemented.
a method for fitting values currently supported: iteratively
reweighted least squares (IRLS
) and maximum likelihood (optim
).
a method of constructing confidence interval and estimating
the standard error either analytic or bootstrap.
Bootstrap confidence interval type may be specified in
controlPopVar.
There is also the third possible value of noEst
which skips the population size estimate all together.
a list indicating parameters to use in fitting the model
may be constructed with singleRcapture::controlMethod
function.
More information included in controlMethod()
.
a list indicating additional formulas for regression
(like formula for inflation parameter/dispersion parameter) may be
constructed with singleRcapture::controlModel
function.
More information will eventually be included in controlModel()
.
a list indicating parameters to use in estimating variance
of population size estimation may be constructed with
singleRcapture::controlPopVar
function.
More information included in controlPopVar()
.
logical values indicating whether to return model matrix, dependent vector and model matrix as a part of output.
not yet implemented.
Not yet implemented
a matrix of offset values with the number of columns matching the number of distribution parameters providing offset values to each of linear predictors.
Piotr Chlebicki, Maciej Beręsewicz
The generalized linear model is characterized by equation
=X
where X is the (lm) model matrix.
The vector generalized linear model is similarly characterized by equations
_k=X_k_k
where X_k is a (lm) model
matrix constructed from appropriate formula
(specified in controlModel
parameter).
The is then a vector constructed as:
=pmatrix
_1
_2
_p
pmatrix^T
and in cases of models in our package the (vlm) model matrix is constructed as a block matrix:
X_vlm=
pmatrix
X_1 & 0 & &0
0 & X_2 & &0
& & &
0 & 0 & &X_p
pmatrix
this differs from convention in VGAM
package (if we only consider our
special cases of vglm models) but this is just a convention and does not
affect the model, this convention is taken because it makes fitting with
IRLS (explanation of algorithm in estimatePopsizeFit()
) algorithm easier.
(If constraints
matrixes in vglm
match the ones we implicitly
use the vglm
model matrix differs with respect to order of
kronecker
multiplication of X
and constraints
.)
In this package we use observed likelihood to fit regression models.
As mentioned above usually the population size estimation is done via: N = _k=1^NI_kP(Y_k>0) = _k=1^N_obs11-P(Y_k=0)
where I_k=I_Y_k > 0 are indicator variables, with value 1 if kth unit was observed at least once and 0 otherwise. The P(Y_k>0) are estimated by maximum likelihood.
The following assumptions are usually present when using the method of estimation described above:
The specified regression model is correct. This entails linear relationship between independent variables and dependent ones and dependent variable being generated by appropriate distribution.
No unobserved heterogeneity. If this assumption is broken there
are some possible (admittedly imperfect) workarounds see details in
singleRmodels()
.
The population size is constant in relevant time frame.
Depending on confidence interval construction (asymptotic) normality of N statistic is assumed.
There are two ways of estimating variance of estimate N,
the first being "analytic"
usually done by application of
law of total variance to N:
var(N)=E(var (N|I_1,...,I_n))+ var(E(N|I_1,...,I_n))
and then by method to N|I_1,... I_N:
E(var (N|I_1,...,I_n))= .((N|I_1,...,I_N))^T cov() ((N|I_1,...,I_N)) |_=
and the var(E(N|I_1,...,I_n)) term may be derived analytically (if we assume independence of observations) since N|I_1,...,I_n is just a constant.
In general this gives us:
aligned
var(E(N|I_1,...,I_n))&=
var(_k=1^NI_kP(Y_k>0))
&=_k=1^Nvar(I_kP(Y_k>0))
&=_k=1^N1P(Y_k>0)^2var(I_k)
&=_k=1^N1P(Y_k>0)^2P(Y_k>0)(1-P(Y_k>0))
&=_k=1^N1P(Y_k>0)(1-P(Y_k>0))
&_k=1^NI_kP(Y_k>0)^2(1-P(Y_k>0))
&=_k=1^N_obs1-P(Y_k>0)P(Y_k>0)^2
aligned
Where the approximation on 6th line appears because in 5th line we sum over all units, that includes unobserved units, since I_k are independent and I_k b(P(Y_k>0)) the 6th line is an unbiased estimator of the 5th line.
The other method for estimating variance is "bootstrap"
, but since
N_obs=_k=1^NI_k is also a random variable bootstrap
will not be as simple as just drawing N_obs units from data
with replacement and just computing N.
Method described above is referred to in literature as "nonparametric"
bootstrap (see controlPopVar()
), due to ignoring variability in observed
sample size it is likely to underestimate variance.
A more sophisticated bootstrap procedure may be described as follows:
Compute the probability distribution as:
f_0N, f_1N, ..., f_yN where f_n denotes observed marginal frequency of units being observed exactly n times.
Draw N units from the distribution above (if N is not an integer than draw N + b(N-N)), where is the floor function.
Truncated units with y=0.
If there are covariates draw them from original data with replacement from uniform distribution. For example if unit drawn to new data has y=2 choose one of covariate vectors from original data that was associated with unit for which was observed 2 times.
Regress y_new on X_vlm new and obtain _new, with starting point to make it slightly faster, use them to compute N_new.
Repeat 2-5 unit there are at least B
statistics are obtained.
Compute confidence intervals based on alpha
and confType
specified in controlPopVar()
.
To do step 1 in procedure above it is convenient to first draw binary vector of length N + b(N-N) with probability 1-f_0N, sum elements in that vector to determine the sample size and then draw sample of this size uniformly from the data.
This procedure is known in literature as "semiparametric"
bootstrap
it is necessary to assume that the have a correct estimate
N in order to use this type of bootstrap.
Lastly there is "paramteric"
bootstrap where we assume that the
probabilistic model used to obtain N is correct the
bootstrap procedure may then be described as:
Draw N + b(N-N) covariate information vectors with replacement from data according to probability distribution that is proportional to: N_k, where N_k is the contribution of kth unit i.e. 1P(Y_k>0).
Determine matrix using estimate .
Generate y (dependent variable) vector using and probability mass function associated with chosen model.
Truncated units with y=0 and construct y_new and X_vlm new.
Regress y_new on X_vlm new and obtain _new use them to compute N_new.
Repeat 1-5 unit there are at least B
statistics are obtained.
Compute confidence intervals based on alpha
and confType
specified in controlPopVar()
It is also worth noting that in the "analytic"
method estimatePopsize
only uses "standard" covariance matrix estimation. It is possible that improper
covariance matrix estimate is the only part of estimation that has its assumptions
violated. In such cases post-hoc procedures are implemented in this package
to address this issue.
Lastly confidence intervals for N are computed (in analytic case) either by assuming that it follows a normal distribution or that variable (N-N) follows a normal distribution.
These estimates may be found using either summary.singleRStaticCountData
method or popSizeEst.singleRStaticCountData
function. They're labelled as
normal
and logNormal
respectively.
General single source capture recapture literature:
Zelterman, Daniel (1988). ‘Robust estimation in truncated discrete distributions with application to capture-recapture experiments’. In: Journal of statistical planning and inference 18.2, pp. 225–237.
Heijden, Peter GM van der et al. (2003). ‘Point and interval estimation of the population size using the truncated Poisson regression model’. In: Statistical Modelling 3.4, pp. 305–322. doi: 10.1191/1471082X03st057oa.
Cruyff, Maarten J. L. F. and Peter G. M. van der Heijden (2008). ‘Point and Interval Estimation of the Population Size Using a Zero-Truncated Negative Binomial Regression Model’. In: Biometrical Journal 50.6, pp. 1035–1050. doi: 10.1002/bimj.200810455
Böhning, Dankmar and Peter G. M. van der Heijden (2009). ‘A covariate adjustment for zero-truncated approaches to estimating the size of hidden and elusive populations’. In: The Annals of Applied Statistics 3.2, pp. 595–610. doi: 10.1214/08-AOAS214.
Böhning, Dankmar, Alberto Vidal-Diez et al. (2013). ‘A Generalization of Chao’s Estimator for Covariate Information’. In: Biometrics 69.4, pp. 1033– 1042. doi: 10.1111/biom.12082
Böhning, Dankmar and Peter G. M. van der Heijden (2019). ‘The identity of the zero-truncated, one-inflated likelihood and the zero-one-truncated likelihood for general count densities with an application to drink-driving in Britain’. In: The Annals of Applied Statistics 13.2, pp. 1198–1211. doi: 10.1214/18-AOAS1232.
Navaratna WC, Del Rio Vilas VJ, Böhning D. Extending Zelterman's approach for robust estimation of population size to zero-truncated clustered Data. Biom J. 2008 Aug;50(4):584-96. doi: 10.1002/bimj.200710441.
Böhning D. On the equivalence of one-inflated zero-truncated and zero-truncated one-inflated count data likelihoods. Biom J. 2022 Aug 15. doi: 10.1002/bimj.202100343.
Böhning, D., Friedl, H. Population size estimation based upon zero-truncated, one-inflated and sparse count data. Stat Methods Appl 30, 1197–1217 (2021). doi: 10.1007/s10260-021-00556-8
Bootstrap:
Zwane, PGM EN and Van der Heijden, Implementing the parametric bootstrap in capture-recapture models with continuous covariates 2003 Statistics & probability letters 65.2 pp 121-125
Norris, James L and Pollock, Kenneth H Including model uncertainty in estimating variances in multiple capture studies 1996 in Environmental and Ecological Statistics 3.3 pp 235-244
Vector generalized linear models:
Yee, T. W. (2015). Vector Generalized Linear and Additive Models: With an Implementation in R. New York, USA: Springer. ISBN 978-1-4939-2817-0.
stats::glm()
-- For more information on generalized linear models.
stats::optim()
-- For more information on optim
function used in
optim
method of fitting regression.
controlMethod()
-- For control parameters related to regression.
controlPopVar()
-- For control parameters related to population size estimation.
controlModel()
-- For control parameters related to model specification.
estimatePopsizeFit()
-- For more information on fitting procedure in
esitmate_popsize
.
popSizeEst()
redoPopEstimation()
-- For extracting population size
estimation results are applying post-hoc procedures.
summary.singleRStaticCountData()
-- For summarizing important information about the
model and population size estimation results.
marginalFreq()
-- For information on marginal frequencies and comparison
between observed and fitted quantities.
VGAM::vglm()
-- For more information on vector generalized linear models.
singleRmodels()
-- For description of various models.
# \donttest{
# Model from 2003 publication
# Point and interval estimation of the
# population size using the truncated Poisson regression mode
# Heijden, Peter GM van der et al. (2003)
model <- estimatePopsize(
formula = capture ~ gender + age + nation,
data = netherlandsimmigrant,
model = ztpoisson
)
summary(model)
# Graphical presentation of model fit
plot(model, "rootogram")
# Statistical test
# see documentation for summary.singleRmargin
summary(marginalFreq(model), df = 1, "group")
# We currently support 2 methods of numerical fitting
# (generalized) IRLS algorithm and via stats::optim
# the latter one is faster when fitting negative binomial models
# (and only then) due to IRLS having to numerically compute
# (expected) information matrixes, optim is also less reliable when
# using alphaFormula argument in controlModel
modelNegBin <- estimatePopsize(
formula = TOTAL_SUB ~ .,
data = farmsubmission,
model = ztnegbin,
method = "optim"
)
summary(modelNegBin)
summary(marginalFreq(modelNegBin))
# More advanced call that specifies additional formula and shows
# in depth information about fitting procedure
pseudoHurdleModel <- estimatePopsize(
formula = capture ~ nation + age,
data = netherlandsimmigrant,
model = Hurdleztgeom,
method = "IRLS",
controlMethod = controlMethod(verbose = 5),
controlModel = controlModel(piFormula = ~ gender)
)
summary(pseudoHurdleModel)
# Assessing model fit
plot(pseudoHurdleModel, "rootogram")
summary(marginalFreq(pseudoHurdleModel), "group", df = 1)
# A advanced input with additional information for fitting procedure and
# additional formula specification and different link for inflation parameter.
Model <- estimatePopsize(
formula = TOTAL_SUB ~ .,
data = farmsubmission,
model = oiztgeom(omegaLink = "cloglog"),
method = "IRLS",
controlMethod = controlMethod(
stepsize = .85,
momentumFactor = 1.2,
epsilon = 1e-10,
silent = TRUE
),
controlModel = controlModel(omegaFormula = ~ C_TYPE + log_size)
)
summary(marginalFreq(Model), df = 18 - length(Model$coefficients))
summary(Model)
# }
Run the code above in your browser using DataLab