/*Kaz's SAS juku*/
/*www.estat.us*/
/*PROC MIXED*/
Data ABC;
set sashelp.Prdsal3; /*This is a SAS default data set for a practice*/
run;
proc mixed data=ABC covtest noclprint;
title "Non conditional model";
class state;
model actual =/solution ddfm=bw;
random intercept/sub=state;
run;
proc mixed data=ABC covtest noclprint;
title "One predictor as an fixed effect";
class state;
model actual =predict/solution ddfm=bw;
random intercept/sub=state;
run;
proc mixed data=ABC covtest noclprint;
title "Character variable as a random effect";
class state product;
model actual =predict product/solution ddfm=bw;
random intercept/sub=state;
random product/sub=state group=product;
run;
/*notes: for this case, if you look at covariance parameter estimates, some results return ".," which means that the variance
components were too small to be estimated. However, this also is influenced by the matric
of the values used for variables involved. You can try rerunning by multiplying the dependent
variable by a large number or do proc standard mean=0 std=100; or something, so
coefficients will be large enough and the variation of them are large enough to be estimated.
By the way this is the greatest feature of SAS PROC MIXED--the fact that it gives up estimating when
the numbers to be estimated are too small. It just returns "." and tell you they are too small.
If this were Bryk and Raudenbush's HLM, the results just don't converge and we don't know what
happened. SAS proc mixed runs the analysis anyways, so we know it happened.
*/
proc mixed data=ABC covtest noclprint;
title "Character variable as a random effect";
class state product;
model actual =predict product/solution ddfm=bw;
random intercept/sub=state;
random product/sub=state ;
run;
proc mixed data=ABC covtest noclprint;
title "Main effects and Interaction Effect, all as fixed effects";
class state product;
model actual =predict product predict*product/solution ddfm=bw;
random intercept/sub=state;
run;
proc mixed data=ABC covtest noclprint;
title "Effect effects and Interaction Effect as random effects";
class state product;
model actual =predict product predict*product/solution ddfm=bw;
random intercept/sub=state;
random predict /sub=state;
random product /sub=state;
random predict*product /sub=state;
run;