-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2022-06-15-singleRcapture-showcase.Rmd
90 lines (67 loc) · 2.15 KB
/
2022-06-15-singleRcapture-showcase.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
title: "R Notebook"
output: html_notebook
---
## Outline
1. general idea behind the package
2. presentation of the package and its functionalities
+ main function `estimate_popsize`
+ diagnostics (residuals, leave-one-out diagnostics)
+ testing `marginalFreq`
+ datasets `carcassubmission`, `netherlandsimmigrant`
3. workplan
4. discussion
## Installation
Installation of the package from github [working branch]
```{r}
remotes::install_github("ncn-foreigners/singleRcapture@working")
```
Loading the package
```{r}
library(singleRcapture)
```
Main functions:
+ `estimate_popsize` -- declaration of formulae, type of model (i.e. distribution), estimation method, variance estimation and many other, under the hood:
+ `estimate_popsize.fit` -- function to fit the model (in matrix notation)
+ `populationEstimate` -- function to estimate the population size given input in `estimate_popsize`
+ `marginalFreq` -- function to verify esti
```{r}
m1 <- estimate_popsize(formula = capture ~ gender + age + nation,
model = "ztpoisson",
method = "mle",
pop.var = "analytic",
data = netherlandsimmigrant)
```
Basic output
```{r}
m1
```
Detailed output
```{r}
summary(m1)
```
Basic, stats functions
```{r}
table(resid(m1))
```
Multiple models
```{r}
selected_models <- c("ztpoisson", "zelterman", "chao", "ztgeom")
multiple_models <- lapply(selected_models,
function(x) {
estimate_popsize(formula = capture ~ gender + age + nation,
model = x,
method = "mle",
pop.var = "analytic",
data = netherlandsimmigrant)
})
pop_sizes <- lapply(multiple_models, "[[", "populationSize")
```
```{r}
data.frame(x = selected_models,
N_hat = sapply(pop_sizes, "[[", "pointEstimate"))
```
```{r}
data.frame(x = selected_models,
N_hat = do.call("rbind", lapply(pop_sizes, "[[", "confidenceInterval")))
```