BookmarkSubscribeRSS Feed
SASHELP84
Calcite | Level 5

Hi,

I am trying to get the marginal difference in mean cost and 95% CI for an exposure with 5 groups using a GLM with log link and gamma distribution and have tried lsmeans, estimate, etc but all the results are off. I also tried %NLEstimate but it did not work for me. 

Any advice?

Thank you!

 


proc genmod data=t0 ;
class expa(ref="1") agegroup(ref='1') female(ref='1') region(ref='1') flag_ad(ref='0') flag_ohter_comb(ref='0')/param=ref;
model total_cost=expa agegroup female region flag_ad flag_ohter_comb/dist=gamma link=log type3;
store p1;
output out=c predicted=pred_c;
run;

 

expa is a categorical variable with 5 levels

 

I am trying to get the exponential transformed cost and 95% CI for expa= 2 vs. 1, 3 vs. 1, 4 vs. 1, 5 vs. 1

 

 

 

/*Test incorrect results*/
proc genmod data=t0 ;
class expa(ref="1") agegroup(ref='1') female(ref='1') region(ref='1') flag_ad(ref='0') flag_ohter_comb(ref='0')/param=ref;
model total_cost=expa agegroup female region flag_ad flag_ohter_comb/dist=gamma link=log type3;
estimate 'expa=1' intercept 1 expa 1 agegroup 1 female 1 region 1 flag_ad 0 flag_ohter_comb 0 / exp;
estimate 'expa=2' intercept 1 expa 2 agegroup 1 female 1 region 1 flag_ad 0 flag_ohter_comb 0 / exp;
estimate 'expa=3' intercept 1 expa 3 agegroup 1 female 1 region 1 flag_ad 0 flag_ohter_comb 0 / exp;
estimate 'expa=4' intercept 1 expa 4 agegroup 1 female 1 region 1 flag_ad 0 flag_ohter_comb 0 / exp;
estimate 'expa=5' intercept 1 expa 5 agegroup 1 female 1 region 1 flag_ad 0 flag_ohter_comb 0 / exp;
lsmestimate expa "2 vs. 1" 2 1 / cl;
lsmestimate expa "3 vs 1" 3 1/ cl;
lsmestimate expa "4 vs 1" 4 1/ cl;
lsmestimate expa "5 vs 1" 5 1/ cl;
run;

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Moved to STAT forum in the hope you'll get an answer there.

SteveDenham
Jade | Level 19

I am almost certain that the coefficients you are supplying are not what you want. 

 

Why not do something like:

 

lsmeans expa/diff=control cl exp;

 

This will construct the differences between each noncontrol level and the control level (which defaults to the first level) and the confidence bounds, followed by exponentiating each of those.

 

For the lsmestimate statements, you need to construct differences rather than the sums of treatment 2 and multiples of treatment 1.  Try

 

lsmestimate expa "2 vs 1" -1 1  0 0 0/ cl exp;
lsmestimate expa "3 vs 1" -1 0 1 0 0/ cl exp;
lsmestimate expa "4 vs 1" -1 0 0 1 0/ cl exp;
lsmestimate expa "5 vs 1" -1 0 0 0 1/ cl exp;

This should give results that are identical to the lsmeans diffs.

 

SteveDenham

 

StatDave
SAS Super FREQ

The NLEstimate macro could certainly work, but since you just want differences of means it would be easier to use the NLMeans macro. 

proc genmod data=t0 ;
  class expa(ref="1") agegroup(ref='1') female(ref='1') region(ref='1') flag_ad(ref='0') flag_ohter_comb(ref='0')/param=ref;
  model total_cost=expa agegroup female region flag_ad flag_ohter_comb/dist=gamma link=log type3;
  store p1;
  run;
proc plm restore=pl;
  lsmeans expa / e ilink diff exp;
  ods output coef=coeffs;
  run;
%NLMeans(instore=pl, coef=coeffs, link=log, title=Difference of EXPA means)

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 1846 views
  • 1 like
  • 4 in conversation