BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jabbawonga
Calcite | Level 5

Hello.  I'm using a very simple data set from an article in trying to further my understanding of GLMs. I've input the data using SAS, and I've run both the PROC REG and PROC GENMOD procedures on the data. In the PROC GENMOD procedure, I used a log link with a normal distribution; in the PROC REG procedure, I used the log of the response variable in the model.

My question is, why don't the parameter estimates of the two procedures match? My understanding is that PROC REG uses OLS/WLS to estimate the parameters, whereas PROC GENMOD uses MLE with a Newton-Raphson iterative process for estimation. But I had thought that, when the assumed distribution is normal and the relationship is linear (which, after the log transformation, it is in the GLM, right?), MLE is equal to OLS/WLS.

Here are the resulting parameters from the run:

    REG     GENMOD

A1   4.623    4.579

A2   4.688    4.730

A3   4.654    4.654

B1   (0.735)    (0.741)

B2   (0.487)    (0.436)

And here is my code:

data GLM;
input Y A1 A2 A3 B1 B2;
lnY = LOG(Y);
datalines;
95 1 0 0 0 0
115 0 1 0 0 0
105 0 0 1 0 0
55 1 0 0 1 0
45 0 1 0 1 0
30 1 0 0 1 1
;

proc genmod data=GLM;
model Y = A1 A2 A3 B1 B2 / dist=normal link=log scale=deviance noint ;
weight Y;
run;

proc reg data=GLM;
model lnY = A1 A2 A3 B1 B2 / noint;
weight Y;
run;

As it turns out, if I run GENMOD with an identity link function and run REG using Y instead of LnY, I get the same answer.  So, for some reason the transformation from Y to LnY is causing the discrepancy, but mathematically I feel like the answers should still be equal.

Any insight that anyone can contribute is greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ

A model on Y in GENMOD with LINK=LOG is not the same thing as a model on ln(Y) in REG. The former assumes Y is distributed as normal and models g(E(Y))=ln(E(Y)).  The latter assumes ln(Y) is distributed as normal (Y is lognormal) and models E(ln(Y)).  Generally, ln(E(Y)) is not the same as E(ln(Y)).

View solution in original post

7 REPLIES 7
SteveDenham
Jade | Level 19

It appears that the difference lies in the WEIGHT statement.  If you remove it, the estimates are identical.  The definitions are slightly different according to the documentation--in GENMOD, observations are weighted by dispersion parameter/weight variable, in REG, they are relative weights.

Steve Denham

Jabbawonga
Calcite | Level 5

Thanks for the reply Steve.  If I run the code instead using an identity link function and don't log-transform the response in the REG procedure, I get the same answer whether I use weights or not.  If I use a log link in GENMOD and log-transform the response in REG I don't get the same answer, whether I use weights or not.  So I had concluded that weights weren't the issue.

Did you run the code with a log transform without weights and get the same answer?

Actually, technically speaking, REG uses OLS and GENMOD uses MLE, which uses iteratively reweighted LS to estimate, so perhaps only the first iteration in GENMOD would match the REG answer...?

SteveDenham
Jade | Level 19

Yes, I just commented out the weight statement, and the results, for this sample dataset, were the same.  Also, I ran with and without the noint option.

To see if the first GENMOD iteration matches REG, you could specify the ITPRINT option in the model statement.

Steve Denham

Jabbawonga
Calcite | Level 5

Ok, I'm confused now.  Here's the exact code I'm running:

data GLM;

input Y A1 A2 A3 B1 B2;

lnY = LOG(Y);

datalines;

95 1 0 0 0 0

115 0 1 0 0 0

105 0 0 1 0 0

55 1 0 0 1 0

45 0 1 0 1 0

30 1 0 0 1 1

;

run;

proc genmod data=GLM;

model Y = A1 A2 A3 B1 B2 / dist=normal link=log noint;

/* weight Y; */

run;

proc reg data=GLM;

model lnY = A1 A2 A3 B1 B2 / noint ;

/*weight Y; */

run;

But I'm getting different answers.  What am I doing wrong?

StatDave
SAS Super FREQ

A model on Y in GENMOD with LINK=LOG is not the same thing as a model on ln(Y) in REG. The former assumes Y is distributed as normal and models g(E(Y))=ln(E(Y)).  The latter assumes ln(Y) is distributed as normal (Y is lognormal) and models E(ln(Y)).  Generally, ln(E(Y)) is not the same as E(ln(Y)).

Jabbawonga
Calcite | Level 5

Very helpful, thanks!

SteveDenham
Jade | Level 19

@Jabbawonga:  So do I now.  I must have made some sort of error when I ran things before that I can no longer replicate.

Anyway, StatDave has the right answer.  I was thinking program-wise and not theory-wise.

Steve Denham

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 3685 views
  • 0 likes
  • 3 in conversation