BookmarkSubscribeRSS Feed
davidGOLIATH
Calcite | Level 5

Howdy.

Does anyone know of a way to script to compare mixed effects model mean structures with a likelihood ratio test in SAS?

I know SAS spits out -2 Log Likelihoods in proc mixed (with method=ml), and I can run two models (a simple example with linear models:  one with two main effects [random intercept, let's say]; and one with the two main effects and an interaction term [random slope + intercept]) then use each -2 Log Likelihood to construct a likelihood ratio statistic and test against chi-squared, but I would think there has to be some not-too-difficult way to script such a test rather than scrolling back through the outputs and constructing the test statistic "by hand."

I searched about a bit already, but didn't find anything helpful, except a fairly convoluted macro.

Any assistance will be much appreciated.

Thanks kindly -

d.G.

6 REPLIES 6
1zmm
Quartz | Level 8

PROC MIXED can create an Output Delivery System (ODS) tables of the fit statistics for a model, one of which is the -2*log likelihood statistic.  Run PROC MIXED twice to generate these SAS data sets of fit statistics, once with your more limited model and the other time with your more expansive model.  In a DATA step, select the -2*log likelihood statistic from the two ODS tables, merge these two tables together, subtract one statistic from the (renamed) other statistic, and calculate the probability under a chi-squared distribution that this difference is statistically significant.

lvm
Rhodochrosite | Level 12 lvm
Rhodochrosite | Level 12

Just to expand on the answer from 1zmm. The ODS output file is called FitStatistics. Here is a sample program for doing the likelihood ratio test for a fixed effect (treatment) based on two runs of MIXED. This is a different model from the one you describe, but it shows how to store the -2 log likelihoods, and then get their difference in a DATA step. You will have to keep track of the approriate number of degrees of freedom. One could get more sophisticated and store df for each run in other ODS files, combine all of these, and then get the chi-square p value in a data step, but this should get you in the right direction. For others reading this, it is very important that method=ml is used to do the likelihood ratio test for fixed effects.

data a;     *-generate some data for the demonstration;

do block = 1 to 6;

    blk = rannor(1)*sqrt(2);

    do trt = 1 to 4;

        error = rannor(1);

        y = 10 + blk + trt/2 + error;

        output;

        end;

    end;

;

proc mixed data = a method=ml;

ods output fitstatistics=fits1;

class block trt;

model y = trt / s;

random block;

run;

proc print data=fits1;

run;

proc mixed data = a method=ml;

ods output fitstatistics=fits2;

class block trt;

model y =  / s;

random block;

run;

proc print data=fits2;

run;

data combine;

    merge    fits1(obs=1 rename=(Value=one))

            fits2(obs=1 rename=(Value=two));

    statistic = two - one;

proc print data=combine;run;

mbakare
Calcite | Level 5

Thanks for this response. My worry with the likelihood ratio tests for mean structures in proc mixed is that  the difference of the -2 loglikelihood will have chi distribution with zero degree of freedom. From the example you gave, there is one covariance parameter in each of the fitted model which implies different of zero degree of freedom. This is the problem I am having with the analysis I am doing.

Please clarification.

davidGOLIATH
Calcite | Level 5

Thanks for the posts, 1zmm and lvm:  both helpful responses.

I was really hoping there was a way in SAS to put two (or more!) different models in a single procedure and have SAS calculate and output LR tests:  either ML-based for fixed-effect, mean-structure testing or REML-based for testing random-effects / covariance patterns.  If anyone out there knows of such a dangerous weapon  Smiley Wink  let a message-board brother know.

Thanks,

David Goliath

lvm
Rhodochrosite | Level 12 lvm
Rhodochrosite | Level 12

You were only asking about fixed effects in your original posts. In general, MIXED or GLIMMIX are designed to fit only one model at a time. So, you have to run the procedure twice. But for random effects, it is a different story. With GLIMMIX (not MIXED), you can use the COVTEST statement (don't confuse this with the covtest option in MIXED). Check out the documentation. This is a powerful tool for testing random effects using likelihood ratios.

davidGOLIATH
Calcite | Level 5

Thanks again for the reply, lvm.

True, I only asked about fixed effects in my first post, but I'm also wondering about REML-based LR tests for testing random effects / covariance patterns.

I see that covtest option in proc mixed produces standard errors and Wald Z-tests for covariance parameter estimates whereas covtest statement in proc glimmix appears to be testing any specified covariance pattern against an assumed-independent pattern.  Very kewl.

Much obliged.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 3388 views
  • 6 likes
  • 4 in conversation