# 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{iid}}{\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{iid}}{\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 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_ -23.4 6.02   -3.89 0.125 -33.7 -23.1   -14  2304     1
##
## linpred_ :
##    Mean    SD t-value    MCSE q0.05 q0.5 q0.95 n_eff R_hat
## 1  2.60 0.254   10.23 0.00486  2.19 2.61  3.01  2743 0.999
## 2  3.02 0.371    8.12 0.00720  2.41 3.02  3.62  2662 1.000
## 3  3.16 0.241   13.13 0.00445  2.76 3.16  3.57  2922 1.000
## 4  1.91 0.175   10.88 0.00320  1.62 1.90  2.20  3000 1.000
## 5  2.99 0.230   12.99 0.00443  2.60 2.98  3.37  2687 0.999
## 6  3.22 0.301   10.68 0.00563  2.72 3.22  3.71  2867 1.002
## 7  2.29 0.210   10.93 0.00387  1.95 2.29  2.63  2937 1.000
## 8  3.96 0.193   20.52 0.00364  3.64 3.97  4.28  2815 1.000
## 9  1.70 0.248    6.86 0.00453  1.29 1.70  2.11  3000 1.001
## 10 2.64 0.187   14.09 0.00342  2.33 2.64  2.95  3000 1.001
## ... 65 elements suppressed ...
##
## beta :
##             Mean    SD t-value    MCSE q0.05  q0.5 q0.95 n_eff R_hat
## (Intercept) 1.00 0.125    7.98 0.00229 0.795 0.998  1.21  3000     1
## x           3.05 0.212   14.39 0.00392 2.684 3.045  3.39  2916     1
##
## v_sigma :
##          Mean     SD t-value    MCSE q0.05  q0.5 q0.95 n_eff R_hat
## v_sigma 0.469 0.0577    8.14 0.00162 0.383 0.465 0.567  1263     1
##
## v :
##       Mean    SD t-value    MCSE   q0.05    q0.5  q0.95 n_eff R_hat
## 1  -0.4522 0.260  -1.737 0.00498 -0.8708 -0.4464 -0.022  2728 1.000
## 2  -0.2657 0.372  -0.715 0.00681 -0.8693 -0.2647  0.334  2981 1.000
## 3   0.2393 0.246   0.975 0.00454 -0.1676  0.2371  0.648  2921 1.000
## 4   0.3461 0.195   1.772 0.00357  0.0335  0.3435  0.672  3000 1.001
## 5  -0.5274 0.241  -2.187 0.00450 -0.9293 -0.5311 -0.138  2878 0.999
## 6  -0.0528 0.303  -0.174 0.00561 -0.5457 -0.0503  0.444  2917 1.001
## 7  -0.4344 0.216  -2.012 0.00394 -0.7846 -0.4345 -0.085  3000 1.000
## 8   0.2249 0.212   1.063 0.00398 -0.1281  0.2279  0.576  2818 1.001
## 9   0.2541 0.256   0.993 0.00467 -0.1664  0.2547  0.684  3000 1.002
## 10 -0.5063 0.199  -2.548 0.00363 -0.8364 -0.5067 -0.186  3000 1.002
## ... 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 ## 96.76003 49.95421 compute_WAIC(sim, show.progress=FALSE) ## WAIC1 p_WAIC1 WAIC2 p_WAIC2 ## 67.49842 20.69779 89.36142 31.62929 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")  