Title: | Latent Class Capture-Recapture Models |
---|---|
Description: | Estimation of latent class models with individual covariates for capture-recapture data. See Bartolucci, F. and Forcina, A. (2022), Estimating the size of a closed population by modeling latent and observed heterogeneity, Biometrics, 80(2), ujae017. |
Authors: | Francesco Bartolucci [aut, cre], Antonio Forcina [aut] |
Maintainer: | Francesco Bartolucci <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.0 |
Built: | 2024-11-21 03:40:16 UTC |
Source: | https://github.com/cran/LCCR |
Estimation of latent class models with individual covariates for capture-recapture data. See Bartolucci, F. and Forcina, A. (2022), Estimating the size of a closed population by modeling latent and observed heterogeneity, Biometrics, 80(2), ujae017.
The package provides functions to specify latent class models for capture-recapture data with individual covariates, simulate data from the specified model and estimate it on the basis of observed data, including the possibility to obtain a profile confidence interval for the population size.
The latent class models may be specified by a log-linear or a recursive logit parametrization of the conditional distribution of the capture configurations given the latent class. The log-linear parametrization is based on main effects that may depend on some covariates and may include bivariate interaction terms. The recursive logit parametrization allows us to model the dependence of capture probabilities on previous capture history. Linear constraints on the model parameters may be assumed to make the model more parsimonious. Covariates may also affect the latent class weights by a Multinomial logit parametrization.
Estimation of the specified model is based on the unconditional likelihood method following the approach formalized in Forcina and Bartolucci (2021), which may be seen as a refinement of the one in Liu et al. (2017). The approach uses as additional parameters the weights associated to the different strata that are estimated together with the model parameters and the population size. Functions for constructing a profile confidence interval for the population size are provided; this proceduire is recommended as an alternative to using the normal approximation.
Functions for conditional maximum likelihood estimation as described in Bartolucci and Forcina (2006) are also included in the package.
Francesco Bartolucci [aut, cre], Antonio Forcina [aut]
Maintainer: Francesco Bartolucci <[email protected]>
Bartolucci, F. and Forcina, A. (2006). Estimating the size of a closed population by modeling latent and observed heterogeneity. Journal of the American Statistical Association, 101, 786-794.
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
Liu, Y., Li, P., and Qin, J. (2017). Maximum empirical likelihood estimation for abundance in a closed population from capture-recapture data. Biometrika, 104, 527-543.
data(data_sim2) # estimate latent class model with 2 classes, same main log-linear effect across lists, # one covariate affecting the weights, and bivariate interaction between consecutive lists est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") est # compute profile confidence interval conf = confint(est) conf plot(conf)
data(data_sim2) # estimate latent class model with 2 classes, same main log-linear effect across lists, # one covariate affecting the weights, and bivariate interaction between consecutive lists est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") est # compute profile confidence interval conf = confint(est) conf plot(conf)
Given a matrix of individual capture configurations, and the corresponding matrix and array of covariates (affecting the class weights and the conditional capture probabilities given the latent class), the function aggregates data, providing a stratified capture-recapture format.
aggr_data(Y, W = NULL, X = NULL)
aggr_data(Y, W = NULL, X = NULL)
Y |
matrix of frequencies of capture configurations |
W |
matrix of covariates affecting the class weights |
X |
array of covariates affecting the conditional capture probabilities |
Ya |
matrix of aggregated frequencies of capture configurations |
Wa |
matrix of aggregated covariates affecting the class weights |
Xa |
array of aggregated covariates affecting the conditional capture probabilities |
Francesco Bartolucci, Antonio Forcina
# case without covariates Y = rbind(c(0,1,0,0,0,0,0,0),c(0,0,0,1,0,0,0,0),c(0,0,0,0,0,0,1,0)) aggr_data(Y) # case with covariates W = c(1,1,2); X = as.matrix(c(0,0,2)) aggr_data(Y,W,X)
# case without covariates Y = rbind(c(0,1,0,0,0,0,0,0),c(0,0,0,1,0,0,0,0),c(0,0,0,0,0,0,1,0)) aggr_data(Y) # case with covariates W = c(1,1,2); X = as.matrix(c(0,0,2)) aggr_data(Y,W,X)
Profile confidence interval for a latent class model with covariates.
## S3 method for class 'estLCCR' confint(object, parm = list(), level = 0.95, ...)
## S3 method for class 'estLCCR' confint(object, parm = list(), level = 0.95, ...)
object |
output from |
parm |
a list containing control arguments for the step length of the N values( |
level |
the confidence level required |
... |
additional argument(s) for methods |
conf |
confidence interval |
Nv |
vector of values of N tried |
lkv |
corresponding vector of log-likelihood values |
level |
level of confidence |
Nh |
point estimate of N |
lkh |
maximum log-likelihood values |
lk1 |
log-likelihood value at the lower bound |
lk2 |
log-likelihood value at the upper bound |
step |
step used in the grid search |
err |
error in the grid search |
Francesco Bartolucci, Antonio Forcina
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
Liu, Y., Li, P., and Qin, J. (2017). Maximum empirical likelihood estimation for abundance in a closed population from capture-recapture data. Biometrika, 104, 527-543.
data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") conf = confint(est) plot(conf)
data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") conf = confint(est) plot(conf)
Profile confidence interval for a latent class model with covariates based on the CML method.
## S3 method for class 'estLCCRcon' confint(object, parm = list(), level = 0.95, ...)
## S3 method for class 'estLCCRcon' confint(object, parm = list(), level = 0.95, ...)
object |
output from |
parm |
a list containing control arguments for the step length of the N values( |
level |
the confidence level required |
... |
additional argument(s) for methods |
conf |
confidence interval |
Nv |
vector of values of N tried |
lkv |
corresponding vector of log-likelihood values |
level |
level of confidence |
Nh |
point estimate of N |
devh |
minimum deviance |
dev1 |
deviance at the lower bound |
dev2 |
deviance at the upper bound |
step |
step used in the grid search |
err |
error in the grid search |
Francesco Bartolucci, Antonio Forcina
Bartolucci, F. and Forcina, A. (2006). Estimating the size of a closed population by modeling latent and observed heterogeneity. Journal of the American Statistical Association, 101, 786-794.
data(data_sim2) est = estLCCRcon(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") conf = confint(est) plot(conf)
data(data_sim2) est = estLCCRcon(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") conf = confint(est) plot(conf)
Simulated capture-recapture data from a latent class model with 2 classes having the same weight on 5 lists.
data(data_sim1)
data(data_sim1)
A matrix containing the capture configurations at individual level.
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
data(data_sim1) est = estLCCR(Y=data_sim1,H=2)
data(data_sim1) est = estLCCR(Y=data_sim1,H=2)
Simulated capture-recapture data from a latent class model with 2 classes, one covariate affecting the class weights, and bivariate loglinear interactions between consecutive lists.
data(data_sim2)
data(data_sim2)
A list containing capture configurations at individual level and corresponding covariates.
Y
capture configurations
W
values of the covariate affecting the class weights
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same")
data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same")
Simulated capture-recapture data from a latent class model with 3 classes, one covariate affecting the logits of each response, and lag dependence.
data(data_sim3)
data(data_sim3)
A list containing capture configurations at individual level and corresponding covariates.
Y
capture configurations
X
values of the covariate affecting the conditional capture probabilities given the latent class
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
data(data_sim3) est = estLCCR(Y=data_sim3$Y,H=3,model="logit",X=data_sim3$X,flag="atleast")
data(data_sim3) est = estLCCR(Y=data_sim3$Y,H=3,model="logit",X=data_sim3$X,flag="atleast")
Simulated stratified capture-recapture data from a latent class model with 2 classes and covariates affecting both the class weights and the conditional capture probabilities given the latent class.
data(data_sim4)
data(data_sim4)
A list containing capture configurations at individual level and corresponding covariates.
Y
capture configurations
W
values of the covariate affecting the class weights
X
values of the covariate affecting the conditional capture probabilities given the latent class
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
data(data_sim4) est = estLCCR(Y=data_sim4$Y,H=2,X=data_sim4$X,W=data_sim4$W)
data(data_sim4) est = estLCCR(Y=data_sim4$Y,H=2,X=data_sim4$X,W=data_sim4$W)
For a latent class model for capture-recapture data, it provides design matrices for the recursive logit parametrization used to formulate the conditional distribution of capture configurations given the latent class. It is possible to include the effect of covariates and of previous captures.
design_matrix_logit(J, H = 1, main = c("LC", "same", "Rasch"), X = NULL, free_cov = c("no", "class", "resp", "both"), flag = c("no", "prev", "sum", "atleast"), free_flag = c("no", "class", "resp", "both"))
design_matrix_logit(J, H = 1, main = c("LC", "same", "Rasch"), X = NULL, free_cov = c("no", "class", "resp", "both"), flag = c("no", "prev", "sum", "atleast"), free_flag = c("no", "class", "resp", "both"))
J |
number of capture occasions |
H |
number of latent classes |
main |
"LC" for the latent class model in which there is a separate main effect for each capture occasion and latent class; "same" for the constrained model in which the main effect is the same across capture occasions but different across latent classes; "Rasch" for the constrained model in which each main effect is expressed in an additive form with a parameter related to the latent class and another parameter related to the capture occasion |
X |
array of covariates (n. strata x n. covariates x n. responses) |
free_cov |
"no" for constant effect of the covariates across capture occasions and latent classes; "class" for effect of covariates varying only with the latent class; "resp" for effect of covariates varying only with the capture occasion; "both" for effect of covariates varying with the capture occasion and the latent class |
flag |
"no" for no lag effect; "prev" for effect of the previous capture occasion only; "sum" for the effect of the sum of the previous capture occasions; "atleast" for the effect of at least one capture at the previous occasions |
free_flag |
"no" for constant effect of the previous capture occasions with respect to the occasion and the latent class; "class" for free effect only with respect to the latent class; "int" for free effect only with respect to the occasion; "both" for free effect with respect to capture occasion and latent class |
M |
design matrices |
par_list |
list of parameter names |
Main |
list of capture configurations |
Francesco Bartolucci, Antonio Foricna
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
design_matrix_loglin
, matrix_logit
, estLCCR
For a latent class model for capture-recapture data, it provides design matrices for the loglinear parametrization used to formulate the conditional distribution of the capture configurations given the latent class. It is possible to include the effect of covariates and bivariate interactions.
design_matrix_loglin(J, H = 1, main = c("LC", "same", "Rasch"), X = NULL, free_cov = c("no", "class", "resp", "both"), biv = NULL, free_biv = c("no", "class", "int", "both"))
design_matrix_loglin(J, H = 1, main = c("LC", "same", "Rasch"), X = NULL, free_cov = c("no", "class", "resp", "both"), biv = NULL, free_biv = c("no", "class", "int", "both"))
J |
number of capture occasions |
H |
number of latent classes |
main |
"LC" for the latent class model in which there is a separate main effect for each capture occasion and latent class; "same" for the constrained model in which the main effect is the same across capture occasions but different across latent classes; "Rasch" for the constrained model in which each main effect is expressed in an additive form with a parameter related to the latent class and another parameter related to the capture occasion |
X |
array of covariates (n. strata x n. covariates x n. responses) |
free_cov |
"no" for constant effect of the covariates across capture occasions and latent classes; "class" for effect of covariates varying only with the latent class; "resp" for effect of covariates varying only with the capture occasion; "both" for effect of covariates varying with the capture occasion and the latent class |
biv |
matrix with two columns containing the list of bivariate interactions |
free_biv |
"no" for constant bivariate interation effect with respect to the occasion and the latent class; "class" for free interaction with respect to the latent class; "int" for free effect only with respect to the interation; "both" for free effect with respect to interation and latent class |
M |
design matrices |
par_list |
list of parameter names |
Main |
list of capture configurations |
Francesco Bartolucci, Antonio Foricna
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
For a latent class model for stratified capture-recapture data with individual covariates, it estimates the model on the basis of observed data by the unconditional likelihood method, exploiting weights associated to the different strata. Estimation of the model parameters, included the population size, is based on an EM algorithm.
estLCCR(Y, H, model = c("loglin", "logit"), W = NULL, X = NULL, N = NULL, biv = NULL, flag = c("no", "prev", "sum", "atleast"), main = c("LC", "same", "Rasch"), free_cov = c("no", "class", "resp", "both"), free_biv = c("no", "class", "int", "both"), free_flag = c("no", "class", "resp", "both"), N0 = NULL, beta0 = NULL, lambda0 = NULL, control = list(), verb = TRUE, init_rand = FALSE, se_out = FALSE)
estLCCR(Y, H, model = c("loglin", "logit"), W = NULL, X = NULL, N = NULL, biv = NULL, flag = c("no", "prev", "sum", "atleast"), main = c("LC", "same", "Rasch"), free_cov = c("no", "class", "resp", "both"), free_biv = c("no", "class", "int", "both"), free_flag = c("no", "class", "resp", "both"), N0 = NULL, beta0 = NULL, lambda0 = NULL, control = list(), verb = TRUE, init_rand = FALSE, se_out = FALSE)
Y |
matrix of frequencies for each stratum (by row) |
H |
number of latent classes |
model |
"loglin" for loglinear parametrization; "logit" for recursive logit parametrization |
W |
matrix of covariates on the class weights |
X |
array of covariates (n. strata x n. covariates x n. responses) |
N |
fixed population size |
biv |
matrix with two columns containing the list of bivariate interactions (for loglinear parametrization) |
flag |
"no" for no lag effect; "prev" for effect of the previous capture occasion only; "sum" for the effect of the sum of the previous capture occasions; "atleast" for the effect of at least one capture at the previous occasions (for recursive logit parametrization) |
main |
"LC" for the latent class model in which there is a separate main effect for each capture occasion and latent class; "same" for the constrained model in which the main effect is the same across capture occasions but different across latent classes; "Rasch" for the constrained model in which each main effect is expressed in an additive form with a parameter related to the latent class and another parameter related to the capture occasion |
free_cov |
"no" for constant effect of the covariates across capture occasions and latent classes; "class" for effect of covariates varying only with the latent class; "resp" for effect of covariates varying only with the capture occasion; "both" for effect of covariates varying with the capture occasion and the latent class |
free_biv |
"no" for constant bivariate interation effect with respect to the occasion and the latent class; "class" for free interaction with respect to the latent class; "int" for free effect only with respect to the interation; "both" for free effect with respect to interation and latent class (for loglinear parametrization) |
free_flag |
"no" for constant effect of the previous capture occasions with respect to the occasion and the latent class; "class" for free effect only with respect to the latent class; "int" for free effect only with respect to the occasion; "both" for free effect with respect to capture occasion and latent class (for recursive logit parametrization) |
N0 |
initial value of the population size |
beta0 |
initial value of the parameters affecting the class weights |
lambda0 |
initial value of the parameters affecting the conditional distribution of capture configurations given the latent class |
control |
a list containing control arguments for the maximum number of iterations of the EM algorithm ( |
verb |
to have partial output during the model fitting |
init_rand |
to use a random initialization of the parameters |
se_out |
to require computation of the standard errors |
beta |
estimate of the parameters affecting the class weights |
lambda |
estimate of the parameters affecting the conditional distribution of capture configurations given the latent class |
lk |
final log-likelihood value |
N |
estimate of the population size |
np |
number of free parameters |
AIC |
value of AIC for model selection |
BIC |
value of BIC for model selection |
M |
design matrices used for the recursive logit or loglinear parametrization of the conditional distribution of capture configurations given the latent class |
tauv |
estimate of the weights of each stratum |
phiv |
estimate of the probability of being never captured for each stratum |
Piv |
matrix of the probabilities of the latent classes for each stratum |
Q |
array of the conditional probabilities of the capture configurations given each latent class and stratum |
seN |
standard error for the estimate of N |
sebeta |
standard error for the estimate of beta |
selambda |
standard error for the estimate of lambda |
lk1 |
component of the log-likelihood based on the binomial factor in N |
lk2 |
component of the log-likelihood involving N and the overall probability of being never captured |
lk3 |
component of the log-likelihood involving the capture probabilities |
lk4 |
component of the log-likelihood involving the stratum weights |
Francesco Bartolucci, Antonio Forcina
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
Liu, Y., Li, P., and Qin, J. (2017). Maximum empirical likelihood estimation for abundance in a closed population from capture-recapture data. Biometrika, 104, 527-543.
design_matrix_logit
, design_matrix_loglin
, simLCCR
# estimate latent class model with 2 classes having the same weight on 5 lists data(data_sim1) est = estLCCR(Y=data_sim1,H=2) est # estimate latent class model with 2 classes, one covariate affecting the weights and bivariate # loglinear interactions between consecutive lists data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") est # estimate latent class model with 3 classes, one covariate affecting the logits of each response, # and lag dependence data(data_sim3) est = estLCCR(Y=data_sim3$Y,H=3,model="logit",X=data_sim3$X,flag="atleast") est # estimate latent class model with 2 classes and covariates affecting both the class weights and # conditional capture probabilities given the latent class data(data_sim4) est = estLCCR(Y=data_sim4$Y,H=2,X=data_sim4$X,W=data_sim4$W) est
# estimate latent class model with 2 classes having the same weight on 5 lists data(data_sim1) est = estLCCR(Y=data_sim1,H=2) est # estimate latent class model with 2 classes, one covariate affecting the weights and bivariate # loglinear interactions between consecutive lists data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") est # estimate latent class model with 3 classes, one covariate affecting the logits of each response, # and lag dependence data(data_sim3) est = estLCCR(Y=data_sim3$Y,H=3,model="logit",X=data_sim3$X,flag="atleast") est # estimate latent class model with 2 classes and covariates affecting both the class weights and # conditional capture probabilities given the latent class data(data_sim4) est = estLCCR(Y=data_sim4$Y,H=2,X=data_sim4$X,W=data_sim4$W) est
For a latent class model for stratified capture-recapture data with individual covariates, it estimates the model on the basis of observed data by the conditional likelihood method, exploiting weights associated to the different strata. Estimation of the model parameters, included the population size, is based on an EM algorithm.
estLCCRcon(Y, H, model = c("loglin", "logit"), W = NULL, X = NULL, N = NULL, biv = NULL, flag = c("no", "prev", "sum", "atleast"), main = c("LC", "same", "Rasch"), free_cov = c("no", "class", "resp", "both"), free_biv = c("no", "class", "int", "both"), free_flag = c("no", "class", "resp", "both"), beta0 = NULL, lambda0 = NULL, control = list(), verb = TRUE, init_rand = FALSE, se_out = FALSE)
estLCCRcon(Y, H, model = c("loglin", "logit"), W = NULL, X = NULL, N = NULL, biv = NULL, flag = c("no", "prev", "sum", "atleast"), main = c("LC", "same", "Rasch"), free_cov = c("no", "class", "resp", "both"), free_biv = c("no", "class", "int", "both"), free_flag = c("no", "class", "resp", "both"), beta0 = NULL, lambda0 = NULL, control = list(), verb = TRUE, init_rand = FALSE, se_out = FALSE)
Y |
matrix of frequencies for each stratum (by row) |
H |
number of latent classes |
model |
"loglin" for loglinear parametrization; "logit" for recursive logit parametrization |
W |
matrix of covariates on the class weights |
X |
array of covariates (n. strata x n. covariates x n. responses) |
N |
fixed population size |
biv |
matrix with two columns containing the list of bivariate interactions (for loglinear parametrization) |
flag |
"no" for no lag effect; "prev" for effect of the previous capture occasion only; "sum" for the effect of the sum of the previous capture occasions; "atleast" for the effect of at least one capture at the previous occasions (for recursive logit parametrization) |
main |
"LC" for the latent class model in which there is a separate main effect for each capture occasion and latent class; "same" for the constrained model in which the main effect is the same across capture occasions but different across latent classes; "Rasch" for the constrained model in which each main effect is expressed in an additive form with a parameter related to the latent class and another parameter related to the capture occasion |
free_cov |
"no" for constant effect of the covariates across capture occasions and latent classes; "class" for effect of covariates varying only with the latent class; "resp" for effect of covariates varying only with the capture occasion; "both" for effect of covariates varying with the capture occasion and the latent class |
free_biv |
"no" for constant bivariate interation effect with respect to the occasion and the latent class; "class" for free interaction with respect to the latent class; "int" for free effect only with respect to the interation; "both" for free effect with respect to interation and latent class (for loglinear parametrization) |
free_flag |
"no" for constant effect of the previous capture occasions with respect to the occasion and the latent class; "class" for free effect only with respect to the latent class; "int" for free effect only with respect to the occasion; "both" for free effect with respect to capture occasion and latent class (for recursive logit parametrization) |
beta0 |
initial value of the parameters affecting the class weights |
lambda0 |
initial value of the parameters affecting the conditional distribution of capture configurations given the latent class |
control |
a list containing control arguments for the maximum number of iterations of the EM algorithm ( |
verb |
to have partial output during the model fitting |
init_rand |
to use a random initialization of the parameters |
se_out |
to require computation of the standard errors |
beta |
estimate of the parameters affecting the class weights |
lambda |
estimate of the parameters affecting the conditional distribution of capture configurations given the latent class |
lk |
final log-likelihood value |
dev |
final value of the deviance that is used to build confidence intervals |
N |
estimate of the population size |
np |
number of free parameters |
AIC |
value of AIC for model selection |
BIC |
value of BIC for model selection |
M |
design matrices used for the recursive logit or loglinear parametrization of the conditional distribution of capture configurations given the latent class |
phiv |
estimate of the probability of being never captured for each stratum |
Piv |
matrix of the probabilities of the latent classes for each stratum |
Q |
array of the conditional probabilities of the capture configurations given each latent class and stratum |
seN |
standard error for the estimate of N |
sebeta |
standard error for the estimate of beta |
selambda |
standard error for the estimate of lambda |
Francesco Bartolucci, Antonio Forcina
Bartolucci, F. and Forcina, A. (2006). Estimating the size of a closed population by modeling latent and observed heterogeneity. Journal of the American Statistical Association, 101, 786-794.
design_matrix_logit
, design_matrix_loglin
, simLCCR
# estimate latent class model with 2 classes having the same weight on 5 lists data(data_sim1) est = estLCCRcon(Y=data_sim1,H=2) est # estimate latent class model with 2 classes, one covariate affecting the weights and bivariate # loglinear interactions between consecutive lists data(data_sim2) est = estLCCRcon(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") est # estimate latent class model with 3 classes, one covariate affecting the logits of each response, # and lag dependence data(data_sim3) est = estLCCRcon(Y=data_sim3$Y,H=3,model="logit",X=data_sim3$X,flag="atleast") est # estimate latent class model with 2 classes and covariates affecting both the class weights and # conditional capture probabilities given the latent class data(data_sim4) est = estLCCRcon(Y=data_sim4$Y,H=2,X=data_sim4$X,W=data_sim4$W) est
# estimate latent class model with 2 classes having the same weight on 5 lists data(data_sim1) est = estLCCRcon(Y=data_sim1,H=2) est # estimate latent class model with 2 classes, one covariate affecting the weights and bivariate # loglinear interactions between consecutive lists data(data_sim2) est = estLCCRcon(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") est # estimate latent class model with 3 classes, one covariate affecting the logits of each response, # and lag dependence data(data_sim3) est = estLCCRcon(Y=data_sim3$Y,H=3,model="logit",X=data_sim3$X,flag="atleast") est # estimate latent class model with 2 classes and covariates affecting both the class weights and # conditional capture probabilities given the latent class data(data_sim4) est = estLCCRcon(Y=data_sim4$Y,H=2,X=data_sim4$X,W=data_sim4$W) est
Given a matrix of observed capture-recapture configurations, convert the data to a matrix of frequencies having the same number of rows and a number of columns equal to the number of possible configurations.
freq_data(R,count=rep(1,nrow(R)))
freq_data(R,count=rep(1,nrow(R)))
R |
Matrix of size n (sample size) x J (number of capture occastions) of observed capture-recapture configurations |
count |
Vector of counts for each configuration |
Y |
Matrix of frequency of each capture configuration of size n x (2^J) |
Francesco Bartolucci, Antonio Forcina
R = rbind(c(0,0,0,1),c(0,1,0,0),c(0,0,1,1),c(1,1,1,1),c(1,1,1,1)) Y = freq_data(R)
R = rbind(c(0,0,0,1),c(0,1,0,0),c(0,0,1,1),c(1,1,1,1),c(1,1,1,1)) Y = freq_data(R)
For J binary responses, it provides design matrices A and B used to express the saturated recursive logit parametrization of type log(p) = [A*eta-B*log(1+exp(eta))].
matrix_logit(J)
matrix_logit(J)
J |
number of capture occasions |
A |
first matrix involved in the recursive logit parametrization |
B |
second matrix involved in the recursive logit parametrization |
Francesco Bartolucci, Antonio Foricna
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
Plot for output from confint.estLCCR
.
## S3 method for class 'confLCCR' plot(x,...)
## S3 method for class 'confLCCR' plot(x,...)
x |
an object of class |
... |
further possible arguments |
M |
matrix of binary configurations |
Francesco Bartolucci, Antonio Forcina
data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") conf = confint(est) plot(conf)
data(data_sim2) est = estLCCR(Y=data_sim2$Y,H=2,W=data_sim2$W,biv=matrix(c(1,2,3,4,2,3,4,5),4),main="same") conf = confint(est) plot(conf)
Given the output, it is written in a readable form.
## S3 method for class 'estLCCR' print(x, ...) ## S3 method for class 'estLCCRcon' print(x, ...) ## S3 method for class 'confLCCR' print(x, ...)
## S3 method for class 'estLCCR' print(x, ...) ## S3 method for class 'estLCCRcon' print(x, ...) ## S3 method for class 'confLCCR' print(x, ...)
x |
output from |
... |
further arguments passed to or from other methods |
No return value
Francesco Bartolucci, Antonio Forcina
The function simulates capture-recapture data from a latent class model with individual covariates that may affect the class weights and/or the conditional distribution of capture configurations given the latent class. The data may be in disaggregated form (with each stratum having unitary dimension) or aggregated form (with strata having generic dimension).
simLCCR(H, J, beta, lambda, N, model = c("loglin", "logit"), Wc = NULL, Xc = NULL, biv = NULL, flag = c("no", "prev", "sum", "atleast"), main = c("LC", "same", "Rasch"), free_cov = c("no", "class", "resp", "both"), free_biv = c("no", "class", "int", "both"), free_flag = c("no", "class", "resp", "both"))
simLCCR(H, J, beta, lambda, N, model = c("loglin", "logit"), Wc = NULL, Xc = NULL, biv = NULL, flag = c("no", "prev", "sum", "atleast"), main = c("LC", "same", "Rasch"), free_cov = c("no", "class", "resp", "both"), free_biv = c("no", "class", "int", "both"), free_flag = c("no", "class", "resp", "both"))
H |
number of latent classes |
J |
number of capture occasions |
beta |
value of the parameters affecting the class weights |
lambda |
value of the parameters affecting the conditional distribution of capture configurations given the latent |
N |
population size (with individual data); vector containing the size of any stratum (with aggregated data) |
model |
population size (with individual data); vector containing the size of any stratum (with aggregated data) |
Wc |
matrix of covariates affecting the class weights at population level |
Xc |
array of covariates at population level (n. strata x n. covariates x n. responses) |
biv |
matrix with two columns containing the list of bivariate interactions (for loglinear parametrization) |
flag |
"no" for no lag effect; "prev" for effect of the previous capture occasion only; "sum" for the effect of the sum of the previous capture occasions; "atleast" for the effect of at least one capture at the previous occasions (for recursive logit parametrization) |
main |
"LC" for the latent class model in which there is a separate main effect for each capture occasion and latent class; "same" for the constrained model in which the main effect is the same across capture occasions but different across latent classes; "Rasch" for the constrained model in which each main effect is expressed in an additive form with a parameter related to the latent class and another parameter related to the capture occasion |
free_cov |
"no" for constant effect of the covariates across capture occasions and latent classes; "class" for effect of covariates varying only with the latent class; "resp" for effect of covariates varying only with the capture occasion; "both" for effect of covariates varying with the capture occasion and the latent class |
free_biv |
"no" for constant bivariate interation effect with respect to the occasion and the latent class; "class" for free interaction with respect to the latent class; "int" for free effect only with respect to the interation; "both" for free effect with respect to interation and latent class (for loglinear parametrization) |
free_flag |
"no" for constant effect of the previous capture occasions with respect to the occasion and the latent class; "class" for free effect only with respect to the latent class; "int" for free effect only with respect to the occasion; "both" for free effect with respect to capture occasion and latent class (for recursive logit parametrization) |
Y |
matrix of frequencies for each stratum (by row), only for captured indivdiuals |
Yc |
matrix of frequencies for each stratum (by row), for all indivdiuals |
Piv |
matrix of class weights for each stratum |
Q |
matrix of the conditional distribution of capture configurations given the latent class |
Pm |
matrix of the distribution of the capture configurations (with aggregated data) |
R |
matrix of single capture occasions (with individual data), only for captured individuals |
U |
vector of latent classes (with individual data) |
Rc |
matrix of single capture occasions (with individual data), for all individuals |
W |
matrix of covariates affecting the class weights, only for captured individuals |
X |
array of covariates affecting the conditional distribution of capture configurations given the latent class, only for captured individuals |
Francesco Bartolucci, Antonio Forcina
Forcina, A. and Bartolucci, F. (2021). Estimating the size of a closed population by modeling latent and observed heterogeneity, arXiv:2106.03811.
design_matrix_logit
, design_matrix_loglin
, estLCCR
# simulate data from latent class model with 2 classes having the same weight on 5 lists out = simLCCR(2,5,be=0,la=c(rep(-1,5),rep(1,5)),N=200) # simulate data from a latent class model with 2 classes, one covariate affecting the weights and # bivariate loglinear interactions between consecutive lists Wc = rnorm(200) out = simLCCR(2,6,beta=c(0,1),lambda=c(-1,1,1),N=200,Wc=Wc,biv=matrix(c(1,2,3,4,2,3,4,5),4), main="same") # simulate data from a latent class model with 3 classes, one covariate affecting the logits of # each response, and lag dependence Xc = rnorm(200) out = simLCCR(3,6,model="logit",beta=c(0,0),lambda=c(rep(-1,6),rep(0,6),rep(1,6),1,1), N=200,Xc=Xc,flag="atleast") # simulate data from latent class model with 2 classes and covariates affecting both class weights # and conditional probabilities of capture configurations given the latent class Wc = c(-1,0,1); Xc = rnorm(3) out = simLCCR(2,5,beta=c(0,0),lambda=c(rep(-1,5),rep(1,5),1),N=c(100,100,100),Wc=Wc,Xc=Xc)
# simulate data from latent class model with 2 classes having the same weight on 5 lists out = simLCCR(2,5,be=0,la=c(rep(-1,5),rep(1,5)),N=200) # simulate data from a latent class model with 2 classes, one covariate affecting the weights and # bivariate loglinear interactions between consecutive lists Wc = rnorm(200) out = simLCCR(2,6,beta=c(0,1),lambda=c(-1,1,1),N=200,Wc=Wc,biv=matrix(c(1,2,3,4,2,3,4,5),4), main="same") # simulate data from a latent class model with 3 classes, one covariate affecting the logits of # each response, and lag dependence Xc = rnorm(200) out = simLCCR(3,6,model="logit",beta=c(0,0),lambda=c(rep(-1,6),rep(0,6),rep(1,6),1,1), N=200,Xc=Xc,flag="atleast") # simulate data from latent class model with 2 classes and covariates affecting both class weights # and conditional probabilities of capture configurations given the latent class Wc = c(-1,0,1); Xc = rnorm(3) out = simLCCR(2,5,beta=c(0,0),lambda=c(rep(-1,5),rep(1,5),1),N=c(100,100,100),Wc=Wc,Xc=Xc)
It creates all possible binary (with elements equal to 0 or 1) vectors of a specified length; these vectors are casted in a matrix having a number of columns equal to the vector length. If required, the binary vectors are constrained to have the same total (sum of their elements).
sq(J, t = NULL)
sq(J, t = NULL)
J |
legnth of binary vectors |
t |
possible fixed total |
M |
matrix containing all binary vectors |
Francesco Bartolucci, Antonio Forcina
# build matrix of all possible binary vectors of legnth 5 M = sq(5) # build matrix of all possible binary vectors of legnth 5 with total equal 2 M = sq(5,2)
# build matrix of all possible binary vectors of legnth 5 M = sq(5) # build matrix of all possible binary vectors of legnth 5 with total equal 2 M = sq(5,2)
Summary of output from fitting latent class models for capture-recapture data with covariates.
## S3 method for class 'estLCCR' summary(object, ...) ## S3 method for class 'estLCCRcon' summary(object, ...) ## S3 method for class 'confLCCR' summary(object, ...)
## S3 method for class 'estLCCR' summary(object, ...) ## S3 method for class 'estLCCRcon' summary(object, ...) ## S3 method for class 'confLCCR' summary(object, ...)
object |
output from |
... |
further arguments passed to or from other methods |
No return value
Francesco Bartolucci, Antonio Forcina