This script illustrates the use of the MCMC procedure for the analysis of a hierarchical model. The data, internally generated, track the evolution of the weight of 30 rats over five periods. The model assumes that the weight growth for each rat follows a straight line (slope and intercept), but that these parameters (random effects) are specific to each rat and come from a common multivariate normal distribution. The procedure estimates the parameters of this group distribution as well as the residual variance of the model.
Data Analysis
Type : CREATION_INTERNE
The 'rats' dataset is generated via a DATALINES statement. The code transforms the data from a wide format (multiple measurements per row) to a long format (one measurement per row with corresponding 'subject' and 'age' variables).
1 Code Block
DATA STEP Data
Explanation : This data block reads rat weights from 'datalines'. It uses an array (ARRAY) to map measurement days and calculations on the automatic variable `_n_` to assign a subject ID (`subject`) and age (`age`) to each measurement. The 'input weight @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;' statement is used to read multiple weight observations from a single data line, thus creating a dataset in long format.
Explanation : This block applies the MCMC procedure to perform Bayesian analysis. It defines model parameters, including hyperparameters (theta_c, Sig_c, var_y) and their prior distributions (PRIOR). The RANDOM statement specifies that the alpha and beta parameters (grouped in the 'theta' array) are random effects per subject, following a multivariate normal distribution. The MODEL statement defines the likelihood model for weight ('weight'). The procedure generates 10000 samples from the posterior distribution of the parameters, which are stored in the 'postout' table.
random theta ~ mvn(theta_c, Sig_c) subject=subject
17
monitor=(alpha_9 beta_9 alpha_25 beta_25);
18
mu = alpha + beta * age;
19
model weight ~ normal(mu, var=var_y);
20
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.