I am trying to use "proc mcmc" to specify a correlated random intercept and slope model, similar to the one exemplified on this page: http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_mcmc_examples15.htm The purpose is to specify more complex covariance structures of the residual error. I have written a program. The problem does not run. Immediately after submitting I get Read Access Violation and Write Access Violation errors. So, what is wrong? Here is the program with the dataset: data WORK.ndata;
infile datalines;
input Patient Treatment $ Cycle $ Period $ Y;
datalines;
1 A 1 1 2394
1 B 1 2 2686
1 A 2 3 2515
1 B 2 4 2675
1 A 3 5 2583
1 B 3 6 2802
2 A 1 1 2746
2 B 1 2 2726
2 A 2 3 2592
2 B 2 4 2867
2 A 3 5 2743
2 B 3 6 2742
3 A 1 1 2668
3 B 1 2 2560
3 A 2 3 2542
3 B 2 4 2584
3 A 3 5 2491
3 B 3 6 2737
4 A 1 1 2397
4 B 1 2 2696
4 A 2 3 2411
4 B 2 4 2895
4 A 3 5 2499
4 B 3 6 2760
5 A 1 1 3179
5 B 1 2 3221
5 A 2 3 2952
5 B 2 4 3096
5 A 3 5 2600
5 B 3 6 3192
6 A 1 1 2643
6 B 1 2 2496
6 A 2 3 2759
6 B 2 4 2847
6 A 3 5 2651
6 B 3 6 2860
7 A 1 1 2678
7 B 1 2 2843
7 A 2 3 2492
7 B 2 4 2763
7 A 3 5 2801
7 B 3 6 2890
8 A 1 1 2887
8 B 1 2 2862
8 A 2 3 2875
8 B 2 4 3083
8 A 3 5 2689
8 B 3 6 2967
9 A 1 1 2490
9 B 1 2 2841
9 A 2 3 2648
9 B 2 4 3044
9 A 3 5 2688
9 B 3 6 2914
10 A 1 1 2268
10 B 1 2 2576
10 A 2 3 2413
10 B 2 4 2493
10 A 3 5 2344
10 B 3 6 2699
11 A 1 1 2617
11 B 1 2 2923
11 A 2 3 2629
11 B 2 4 2832
11 A 3 5 2732
11 B 3 6 2866
12 A 1 1 2627
12 B 1 2 2759
12 A 2 3 2712
12 B 2 4 2698
12 A 3 5 2572
12 B 3 6 2826
run;
proc sort data=WORK.ndata;
by Patient Period;
run;
* Determine number of patients and number of observations ;
data _NULL_;
set WORK.ndata nobs=_n;
by Patient;
retain num 0;
if first.Patient then num+1;
call symput('PatientNumber', num);
call symputx('nobs', _n);
run;
* Create random effects design matrix ;
data WORK.design_matrix;
set WORK.ndata;
array b_[&PatientNumber];
array d_[&PatientNumber];
do i = 1 to &PatientNumber by 1;
if Patient = i then do;
b_[i] = 1;
if Treatment = "B" then d_[i] = 1;
else d_[i] = 0;
end;
else do;
b_[i] = 0;
d_[i] = 0;
end;
end;
keep b_: d_:;
run;
* Create dataset with first and last index ;
data WORK.index;
set WORK.ndata;
by Patient;
retain num;
if first.Patient then num = _n_;
if last.Patient then do;
first = num;
last = _n_;
output;
end;
keep first last;
run;
* Create dummy dataset ;
data dummy;
run;
proc mcmc data=dummy outpost=outAR1_jointllike seed=3141593 nmc=10000 thin=1 nbi=0 jointllike;
array ALPHA[%eval(2*&PatientNumber)] b_1-b_%eval(&PatientNumber) d_1-d_%eval(&PatientNumber);
array MU[&nobs];
array COV[&nobs,&nobs];
array M[%eval(2*&PatientNumber)];
array G[%eval(2*&PatientNumber),%eval(2*&PatientNumber)];
begincnst;
call zeromatrix(G);
do i = 1 to &PatientNumber by 1;
M[i] = gamma_00;
M[i+&PatientNumber] = gamma_10;
G[i,i] = sigma_u0;
G[i+&PatientNumber,i+&PatientNumber] = sigma_u1;
G[i,i+&PatientNumber] = sigma_u0u1;
G[i+&PatientNumber,i] = sigma_u1u0;
end;
endcnst;
array TAU[2] gamma_00 gamma_10;
array SIGMA[2,2] sigma_u0 sigma_u0u1 sigma_u1u0 sigma_u1;
array THETA[2];
array DELTA[2,2];
array PSI[2,2];
array data[&nobs] / nosymbols;
array F[&PatientNumber] / nosymbols;
array L[&PatientNumber] / nosymbols;
array XZ[&nobs,%eval(2*&PatientNumber)] / nosymbols;
begincnst;
call zeromatrix(THETA);
call identity(DELTA);
call mult(DELTA, 1e7, DELTA);
call identity(PSI);
call mult(PSI, 0.01, PSI);
rc = read_array("WORK.ndata", data, "Y");
rc = read_array("WORK.index", F, "first");
rc = read_array("WORK.index", L, "last");
rc = read_array("WORK.design_matrix", XZ);
endcnst;
parms TAU;
parms SIGMA;
parms ALPHA;
parms sigma_e;
parms rho 0.5;
hyperprior TAU ~ mvn(THETA, DELTA);
hyperprior SIGMA ~ iwish(2, PSI);
prior ALPHA ~ mvn(M, G);
prior sigma_e ~ igamma(0.01, scale=0.01);
prior rho ~ uniform(left=-1, right=1);
call zeromatrix(COV);
do k = 1 to &PatientNumber by 1;
do i = F[k] to L[k] by 1;
COV[i,i] = sigma_e;
do j = i+1 to L[k] by 1;
COV[i,j] = sigma_e*rho**abs(i-j);
COV[j,i] = COV[i,j];
end;
end;
end;
call mult(XZ, ALPHA, MU);
llike = lpdfmvn(data, MU, COV);
model general(llike);
run;
%symdel PatientNumber nobs;
proc sql;
drop table WORK.design_matrix, WORK.index, WORK.dummy;
quit;
... View more