# 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_ -20.5 5.84   -3.51 0.111 -30.6 -20.2 -11.4  2784     1
##
## linpred_ :
##     Mean    SD t-value    MCSE  q0.05  q0.5 q0.95 n_eff R_hat
## 1  0.996 0.281    3.55 0.00530 0.5349 1.001  1.45  2802 1.000
## 2  1.853 0.189    9.83 0.00344 1.5436 1.857  2.16  3000 1.000
## 3  3.773 0.259   14.56 0.00473 3.3273 3.783  4.19  3000 0.999
## 4  3.683 0.245   15.03 0.00447 3.2809 3.685  4.09  3000 1.000
## 5  2.307 0.323    7.14 0.00590 1.7668 2.305  2.84  3000 1.000
## 6  0.773 0.430    1.80 0.00892 0.0744 0.776  1.46  2328 1.000
## 7  1.207 0.264    4.57 0.00483 0.7718 1.210  1.64  3000 1.000
## 8  2.964 0.419    7.08 0.00867 2.2646 2.982  3.64  2332 1.000
## 9  4.228 0.291   14.52 0.00532 3.7427 4.226  4.72  3000 1.000
## 10 4.172 0.189   22.07 0.00347 3.8647 4.169  4.48  2960 1.000
## ... 65 elements suppressed ...
##
## beta :
##              Mean    SD t-value    MCSE q0.05  q0.5 q0.95 n_eff R_hat
## (Intercept) 0.868 0.138    6.29 0.00818 0.634 0.871  1.09   284  1.02
## x           3.123 0.242   12.93 0.01296 2.741 3.121  3.54   347  1.01
##
## v_sigma :
##          Mean     SD t-value    MCSE q0.05  q0.5 q0.95 n_eff R_hat
## v_sigma 0.498 0.0573    8.69 0.00128 0.412 0.495 0.598  2012     1
##
## v :
##       Mean    SD t-value    MCSE   q0.05    q0.5 q0.95 n_eff R_hat
## 1  -0.2275 0.288  -0.790 0.00635 -0.7108 -0.2265 0.231  2053 1.001
## 2   0.1043 0.202   0.515 0.00579 -0.2249  0.1018 0.441  1221 1.005
## 3   0.2030 0.272   0.746 0.00690 -0.2442  0.2006 0.659  1554 0.999
## 4   0.3591 0.257   1.398 0.00599 -0.0550  0.3579 0.784  1838 1.000
## 5  -0.2696 0.323  -0.834 0.00590 -0.8039 -0.2690 0.266  3000 1.000
## 6  -0.2594 0.423  -0.613 0.00798 -0.9566 -0.2564 0.425  2804 1.000
## 7   0.0313 0.275   0.114 0.00642 -0.4120  0.0339 0.483  1839 1.005
## 8  -0.3252 0.414  -0.785 0.00824 -1.0049 -0.3133 0.349  2525 1.000
## 9   0.3390 0.297   1.143 0.00660 -0.1517  0.3412 0.833  2019 1.001
## 10  0.2964 0.222   1.334 0.00763 -0.0669  0.2965 0.661   848 1.003
## ... 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 ## 92.92373 51.91088 compute_WAIC(sim, show.progress=FALSE) ## WAIC1 p_WAIC1 WAIC2 p_WAIC2 ## 61.51057 20.51778 84.18910 31.85704 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")  