I am trying to check the variance of random slopes. The following code is provided in a SAS usage Note:
proc mixed data=&dataset plot(maxpoints=7000);
class ID;
model col1=timepoint/solution;
random int timepoint/subject=ID type=un solution;
ods output solutionf=sf(keep=effect estimate rename=(estimate=overall));
ods output solutionr=sr(keep=effect ID estimate rename=(estimate=ssdev));
run;
proc sort data=sf;
by effect;
run;
proc sort data=sr;
by effect;
run;
data final_&indice;
merge sf sr;
by effect;
sscoeff_&indice= overall + ssdev;
run;
When I run a proc univariate on sscoeff_&indice I do not get the same variance estimate that I get on the proc mixed output labeled UN(1,1). Does anyone know why they would not be equal?
Thanks
First of all, the slope variance estimate from PROC MIXED is for the subject slope "effect". You would need to compute the variance for ssdev rather than sscoeff with PROC UNIVARIATE if you want to check on the consistency of the variance estimate.
Second of all, you are not going to get the same variance estimates by these two approaches. The SSDEV estimates are BLUPS and have the "shrinkage" property. The variance from PROC UNIVARIATE should be close, but is likely to be smaller, and that is expected -- the two variances are not the same thing.
@Sanscrit_2prov wrote:
I am trying to check the variance of random slopes. The following code is provided in a SAS usage Note:
proc mixed data=&dataset plot(maxpoints=7000);
class ID;
model col1=timepoint/solution;
random int timepoint/subject=ID type=un solution;
ods output solutionf=sf(keep=effect estimate rename=(estimate=overall));
ods output solutionr=sr(keep=effect ID estimate rename=(estimate=ssdev));
run;
proc sort data=sf;
by effect;
run;
proc sort data=sr;
by effect;
run;
data final_&indice;
merge sf sr;
by effect;
sscoeff_&indice= overall + ssdev;
run;When I run a proc univariate on sscoeff_&indice I do not get the same variance estimate that I get on the proc mixed output labeled UN(1,1). Does anyone know why they would not be equal?
Thanks
How much difference are you seeing?
Different procs different algorithms, different assumptions about data to estimate variance, possibly different numbers of records used depending on where missing values occur.
From proc mixed documentation: "The basic assumption is that the data are linearly related to unobserved multivariate normal random variables.". Proc univariate is generally only looking at one variable at a time. You didn't show you Proc Univariate code so can't tell if any specific options there may also have an affect.
You might also include the link to the Usage Note. There might be comments in there that apply.
To follow up on @ballardw 's comment, you are fitting an unstructured variance-covariance matrix. That implies that there is at least one non-zero covariance entry in the matrix column for your indexed variable (unless you are fitting UN(1)). The covariance(s) for your indexed variables are the source of the difference between the univariate and the multivariate estimates. I am not sure but I suspect that if you fit the UN(1) structure and carried out your calculations that the two should be in closer agreement. Without a specific dataset, I am unsure if this is generally true, or just an artifact from my simulated data.
SteveDenham
First of all, the slope variance estimate from PROC MIXED is for the subject slope "effect". You would need to compute the variance for ssdev rather than sscoeff with PROC UNIVARIATE if you want to check on the consistency of the variance estimate.
Second of all, you are not going to get the same variance estimates by these two approaches. The SSDEV estimates are BLUPS and have the "shrinkage" property. The variance from PROC UNIVARIATE should be close, but is likely to be smaller, and that is expected -- the two variances are not the same thing.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.