Normal: Small Area Estimation using Hierarchical Bayesian under...

View source: R/Normal.R

NormalR Documentation

Small Area Estimation using Hierarchical Bayesian under Normal Distribution

Description

This function is implemented to variable of interest (y) that assumed to be a Normal Distribution. The range of data is (-\infty < y < \infty)

Usage

Normal(
  formula,
  vardir,
  iter.update = 3,
  iter.mcmc = 10000,
  coef,
  var.coef,
  thin = 2,
  burn.in = 2000,
  tau.u = 1,
  data
)

Arguments

formula

Formula that describe the fitted model

vardir

Sampling variances of direct estimations

iter.update

Number of updates with default 3

iter.mcmc

Number of total iterations per chain with default 10000

coef

a vector contains prior initial value of Coefficient of Regression Model for fixed effect with default vector of 0 with the length of the number of regression coefficients

var.coef

a vector contains prior initial value of variance of Coefficient of Regression Model with default vector of 1 with the length of the number of regression coefficients

thin

Thinning rate, must be a positive integer with default 2

burn.in

Number of iterations to discard at the beginning with default 2000

tau.u

Prior initial value of inverse of Variance of area random effect with default 1

data

The data frame

Value

This function returns a list of the following objects:

Est

A vector with the values of Small Area mean Estimates using Hierarchical bayesian method

refVar

Estimated random effect variances

coefficient

A dataframe with the estimated model coefficient

plot

Trace, Dencity, Autocorrelation Function Plot of MCMC samples

Examples


# Data Generation
set.seed(123)
m <- 30
x1 <- runif(m, 0, 1)
x2 <- runif(m, 1, 5)
x3 <- runif(m, 10, 15)
x4 <- runif(m, 10, 20)
b0 <- b1 <- b2 <- b3 <- b4 <- 0.5
u <- rnorm(m, 0, 1)
vardir <- 1 / rgamma(m, 1, 1)
Mu <- b0 + b1 * x1 + b2 * x2 + b3 * x3 + b4 * x4 + u
y <- rnorm(m, Mu, sqrt(vardir))
dataNormal <- as.data.frame(cbind(y, x1, x2, x3, x4, vardir))
dataNormalNs <- dataNormal
dataNormalNs$y[c(3, 10, 15, 29, 30)] <- NA
dataNormalNs$vardir[c(3, 10, 15, 29, 30)] <- NA


## Compute Fitted Model
## y ~ x1 +x2 +x3 +x4


## For data without any nonsampled area
formula <- y~x1 + x2 + x3 + x4
var <- "vardir"
v <- c(1, 1, 1, 1, 1)
c <- c(0, 0, 0, 0, 0)


## Using parameter coef and var.coef
saeHBnormal <- Normal(formula, vardir = var, coef = c, var.coef = v, data = dataNormal)

saeHBnormal$Est # Small Area mean Estimates
saeHBnormal$refVar # Random effect variance
saeHBnormal$coefficient # coefficient
# Load Library 'coda' to execute the plot
# autocorr.plot(saeHBnormal$plot[[3]]) is used to generate ACF Plot
# plot(saeHBnormal$plot[[3]]) is used to generate Density and trace plot

## Do not using parameter coef and var.coef
saeHBnormal <- Normal(formula, vardir = "vardir", data = dataNormal)



## For data with nonsampled area use dataNormalNs


saeHB documentation built on Nov. 26, 2025, 5:06 p.m.