### Random-Effects Model

This example illustrates how you can fit a normal likelihood random-effects model in PROC MCMC. PROC MCMC offers you the ability to model beyond the normal likelihood (see Logistic Regression Random-Effects Model, Nonlinear Poisson Regression Multilevel Random-Effects Model, and Piecewise Exponential Frailty Model).

Consider a scenario in which data are collected in groups and you want to model group-specific effects. You can use a random-effects model (sometimes also known as a variance-components model):

where is the group index and indexes the observations in the ith group. In the regression model, the fixed effects and are the intercept and the coefficient for variable , respectively. The random effect is the mean for the ith group, and are the error term.

Consider the following SAS data set:

title 'Random-Effects Model';

data heights;
input Family G\$ Height @@;
datalines;
1 F 67   1 F 66   1 F 64   1 M 71   1 M 72   2 F 63
2 F 63   2 F 67   2 M 69   2 M 68   2 M 70   3 F 63
3 M 64   4 F 67   4 F 66   4 M 67   4 M 67   4 M 69
;


The response variable Height measures the heights (in inches) of 18 individuals. The covariate x is the gender (variable G), and the individuals are grouped according to Family (group index). Since the variable G is a character variable and PROC MCMC does not support a CLASS statement, you need to create the corresponding design matrix. In this example, the design matrix for a factor variable of level 2 (M and F) can be constructed using the following statement:

data input;
set heights;
if g eq 'F' then gf = 1;
else gf = 0;
drop g;
run;


The data set variable gf is a numeric variable and can be used in the regression model in PROC MCMC.

In data sets with factor variables that have more levels, you can consider using PROC TRANSREG to construct the design matrix. See the section Create Design Matrix for more information.

To model the data, you can assume that Height is normally distributed:

The priors on the parameters , , are also assumed to be normal:

Priors on the variance terms, and , are inverse-gamma:

The inverse-gamma distribution is a conjugate prior for the variance in the normal likelihood and the variance in the prior distribution of the random effect.

The following statements fit a linear random-effects model to the data and produce the output shown in Figure 59.9 and Figure 59.10:

ods graphics on;
proc mcmc data=input outpost=postout nmc=50000 seed=7893 plots=trace;
ods select Parameters REparameters PostSumInt tracepanel;
parms b0 0 b1 0 s2 1 s2g 1;

prior b: ~ normal(0, var = 10000);
prior s: ~ igamma(0.01, scale = 0.01);
random gamma ~ normal(0, var = s2g) subject=family monitor=(gamma);
mu = b0 + b1 * gf + gamma;
model height ~ normal(mu, var = s2);
run;
ods graphics off;


Some of the statements are very similar to those shown in the previous two examples. The ODS GRAPHICS ON statement enables ODS Graphics. The PROC MCMC statement specifies the input and output data sets, the simulation size, and a random number seed. The ODS SELECT statement displays the model parameter and random-effects parameter information tables, summary statistics table, the interval statistics table, and the trace plots.

The PARMS statement lumps all four model parameters in a single block. They are b0 (overall intercept), b1 (main effect for gf), s2 (variance of the likelihood function), and s2g (variance of the random effect). If a random walk Metropolis sampler is the only applicable sampler for all parameters, then these four parameters are updated in a single block. However, because PROC MCMC updates the parameters s2 and s2g via conjugacy, these parameters are separated into individual blocks. (See the Block column in Parameters table in Figure 59.8.)

The PRIOR statements specify priors for all the parameters. The notation b: is a shorthand for all symbols that start with the letter ‘b’. In this example, b: includes b0 and b1. Similarly, s: stands for both s2 and s2g. This shorthand notation can save you some typing, and it keeps your statements tidy.

The RANDOM statement specifies a single random effect to be gamma, and specifies that it has a normal prior centered at 0 with variance s2g. The SUBJECT= argument in the RANDOM statement defines a group index (family) in the model, where all observations from the same family should have the same group indicator value. The MONITOR= option outputs analysis for all the random-effects parameters.

Finally, the MU assignment statement calculates the expected value of the height of the model. The calculation includes the random-effects term gamma. The MODEL statement specifies the likelihood function for height.

The Parameters and Random-Effects Parameters tables, shown in Figure 59.8, contain information about the model parameters and the four random-effects parameters.

Figure 59.8: Model and Random-Effects Parameter Information

 Random-Effects Model

The MCMC Procedure

Parameters
Block Parameter Sampling
Method
Initial
Value
Prior Distribution
1 s2 Conjugate 1.0000 igamma(0.01, scale = 0.01)
2 s2g Conjugate 1.0000 igamma(0.01, scale = 0.01)
3 b0 N-Metropolis 0 normal(0, var = 10000)
b1   0 normal(0, var = 10000)

Random Effect Parameters
Parameter Sampling
Method
Subject Number of
Subjects
Subject
Values
Prior
Distribution
gamma N-Metropolis Family 4 1 2 3 4 normal(0, var = s2g)

The posterior summary and interval statistics for the model parameters and the random-effects parameters are shown in Figure 59.9.

Figure 59.9: Posterior Summary and Interval Statistics

 Random-Effects Model

The MCMC Procedure

Posterior Summaries and Intervals
Parameter N Mean Standard
Deviation
95% HPD Interval
b0 50000 68.4687 1.2757 65.9159 71.1771
b1 50000 -3.5502 0.9762 -5.4269 -1.5257
s2 50000 4.1446 1.9506 1.3768 7.9151
s2g 50000 4.9378 19.2469 0.00105 18.7219
gamma_1 50000 0.9383 1.3255 -1.0078 4.1195
gamma_2 50000 0.0139 1.1956 -2.6746 2.4767
gamma_3 50000 -1.3470 1.6495 -4.7168 1.0744
gamma_4 50000 0.0966 1.1971 -2.4108 2.7432

Trace plots for all the parameters are shown in Figure 59.10. The mixing looks very reasonable, suggesting convergence.

Figure 59.10: Plots for and Log of the Posterior Density

From the interval statistics table, you see that both the equal-tail and HPD intervals for are positive, strongly indicating the positive effect of the parameter. On the other hand, both intervals for cover the value zero, indicating that gf does not have a strong impact on predicting height in this model.