-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
103 lines (80 loc) · 2.78 KB
/
README.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# singleRcaptureExtra
<!-- badges: start -->
[![R-CMD-check](https://github.com/ncn-foreigners/singleRcaptureExtra/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ncn-foreigners/singleRcaptureExtra/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/ncn-foreigners/singleRcaptureExtra/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ncn-foreigners/singleRcaptureExtra/tree/main)
<!-- badges: end -->
An expention of `singleRcapture` package to handle fitted object from other R
packages with zero truncated regression capabilities (and in the future the same
for ratio regression models)
### Quick demo
Utilizing additive models when effect is non linear:
```{r VGAM}
library(VGAM)
library(singleRcaptureExtra)
set.seed(123)
x <- rnorm(n = 1000)
y <- rpois(n = 1000, lambda = exp(-1 + cos(x)))
data <- data.frame(y = y, x = x)
data <- data[data$y > 0, ]
additiveModel <- vgam(y ~ s(x, df = 3), data = data, family = pospoisson())
summary(estimatePopsize(additiveModel))
```
We see that `1000` is well with confidence intervals and that estimates for `x` are approximately correct:
```{r plotVGAM}
plotvgam(additiveModel, data)
```
with the actual curve being:
```{r curve, echo=FALSE}
curve(cos, from = min(x), to = max(x))
```
We also allow bootstrap methods:
```{r VGAMboot}
x <- rnorm(n = 1000)
y <- rpois(n = 1000, lambda = exp(-1 + x))
data <- data.frame(y = y, x = x)
data <- data[data$y > 0, ]
m1 <- vglm(y ~ x, data = data, family = pospoisson())
singleRm1 <- estimatePopsize(m1, popVar = "bootstrap")
summary(singleRm1)
```
The `plots` method that is available for native `singleRcapture` object are also
(being) developed for `singleRcaptureExtra` objects (`singleRforeign` class)
```{r bootHist}
plot(singleRm1, plotType = "bootHist", ylim = c(0, 220))
```
Diagnostics from `singleRcapture` are also available:
```{r}
summary(marginalFreqVglm(singleRm1))
```
Utilising popular `countreg` package (compare with `singleRcapture`):
```{r countreg}
library(countreg)
model <- zerotrunc(
formula = capture ~ gender + age + nation,
data = netherlandsimmigrant,
dist = "poisson"
)
print(summary(estimatePopsize(model)),
# Print summary of foreign object (works for all methods)
summaryForeign = TRUE)
model <- estimatePopsize(
formula = capture ~ gender + age + nation,
data = netherlandsimmigrant,
model = singleRcapture::ztpoisson
)
summary(model)
```
## Funding
Work on this package is supported by the the National Science Center, OPUS 20 grant no. 2020/39/B/HS4/00941.