# Basic area-level model

The basic area-level model (Fay and Herriot 1979; Rao and Molina 2015) is given by $y_i | \theta_i \stackrel{\mathrm{ind}}{\sim} {\cal N} (\theta_i, \psi_i) \,, \\ \theta_i = \beta' x_i + v_i \,,$ where $$i$$ runs from 1 to $$m$$, the number of areas, $$\beta$$ is a vector of regression coefficients for given covariates $$x_i$$, and $$v_i \stackrel{\mathrm{ind}}{\sim} {\cal N} (0, \sigma_v^2)$$ are independent random area effects. For each area an observation $$y_i$$ is available with given variance $$\psi_i$$.

First we generate some data according to this model:

m <- 75L  # number of areas
df <- data.frame(
area=1:m,      # area indicator
x=runif(m)     # covariate
)
v <- rnorm(m, sd=0.5)    # true area effects
theta <- 1 + 3*df$x + v # quantity of interest psi <- runif(m, 0.5, 2) / sample(1:25, m, replace=TRUE) # given variances df$y <- rnorm(m, theta, sqrt(psi))

A sampler function for a model with a regression component and a random intercept is created by

library(mcmcsae)
model <- y ~ reg(~ 1 + x, name="beta") + gen(factor = ~iid(area), name="v")
sampler <- create_sampler(model, sigma.fixed=TRUE, Q0=1/psi, linpred="fitted", data=df)

The meaning of the arguments used here is as follows:

• the first argument is a formula specifying the response variable and the linear predictor part of the model
• sigma.fixed=TRUE signifies that the observation level variance parameter is fixed at 1. In this case it means that the variances are known and given by psi.
• the function expects precisions rather than variances, and with Q0=1/psi the precisions are set to the vector 1/psi.
• linpred="fitted" indicates that we wish to obtain samples from the posterior distribution for the vector $$\theta$$ of small area means.
• data is the data.frame in which variables used in the model specification are looked up.

An MCMC simulation using this sampler function is then carried out as follows:

sim <- MCMCsim(sampler, store.all=TRUE, verbose=FALSE)

A summary of the results is obtained by

(summ <- summary(sim))
## llh_ :
##       Mean   SD t-value  MCSE q0.05  q0.5 q0.95 n_eff R_hat
## llh_ -37.1 6.49   -5.71 0.141   -48 -36.8 -26.7  2127     1
##
## linpred_ :
##     Mean    SD t-value    MCSE q0.05  q0.5 q0.95 n_eff R_hat
## 1  0.991 0.299    3.32 0.00570 0.488 0.995  1.47  2748 1.001
## 2  1.605 0.230    6.98 0.00424 1.237 1.604  1.98  2940 1.001
## 3  1.122 0.285    3.94 0.00520 0.640 1.125  1.59  3000 1.001
## 4  4.217 0.190   22.14 0.00348 3.900 4.218  4.53  3000 1.000
## 5  2.519 0.242   10.43 0.00445 2.126 2.521  2.91  2943 0.999
## 6  3.727 0.247   15.10 0.00469 3.331 3.729  4.14  2768 1.003
## 7  1.128 0.454    2.49 0.00903 0.379 1.138  1.87  2524 1.001
## 8  4.041 0.453    8.93 0.00946 3.310 4.036  4.78  2292 1.003
## 9  1.608 0.391    4.11 0.00715 0.962 1.613  2.24  2995 1.000
## 10 3.145 0.311   10.11 0.00576 2.638 3.142  3.66  2920 1.000
## ... 65 elements suppressed ...
##
## beta :
##             Mean    SD t-value    MCSE q0.05 q0.5 q0.95 n_eff R_hat
## (Intercept) 1.05 0.145     7.2 0.00826 0.796 1.05  1.27   309  1.01
## x           2.72 0.244    11.2 0.01428 2.343 2.71  3.14   291  1.00
##
## v_sigma :
##          Mean     SD t-value    MCSE q0.05  q0.5 q0.95 n_eff R_hat
## v_sigma 0.531 0.0699     7.6 0.00197 0.427 0.528 0.653  1254     1
##
## v :
##       Mean    SD t-value    MCSE  q0.05    q0.5 q0.95 n_eff R_hat
## 1  -0.3215 0.311 -1.0330 0.00771 -0.845 -0.3135 0.186  1631     1
## 2  -0.2090 0.240 -0.8707 0.00574 -0.606 -0.2042 0.186  1746     1
## 3  -0.0130 0.302 -0.0430 0.00780 -0.517 -0.0178 0.492  1494     1
## 4   0.5634 0.218  2.5820 0.00786  0.201  0.5663 0.918   771     1
## 5   0.2403 0.247  0.9710 0.00544 -0.176  0.2400 0.640  2073     1
## 6   0.6126 0.257  2.3808 0.00643  0.189  0.6168 1.029  1602     1
## 7   0.0383 0.440  0.0870 0.00803 -0.676  0.0410 0.752  3000     1
## 8   0.8662 0.447  1.9361 0.00915  0.152  0.8567 1.600  2391     1
## 9  -0.0250 0.389 -0.0644 0.00710 -0.656 -0.0240 0.608  2997     1
## 10 -0.1748 0.317 -0.5514 0.00683 -0.680 -0.1758 0.339  2151     1
## ... 65 elements suppressed ...

In this example we can compare the model parameter estimates to the ‘true’ parameter values that have been used to generate the data. In the next plots we compare the estimated and ‘true’ random effects, as well as the model estimates and ‘true’ estimands. In the latter plot, the original ‘direct’ estimates are added as red triangles.

plot(v, summ$v[, "Mean"], xlab="true v", ylab="posterior mean"); abline(0, 1) plot(theta, summ$linpred_[, "Mean"], xlab="true theta", ylab="estimated"); abline(0, 1)
points(theta, df$y, col=2, pch=2)  We can compute model selection measures DIC and WAIC by compute_DIC(sim) ## DIC p_DIC ## 125.21448 51.10619 compute_WAIC(sim, show.progress=FALSE) ## WAIC1 p_WAIC1 WAIC2 p_WAIC2 ## 98.55269 24.44337 122.48140 36.40772 Posterior means of residuals can be extracted from the simulation output using method residuals. Here is a plot of (posterior means of) residuals against covariate $$x$$: plot(df$x, residuals(sim, mean.only=TRUE), xlab="x", ylab="residual"); abline(h=0) A linear predictor in a linear model can be expressed as a weighted sum of the response variable. If we set compute.weights=TRUE then such weights are computed for all linear predictors specified in argument linpred. In this case it means that a set of weights is computed for each area.

sampler <- create_sampler(model, sigma.fixed=TRUE, Q0=1/psi,
linpred="fitted", data=df, compute.weights=TRUE)
sim <- MCMCsim(sampler, store.all=TRUE, verbose=FALSE)

Now the weights method returns a matrix of weights, in this case a 75 $$\times$$ 75 matrix $$w_{ij}$$ holding the weight of direct estimate $$i$$ in linear predictor $$j$$. To verify that the weights applied to the direct estimates yield the model-based estimates we plot them against each other. Also shown is a plot of the weight of the direct estimate for each area in the predictor for that same area, against the variance of the direct estimate.

plot(summ$linpred_[, "Mean"], crossprod(weights(sim), df$y),
xlab="estimate", ylab="weighted average")
abline(0, 1)
plot(psi, diag(weights(sim)), ylab="weight")  