Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Using mlfit


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Using mlfit
Date   Fri, 29 Aug 2003 12:12:36 +0100

Amani Siyam 

> As part of an exploratory analysis, I am running a series 
> of logistic models
> to investigate the best predictor of a binary variable 
> "lbw" using three
> time point measurements (X3,X6 and X12 at ages 3,6 and 12 months,
> respectively) given that all explanatory variables are 
> highly significant.
> 
> xi: logit lbw i.X3 (model 1)
> xi: logit lbw i.X6 (model 2)
> xi: logit lbw i.X12 (model 3)
> 
> I wish to use the command "mlfit" to obtain the AIC and SC 
> criteria (for
> example as seen below from model 1)
> 
> . mlfit
>  Criteria for assessing logistic model fit
>  Akaike's Information Criterion (AIC) and Schwarz's Criterion (SC)
> 
> ------------------------------------------------------------
> ----------------
> --
>  AIC           SC           | -2 Log Likelihood    Num.Parameters
> ----------------------------+-------------------------------
> ----------------
> --
>  9271.8362     9288.2391    |  9267.8362              2
> ------------------------------------------------------------
> ----------------
> --
> 
> The problem is "mlfit" has no options to store the stats 
> above and I wish to
> display all of those in a matrix as snap-shot of the 
> "goodness of fit" of
> each model.

Not a problem. -mlfit- is an user-written command published 
in STB-45. But it leaves behind the globals S_E_aic and 
S_E_sc containing values of the Akaike Information 
and Schwarz criteria. 

Here is a silly analogue for what I think you want. 

sysuse auto 
gen himpg = mpg > 25
gen hiweight = weight > 3000
matrix criteria = J(3,2,.)
matrix rownames criteria = himpg hiweight rep78 
matrix colnames criteria = AIC SC 
local i = 1 
qui foreach v of var himpg hiweight rep78 { 
	xi: logit foreign i.`v'
	mlfit 
      matrix criteria[`i',1] = $S_E_aic
	matrix criteria[`i++',2] = $S_E_sc
}
mat li criteria, format(%3.2f)

Here is the result: 

criteria[3,2]
            AIC     SC
   himpg  90.89  95.50
hiweight  67.58  72.19
   rep78  62.89  71.33

Notes: 

1. 

Incidentally, I thought of doing this using 
my own program -makematrix-, just posted. 
It can be done this way: 

define a do-file, say mydo.do 

xi : logit foreign i.`1'
mlfit 

and then -run- it repeatedly: 

makematrix, from(S_E_aic S_E_sc) format(%3.2f) : 
"run mydo" himpg biweight rep78

However, this was _after_ I fixed a small bug
which Amani's example exposed. I'll ask Kit
to put the fixed version on SSC

2. 

In Stata 8, check out -estimates table-. 

Nick 
[email protected] 
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index