R: Capture-Recapture Estimation using Bayesian Nonparametric...
LCMCR-package
R Documentation
Capture-Recapture Estimation using Bayesian Nonparametric latent-class models
Description
This package implements a fully Bayesian multiple-recapture method for estimating the unknown size of a population using non-parametric latent class models. This is an implementation of the method described in Manrique-Vallier (forthcoming). The estimation algorithm is based on Markov Chain Monte Carlo sampling.
Manrique-Vallier, D. (forthcoming) "Bayesian Population Size Estimation Using Dirichlet Process Mixtures", Biometrics.
Examples
library('LCMCR')
###Using Kosovo data.###
data(kosovo_aggregate)
###Example 1: Capture-Recapture estimation using convenience functions###
#Create and initialize an LCMCR object for MCMC sampling#
sampler <- lcmCR(captures = kosovo_aggregate, tabular = FALSE, in_list_label = '1',
not_in_list_label = '0', K = 10, a_alpha = 0.25, b_alpha = 0.25,
seed = 'auto', buffer_size = 10000, thinning = 100)
#Obtain 1000 samples from the posterior distribution of N#
N <- lcmCR_PostSampl(sampler, burnin = 10000, samples = 1000, thinning = 100)
#Posterior quantiles#
quantile(N, c(0.025, 0.5, 0.975))
###Example 2: Capture-Recapture estimation using the lcm_CR_Basic object directly###
#Create and initialize an LCMCR object for MCMC sampling#
sampler <- lcmCR(captures = kosovo_aggregate, tabular = FALSE, in_list_label = '1',
not_in_list_label = '0', K = 10, a_alpha = 0.25, b_alpha = 0.25,
seed = 'auto', buffer_size = 1000, thinning = 100)
#Run 10000 iterations as burn-in
sampler$Update(10000)
#List all parameters from the model
sampler$Get_Param_List()
#Set parameter 'n0' for tracing
sampler$Set_Trace('n0')
#List currently traced parameters.
sampler$Get_Trace_List()
#Activate tracing
sampler$Activate_Tracing()
#Run the sampler 100000 times
sampler$Update(100000)
#Get the 1000 samples from the posterior distribution of N
N <- sampler$Get_Trace('n0') + sampler$n
#Plot the trace of N
plot(N, type = 'l')
#Compute posterior quantiles
quantile(N, c(0.025, 0.5, 0.975))
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(LCMCR)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LCMCR/LCMCR-package.Rd_%03d_medium.png", width=480, height=480)
> ### Name: LCMCR-package
> ### Title: Capture-Recapture Estimation using Bayesian Nonparametric
> ### latent-class models
> ### Aliases: LCMCR-package LCMCR
>
> ### ** Examples
>
> library('LCMCR')
>
> ###Using Kosovo data.###
> data(kosovo_aggregate)
>
> ###Example 1: Capture-Recapture estimation using convenience functions###
> #Create and initialize an LCMCR object for MCMC sampling#
> sampler <- lcmCR(captures = kosovo_aggregate, tabular = FALSE, in_list_label = '1',
+ not_in_list_label = '0', K = 10, a_alpha = 0.25, b_alpha = 0.25,
+ seed = 'auto', buffer_size = 10000, thinning = 100)
WARMING UP...
> #Obtain 1000 samples from the posterior distribution of N#
> N <- lcmCR_PostSampl(sampler, burnin = 10000, samples = 1000, thinning = 100)
>
> #Posterior quantiles#
> quantile(N, c(0.025, 0.5, 0.975))
2.5% 50% 97.5%
8832.95 10468.00 13546.87
>
> ###Example 2: Capture-Recapture estimation using the lcm_CR_Basic object directly###
> #Create and initialize an LCMCR object for MCMC sampling#
> sampler <- lcmCR(captures = kosovo_aggregate, tabular = FALSE, in_list_label = '1',
+ not_in_list_label = '0', K = 10, a_alpha = 0.25, b_alpha = 0.25,
+ seed = 'auto', buffer_size = 1000, thinning = 100)
WARMING UP...
>
> #Run 10000 iterations as burn-in
> sampler$Update(10000)
>
> #List all parameters from the model
> sampler$Get_Param_List()
[1] "K" "M" "a_alpha" "alpha" "aux_JK2" "b_alpha"
[7] "count0K" "countK" "count_zIK" "k_star" "lambdaJK" "log_nuK"
[13] "n0" "nuK" "prob_zero"
>
> #Set parameter 'n0' for tracing
> sampler$Set_Trace('n0')
>
> #List currently traced parameters.
> sampler$Get_Trace_List()
[1] "n0"
>
> #Activate tracing
> sampler$Activate_Tracing()
>
> #Run the sampler 100000 times
> sampler$Update(100000)
>
> #Get the 1000 samples from the posterior distribution of N
> N <- sampler$Get_Trace('n0') + sampler$n
>
> #Plot the trace of N
> plot(N, type = 'l')
>
> #Compute posterior quantiles
> quantile(N, c(0.025, 0.5, 0.975))
2.5% 50% 97.5%
9294.95 10618.00 14257.10
>
>
>
>
>
>
> dev.off()
null device
1
>