I am running a repeated measures mixed model, and I am testing the difference in differences.
I want to see if the difference in the machines (1 or 2) is different between 2 treatments. Each patient is tested on 2 machines, at certain times. So for example - at time 1, is the difference in machine1 vs machine 2 different between group 1 and group 2.
When using the 'joint' option in an LSMESTIMATE statement, is it possible to get an estimate of the difference in differences and CI of the difference?
I know that the LMESTIMATE statement is correct as I am getting the correct values - I'm just not sure how to output the difference and CI of difference.
PROC MIXED DATA=allt;
CLASS ptno machine time(ref="1") trt;
MODEL outcome = machine time trt machine*time trt*machine trt*time trt*machine*time ;
REPEATED time / subject=ptno(machine) type=un;
LSMeans machine*time*trt/ cl ;
LSMESTIMATE trt*machine*time 'T1,C-P, G1 vs G2'
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0, 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 / cl joint;
See this note on the difference in difference (DID), particularly the first section and the last section titled "Estimating the difference in difference in models with covariates". As noted the last section, the estimate from the LSMESTIMATE statement (for this model using the identity link) as shown in the first section is an estimate of the DID averaged over the levels of the additional categorical predictor. This is shown in the example below. Note that the first LSMESTIMATE statement (and the ESTIMATE statement) give the estimate of the DID averaged over the C levels. But this might not be advisable if the C*A*B interaction is significant since this means that the DID for A and B changes over the levels of C. The next three LSMESTIMATE statements estimate the separate A*B DIDs in the levels of C and then average them to also get the averaged DID over C. The next LSMESTIMATE statement estimates the difference in the two DIDs between the C levels which is the C*A*B interaction. Finally, the last statement re-estimates the separate DIDs in the C levels and produces a joint test of the hypothesis that they both are zero. Though GENMOD is used for a model not involving repeated measures, the same would apply to your case.
data a;
sd=3;
do c=1,0;
do a=1,0;
do b=1,0;
input mean @@;
do rep=1 to 10;
y=rannor(23425)*sd+mean;
output;
end;
end; end;end;
datalines;
50 70 40 40
60 90 20 40
;
proc genmod plots=none;
class a b c / ref=first;
model y = a|b|c;
estimate "Averaged DID" a*b 1 -1 -1 1;
lsmeans a*b*c;
lsmestimate a*b "Averaged DID" 1 -1 -1 1;
lsmestimate a*b*c "DID c=1" 1 0 -1 0 -1 0 1;
lsmestimate a*b*c "DID c=0" 0 1 0 -1 0 -1 0 1;
lsmestimate a*b*c "Averaged DID" 1 1 -1 -1 -1 -1 1 1 / divisor=2;
lsmestimate a*b*c "c*a*b = c Diff of a*b DIDs" 1 -1 -1 1 -1 1 1 -1 ;
lsmestimate a*b*c "DID c=1" 1 0 -1 0 -1 0 1, "DID c=0" 0 1 0 -1 0 -1 0 1 / joint(label="Test both c DIDs = 0");
run;
See this note on the difference in difference (DID), particularly the first section and the last section titled "Estimating the difference in difference in models with covariates". As noted the last section, the estimate from the LSMESTIMATE statement (for this model using the identity link) as shown in the first section is an estimate of the DID averaged over the levels of the additional categorical predictor. This is shown in the example below. Note that the first LSMESTIMATE statement (and the ESTIMATE statement) give the estimate of the DID averaged over the C levels. But this might not be advisable if the C*A*B interaction is significant since this means that the DID for A and B changes over the levels of C. The next three LSMESTIMATE statements estimate the separate A*B DIDs in the levels of C and then average them to also get the averaged DID over C. The next LSMESTIMATE statement estimates the difference in the two DIDs between the C levels which is the C*A*B interaction. Finally, the last statement re-estimates the separate DIDs in the C levels and produces a joint test of the hypothesis that they both are zero. Though GENMOD is used for a model not involving repeated measures, the same would apply to your case.
data a;
sd=3;
do c=1,0;
do a=1,0;
do b=1,0;
input mean @@;
do rep=1 to 10;
y=rannor(23425)*sd+mean;
output;
end;
end; end;end;
datalines;
50 70 40 40
60 90 20 40
;
proc genmod plots=none;
class a b c / ref=first;
model y = a|b|c;
estimate "Averaged DID" a*b 1 -1 -1 1;
lsmeans a*b*c;
lsmestimate a*b "Averaged DID" 1 -1 -1 1;
lsmestimate a*b*c "DID c=1" 1 0 -1 0 -1 0 1;
lsmestimate a*b*c "DID c=0" 0 1 0 -1 0 -1 0 1;
lsmestimate a*b*c "Averaged DID" 1 1 -1 -1 -1 -1 1 1 / divisor=2;
lsmestimate a*b*c "c*a*b = c Diff of a*b DIDs" 1 -1 -1 1 -1 1 1 -1 ;
lsmestimate a*b*c "DID c=1" 1 0 -1 0 -1 0 1, "DID c=0" 0 1 0 -1 0 -1 0 1 / joint(label="Test both c DIDs = 0");
run;
Perfect, thank you!
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.