Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Posterior outcome for "each subject" by Proc MCMC

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 11-13-2019 07:36 AM
(451 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Found the solution.

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

random z ~ table(p) subject = id;

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

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.