BookmarkSubscribeRSS Feed
csfcgua1
Fluorite | Level 6

Hello, 

 

say I have a data set comprised of blood pressure measurements from N subjects. I would like to assign a status (1, 2, or 3) to each subject based on his/her blood pressure level, and the probability of being 1, 2, or 3 is a dirichlet distribution.

Data BP;
input ID BP;
datalines;
1 90
2 120
3 80
4 75
5 ...
;
run;

 

I modified the SAS official Example 75.1-Simulating Samples From a Known Density to perform the analysis:

proc mcmc data=BP outpost=simout seed=1234 nmc=30000 monitor=(z p);
array ref_p[3] (0.3 0.4 0.3);
array ref_mu[3] (70 100 130);
parm z p mu;
prior z ~ table(p);

hyperprior p ~ dirich(ref_p);

prior mu ~ normal(ref_mu[z], prec = 0.05);

prior tau ~ gamma(0.1, iscale=0.1);

model BP ~ normal(mu, prec = tau);
run;

The desired outcome would be like this:

ID p1     p2    p3    z
1  0.2    0.3   0.5   3
2  0.4    0.5   0.1   2
3  0.6    0.3   0.1   1
4 ...
...

but I only obtained an overall summary of z (mean of 2 since the second ref_p is the highest) for the whole group instead of for each subject.

 

Does anyone know how to modify the code so that I can assign which variables should be estimated for the whole group and which are by subject?

 

Thanks.

1 REPLY 1
csfcgua1
Fluorite | Level 6

Found the solution.

Just use the random statement for z, then everything works out.

 

random z ~ table(p) subject = id;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 278 views
  • 0 likes
  • 1 in conversation