# RE: st: Question regarding linktest and its implementation

 From "Daniel Schneider" To Subject RE: st: Question regarding linktest and its implementation Date Sun, 6 Aug 2006 12:33:01 -0700

```Here is a simple example:

. sysuse auto
(1978 Automobile Data)

/* An arbitrary GLM model with Gamma distribution and inverse link */

. glm price trunk foreign weight,fam(gam)

Iteration 0:   log likelihood = -715.70821
Iteration 1:   log likelihood = -715.62533
Iteration 2:   log likelihood = -715.62504

Generalized linear models                          No. of obs      =
74
Optimization     : ML                              Residual df     =
70
Scale parameter =
.0729733
Deviance         =  4.436463251                    (1/df) Deviance =
.063378
Pearson          =   5.10813316                    (1/df) Pearson  =
.0729733

Variance function: V(u) = u^2                      [Gamma]
Link function    : g(u) = 1/u                      [Reciprocal]

AIC             =
19.44933
Log likelihood   = -715.6250372                    BIC             =
-296.8481

------------------------------------------------------------------------
------
|                 OIM
price |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+----------------------------------------------------------
------
trunk |   1.66e-06   1.65e-06     1.01   0.312    -1.56e-06
4.89e-06
foreign |  -.0001001   .0000136    -7.34   0.000    -.0001268
-.0000734
weight |  -8.86e-08   9.31e-09    -9.51   0.000    -1.07e-07
-7.03e-08
_cons |   .0004541   .0000289    15.72   0.000     .0003974
.0005107
------------------------------------------------------------------------
------

/* these are predictions based on the scale of the dependent variable */

. predict pr1
(option mu assumed; predicted mean price)

/* these are un-re-transformed predictions, this is what linktest uses
*/

. predict pr2,xb

. gen pr1sq=pr1^2

. gen pr2sq=pr2^2

/* Here is the linktest directly */

Iteration 1 : deviance =    5.2028
Iteration 2 : deviance =    4.4811
Iteration 3 : deviance =    4.3783
Iteration 4 : deviance =    4.3760
Iteration 5 : deviance =    4.3760
Iteration 6 : deviance =    4.3760

Residual df  =        71                                No. of obs =
74
Pearson X2   =  5.113241                                Deviance   =
4.375989
Dispersion   =  .0720175                                Dispersion =
.0616336

Gamma distribution, power link (power = -1)
------------------------------------------------------------------------
------
price |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+----------------------------------------------------------
------
_hat |   1.333585   .3680821     3.62   0.000     .6121571
2.055012
_hatsq |  -1117.429   1200.049    -0.93   0.352    -3469.481
1234.624
_cons |  -.0000214   .0000261    -0.82   0.412    -.0000726
.0000298
------------------------------------------------------------------------
------

/* this is the replication of the linktest. Note that the results are
similar but not identical because linktest seems to rely on an older
version of GLM. The difference lies in how the standard errors are
calculated - this difference is not important for most cases, therefore
it is not the point I am making (see below) */

. glm price pr2 pr2sq,fam(gam)

Iteration 0:   log likelihood = -716.00822
Iteration 1:   log likelihood = -715.60755
Iteration 2:   log likelihood = -715.59485
Iteration 3:   log likelihood =  -715.5948

Generalized linear models                          No. of obs      =
74
Optimization     : ML                              Residual df     =
71
Scale parameter =
.0720172
Deviance         =   4.37598887                    (1/df) Deviance =
.0616336
Pearson          =  5.113222128                    (1/df) Pearson  =
.0720172

Variance function: V(u) = u^2                      [Gamma]
Link function    : g(u) = 1/u                      [Reciprocal]

AIC             =
19.42148
Log likelihood   =    -715.5948                    BIC             =
-301.2126

------------------------------------------------------------------------
------
|                 OIM
price |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+----------------------------------------------------------
------
pr2 |   1.333624   .3679106     3.62   0.000     .6125322
2.054715
pr2sq |  -1117.528   1199.493    -0.93   0.352    -3468.491
1233.436
_cons |  -.0000214   .0000261    -0.82   0.412    -.0000726
.0000297
------------------------------------------------------------------------
------

/* the next estimation is identical to the linktest, but based on
different predictions. These predictions are in the same scale as the
dependent variable (that is reused in the linktest). The question is:
what are the correct predictions to use? My understanding would be this
approach, but linktest implements a different one using the
un-re-transformed predictions and then re-applying the link-function to
those to fit them to the observed values. As you can clearly see, the
difference matters for the substantive interpretation (the only case it
does not matter is when an identity-link is used because in that case
pr1==pr2)! */

. glm price pr1 pr1sq,fam(gam)

Iteration 0:   log likelihood = -715.36138
Iteration 1:   log likelihood = -715.26719
Iteration 2:   log likelihood = -715.26676

Generalized linear models                          No. of obs      =
74
Optimization     : ML                              Residual df     =
71
Scale parameter =
.0599273
Deviance         =  3.719899097                    (1/df) Deviance =
.0523929
Pearson          =  4.254836057                    (1/df) Pearson  =
.0599273

Variance function: V(u) = u^2                      [Gamma]
Link function    : g(u) = 1/u                      [Reciprocal]

AIC             =
19.41262
Log likelihood   = -715.2667551                    BIC             =
-301.8687

------------------------------------------------------------------------
------
|                 OIM
price |      Coef.   Std. Err.      z    P>|z|     [95% Conf.
Interval]
-------------+----------------------------------------------------------
------
pr1 |  -6.17e-08   7.46e-09    -8.27   0.000    -7.63e-08
-4.71e-08
pr1sq |   2.42e-12   3.76e-13     6.44   0.000     1.69e-12
3.16e-12
_cons |   .0004557   .0000327    13.92   0.000     .0003916
.0005199
------------------------------------------------------------------------
------

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of
> Richard Williams
> Sent: Sunday, August 06, 2006 8:57 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: Question regarding linktest and its implementation
>
>
> At 07:46 PM 8/5/2006, Daniel Schneider wrote:
> >Does anyone have experience with this? Is it possible that
> the revision
> >of GLM models for the more recent stata version has changed
> some of the
> >meaning of predictions and is not correctly implemented in
> >command that seems to be based on an older Stata version?
>
> Anything is possible.  To see if there is some change though,
> I would suggest
>
> a) running something in both Stata 8.2 (or earlier) and in 9.0, and
> seeing if the results differ, or
>
> b) If you don't have an earlier version of Stata, try using version
> control in 9.0.
>
> If you don't have an earlier version of Stata, if you post a simple
> replicable example (e.g. use auto or other readily available data)
> somebody with an older Stata can try it for you.
>
>
> -------------------------------------------
> Richard Williams, Notre Dame Dept of Sociology
> OFFICE: (574)631-6668, (574)631-6463
> FAX:    (574)288-4373
> HOME:   (574)289-5227
> EMAIL:  Richard.A.Williams.5@ND.Edu
> WWW (personal):    http://www.nd.edu/~rwilliam
> WWW (department):    http://www.nd.edu/~soc
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```