This is grnp490.prg from the Greene textbook examples. In order to do the LR test using MAXIMIZE, you need to
(a) be able to estimate both the restricted and unrestricted models
(b) have the maximize function compute either the actual log likelihood (including all constants) or at least compute that up to a common additive constant.
Then 2 x the difference between the %funcval's is the test statistic.
- Code: Select all
*
* Example of testing procedures on page 490
* ?? Restricted estimate is off (doesn't match one from earlier in chapter)
* ?? VB on p 491 is computed at the unrestricted model; the calculation on
* 492 uses the correct VB at the restricted estimates
*
open data tablefd-1[1].txt
data(format=prn,org=columns) 1 20 id y e
*
nonlin b r
compute b=0,r=1
*
frml logl = bi=1/(b+e),r*log(bi)-%lngamma(r)+(r-1)*log(y)-y*bi
*
maximize(method=bfgs) logl
test(title="Wald Test for rho=1")
# 2
# 1.0
compute funcunr=%funcval
*
nonlin b r=1
maximize(method=bfgs) logl
compute funcres=%funcval
cdf(title="Likelihood Ratio Test") chisqr -2*(funcres-funcunr) 1