-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
102 lines (70 loc) · 2.43 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
---
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%"
)
```
# quickNmix
The goal of quickNmix is to aid in the fitting of asymptotic N-mixture models, which are computed significantly faster than their canonical counterpart when population sizes are large.
## Installation
You can install the released version of quickNmix from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("quickNmix")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("mrparker909/quickNmix")
```
## Example 1
This is a basic example which shows how to fit a model with site varying lambda, and time varying pdet:
```{r example, cache=T}
library(quickNmix)
tictoc::tic()
nit = anmu[1:2,1:5] # ancient murrelet chick counts
mod = fitNmix(nit=nit,
K=400, # upper bound on population size
l_s_c=list(c(0,1)), # lambda site covariate
p_t_c=list(c(0,1,1,1,1)),
control=list(reltol=1e-5))
tictoc::toc()
```
model AIC value:
```{r example_p2, cache=T}
mod$model_results$AIC
```
lambda estimates for each site:
```{r example_p3, cache=T}
mod$model_results$estimate_matrices$lambda
```
gamma estimates for each site and time:
```{r example_p4, cache=T}
mod$model_results$estimate_matrices$gamma
```
omega estimates for each site and time:
```{r example_p5, cache=T}
mod$model_results$estimate_matrices$omega
```
pdet estimates for each site and time:
```{r example_p6, cache=T}
mod$model_results$estimate_matrices$pdet
```
## Example 2
This is a basic example which shows how you can use multiple cores to compute:
```{r example2, cache=T}
library(quickNmix)
# uses library doParallel, here we use 2 cores
doParallel::registerDoParallel(cores = 2)
tictoc::tic()
nit = anmu[c(2,5),1:12] # ancient murrelet chick counts
mod2 = fitNmix(nit=nit, K=400)
tictoc::toc()
mod2
```
Multi-threading is implemented using R packages doParallel and foreach. Note that multi-threading is used to split the computation of the transition probability matrix by rows. This may not be efficient on some architectures, and will not be efficient for small K: efficiency increases with increasing K. Alternative choices for multi-core processing are being considered.