-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
105 lines (72 loc) · 4.49 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 -->
<!-- badges: start --> [](https://github.com/harvard-ufds/saeczi/actions/workflows/R-CMD-check.yaml) [](https://CRAN.R-project.org/package=saeczi) <!-- badges: end -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# saeczi
### (Small Area Estimation for Continuous Zero Inflated data)
## Overview
`saeczi` is an R package that implements a small area estimator that uses a two-stage modeling approach for zero-inflated response variables. In particular, we are working with variables that follow a semi-continuous distribution with a mixture of zeroes and positive continuously distributed values. An example can be seen below.
{width=60%}
`saeczi` first fits a linear mixed model to the non-zero portion of the response and then a generalized linear mixed model with binomial response to classify the probability of zero for a given data point. In estimation these models are each applied to new data points and combined to compute a final prediction.
The package can also generate MSE estimates using a parametric bootstrap approach described in Chandra and Sud (2012) either in parallel or sequentially.
## Installation
Install the latest CRAN release with:
```{r cran-installation, eval = FALSE}
install.packages("saeczi")
```
You can also install the developmental version of `saeczi` from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("pak")
pak::pkg_install("harvard-ufds/saeczi")
```
## Usage
We'll use the internal package data to show an example of how to use `saeczi`. The two data sets contained within the package contain example forestry data collected by the Forestry Inventory and Analysis (FIA) research program.
- `saeczi::samp`: Example FIA plot-level sample data for each county in Oregon.
- `saeczi::pop`: Example FIA pixel level population auxiliary data for each county in Oregon.
The main response variable included in `samp` is above ground live biomass and our small areas in this case are the counties in Oregon. To keep things simple we will use tree canopy cover (tcc16) and elevation (elev) as our predictors in both of the models. We can use `saeczi` to get estimates for the mean biomass in each county as well as the corresponding bootstrapped (B = 500) MSE estimate as follows.
```{r, warning=FALSE, message=FALSE}
library(saeczi)
data(pop)
data(samp)
result <- saeczi(samp_dat = samp,
pop_dat = pop,
lin_formula = DRYBIO_AG_TPA_live_ADJ ~ tcc16 + elev,
log_formula = DRYBIO_AG_TPA_live_ADJ ~ tcc16,
domain_level = "COUNTYFIPS",
mse_est = TRUE,
B = 1000L)
```
#### Return
The function returns the following objects:
| Name | Description |
|:------------------------------------|:------------------------------------|
| `call` | The original function call |
| `res` | A data.frame containing the estimates |
| `lin_mod` | The linear model object of class `merMod` used to compute the estimates |
| `log_mod` | The logistic model object of class `merMod` used to compute the estimates |
As there are 36 total counties in Oregon, we will just look at the first few rows of the results:
```{r}
result$res |> head()
```
### Parallelization
`saeczi` supports parallelization through the `future` package to speed up the bootstrapping process, but requires a small amount of additional work on the part of the user. It is not enough just to specify `parallel = TRUE` in the function signature as a `future::plan` must also be specified.
Below is an example that uses multisession' future resolution with 6 threads:
```{r, eval = FALSE}
future::plan("multisession", workers = 6)
result_par <- saeczi(samp_dat = samp,
pop_dat = pop,
lin_formula = DRYBIO_AG_TPA_live_ADJ ~ tcc16 + elev,
log_formula = DRYBIO_AG_TPA_live_ADJ ~ tcc16,
domain_level = "COUNTYFIPS",
mse_est = TRUE,
parallel = TRUE,
B = 1000L)
```