-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
168 lines (126 loc) · 3.91 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# saens
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/saens)](https://CRAN.R-project.org/package=saens)
[![R-CMD-check](https://github.com/Alfrzlp/sae-ns/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Alfrzlp/sae-ns/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
## Author
Ridson Al Farizal P, Azka Ubaidillah
## Maintainer
Ridson Al Farizal P [ridsonap\@bps.go.id](mailto:ridsonap@bps.go.id)
## Description
Implementation of small area estimation (Fay-Herriot model) with EBLUP (Empirical Best Linear Unbiased Prediction) Approach for non-sampled area estimation by adding cluster information and assuming that there are similarities among particular areas. See also Rao & Molina (2015, ISBN:978-1-118-73578-7) and Anisa et al. (2013) <doi:10.9790/5728-10121519>.
## Installation
You can install the development version of saens from [GitHub](https://github.com/) with:
```{r, eval=FALSE}
# install.packages("devtools")
devtools::install_github("Alfrzlp/saens")
```
or you can install cran version
```{r, eval=FALSE}
install.packages("saens")
```
# Example
This is a basic example which shows you how to solve a common problem:
```{r example, message=FALSE, warning=FALSE}
library(saens)
library(dplyr)
library(tidyr)
library(ggplot2)
windowsFonts(
poppins = windowsFont('poppins')
)
```
## Data
```{r data}
milk$var <- milk$SD^2
# glimpse(mys)
# glimpse(milk)
```
# EBLUP Model
```{r}
model1 <- eblupfh(yi ~ as.factor(MajorArea), data = milk, vardir = "var")
```
### AIC, BIC, and Loglikehood
```{r}
AIC(model1)
BIC(model1)
logLik(model1)
```
### Coef
```{r}
coef(model1)
```
### Summary
```{r}
summary(model1)
```
### Autoplot
```{r, dpi=500, fig.height=2, fig.width=6}
saens::autoplot(model1, variable = 'MSE')
```
```{r, dpi=500, fig.height=2, fig.width=6}
saens::autoplot(model1, variable = 'RRMSE')
```
```{r, dpi=500, fig.height=2, fig.width=6}
saens::autoplot(model1, variable = 'estimation')
```
# EBLUP Model for Non-sampled Areas
```{r}
model_ns <- eblupfh_cluster(y ~ x1 + x2 + x3, data = mys, vardir = "var", cluster = "clust")
```
### Comparison of estimates and RSE
```{r}
mys$eblup_est <- model_ns$df_res$eblup
mys$eblup_rse <- model_ns$df_res$rse
glimpse(mys)
```
```{r, dpi=500, fig.height=3, fig.width=6}
mys %>%
select(area, rse, eblup_rse) %>%
pivot_longer(-1, names_to = "metode", values_to = "rse") %>%
ggplot(aes(x = area, y = rse, col = metode)) +
geom_line() +
scale_color_discrete(
labels = c('EBLUP', 'Direct Estimate')
) +
labs(col = NULL, y = 'Estimate', x = 'Domain', title = 'Comparison of RSE') +
theme(
legend.position = 'bottom',
text = element_text(family = 'poppins'),
axis.ticks.x = element_blank(),
plot.title = element_text(face = 2, vjust = 0),
plot.subtitle = element_text(colour = 'gray30', vjust = 0)
)
```
```{r, dpi=500, fig.height=3, fig.width=6}
mys %>%
select(area, y, eblup_est) %>%
pivot_longer(-1, names_to = "metode", values_to = "rse") %>%
ggplot(aes(x = area, y = rse, col = metode)) +
geom_line() +
scale_color_discrete(
labels = c('EBLUP', 'Direct Estimate')
) +
labs(col = NULL, y = 'Estimate', x = 'Domain', title = 'Comparison of Estimates') +
theme(
legend.position = 'bottom',
text = element_text(family = 'poppins'),
axis.ticks.x = element_blank(),
plot.title = element_text(face = 2, vjust = 0),
plot.subtitle = element_text(colour = 'gray30', vjust = 0)
)
```
## References
- Rao, J. N., & Molina, I. (2015). Small area estimation. John Wiley & Sons.
- Anisa, R., Kurnia, A., & Indahwati, I. (2013). Cluster information of non-sampled area in small area estimation. E-Prosiding Internasional\| Departemen Statistika FMIPA Universitas Padjadjaran, 1(1), 69-76.