saehb.tf.beta

Small Area Estimation using Hierarchical Bayes Twofold Subarea Level Model under Beta Distribution

https://github.com/nasyazahira/saehb.tf.beta

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Small Area Estimation using Hierarchical Bayes Twofold Subarea Level Model under Beta Distribution

Basic Info
  • Host: GitHub
  • Owner: Nasyazahira
  • License: gpl-3.0
  • Language: C++
  • Default Branch: main
  • Homepage:
  • Size: 3.84 MB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created about 1 year ago · Last pushed 10 months ago
Metadata Files
Readme License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# saeHB.TF.beta





`saeHB.TF.beta` provides several functions for area and subarea level of small area estimation under Twofold Subarea Level Model using hierarchical Bayesian (HB) method with Beta distribution for variables of interest. Some dataset simulated by a data generation are also provided. The ‘rstan’ package is employed to obtain parameter estimates using STAN.

## Function

## Installation

You can install the development version of saeHB.TF.beta from [GitHub](https://github.com/) with:

```{r, eval=FALSE}
# install.packages("devtools")
devtools::install.github("Nasyazahira/saeHB.TF.beta")
```

## Example

Here is a basic example of using the **betaTF** function to make estimates based on sample data in this package

### Load Package and Data

```{r}
library(saeHB.TF.beta)

#Load Dataset
data(dataBeta) #for dataset with nonsampled subarea use dataBetaNS
```


### Exploration

```{r, message=FALSE, warning=FALSE, fig.show='hold', out.width='50%'}
dataBeta$CV <- sqrt(dataBeta$vardir)/dataBeta$y
explore(y~X1+X2, CV = "CV", data = dataBeta, normality = TRUE)
```

### Modeling

```{r example, results='hide', message=FALSE, warning=FALSE}
#Fitting model
fit <- betaTF(y~X1+X2, area="codearea", weight="w", data=dataBeta, iter.update = 5, iter.mcmc = 10000)
```

### Extract Result for Area

Area mean estimation

```{r, results='hide'}
fit$Est_area
```

Area random effect

```{r, results='hide'}
fit$area_randeff
```

Calculate Area Relative Standard Error (RSE) or CV

```{r, results='hide'}
RSE_area <- (fit$Est_area$SD)/(fit$Est_area$Mean)*100
summary(RSE_area)
```

### Extract Result for Subarea

Subarea mean estimation

```{r, results='hide'}
fit$Est_sub
```

Subarea random effect

```{r, results='hide'}
fit$sub_randeff
```

Calculate Subarea Relative Standard Error (RSE) or CV

```{r, results='hide'}
RSE_sub <- (fit$Est_sub$SD)/(fit$Est_sub$Mean)*100
summary(RSE_sub)
```

### Extract Coefficient Estimation $\beta$

```{r, results='hide'}
fit$coefficient
```

### Extract Area Random Effect Variance $\sigma_u^2$ and Subarea Random Effect Variance $\sigma_v^2$

```{r, results='hide'}
fit$refVar
```

### Visualize the Result

```{r, results='hide', warning=FALSE}
library(ggplot2)
```

Save the output of Subarea estimation and the Direct Estimation (y)

```{r}
df <- data.frame(
  area = seq_along(fit$Est_sub$Mean),             
  direct = dataBeta$y,              
  mean_estimate = fit$Est_sub$Mean
)
```

Area Mean Estimation

```{r}
ggplot(df, aes(x = area)) +
  geom_point(aes(y = direct), size = 2, colour = "#388894", alpha = 0.6) +   # scatter points
  geom_point(aes(y = mean_estimate), size = 2, colour = "#2b707a") +   # scatter points
  geom_line(aes(y = direct), linewidth = 1, colour = "#388894", alpha = 0.6) +  # line connecting points
  geom_line(aes(y = mean_estimate), linewidth = 1, colour = "#2b707a") +  # line connecting points
  labs(
    title = "Scatter + Line Plot of Estimated Means",
    x = "Area Index",
    y = "Value"
  )
```

```{r, warning=FALSE, message=FALSE}
ggplot(df, aes(x = , direct, y = mean_estimate)) +
  geom_point( size = 2, colour = "#2b707a") +
   geom_abline(intercept = 0, slope = 1, color = "gray40", linetype = "dashed") +
  geom_smooth(method = "lm", color = "#2b707a", se = FALSE) +
  ylim(0, 1) +
  labs(
    title = "Scatter Plot of Direct vs Model-Based",
    x = "Direct",
    y = "Model Based"
  )
```

Combine the CV of direct estimation and CV from output

```{r}
df_cv <- data.frame(
  direct = sqrt(dataBeta$vardir)/dataBeta$y*100,              
  cv_estimate = RSE_sub
)
df_cv <- df_cv[order(df_cv$direct), ]
df_cv$area <- seq_along(dataBeta$y)
```

Relative Standard Error of Subarea Mean Estimation

```{r, warning=FALSE}
ggplot(df_cv, aes(x = area)) +
  geom_point(aes(y = direct), size = 2, colour = "#388894", alpha = 0.5) +
  geom_point(aes(y = cv_estimate), size = 2, colour = "#2b707a") +
  ylim(0, 100) +
  labs(
    title = "Scatter Plot of Direct vs Model-Based CV",
    x = "Area",
    y = "CV (%)"
  )
```

Owner

  • Login: Nasyazahira
  • Kind: user

GitHub Events

Total
  • Push event: 21
  • Create event: 4
Last Year
  • Push event: 21
  • Create event: 4

Packages

  • Total packages: 1
  • Total downloads:
    • cran 190 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
cran.r-project.org: saeHB.TF.beta

SAE using HB Twofold Subarea Model under Beta Distribution

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 190 Last month
Rankings
Dependent packages count: 25.9%
Dependent repos count: 31.9%
Average: 47.8%
Downloads: 85.7%
Maintainers (1)
Last synced: 10 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.4.0 depends
  • Rcpp >= 0.12.0 imports
  • RcppParallel >= 5.0.1 imports
  • bayesplot * imports
  • methods * imports
  • rstan >= 2.18.1 imports
  • rstantools >= 2.4.0 imports
  • stringr * imports