Ang. [Gretl-devel] forward selection procedure and foreach loops

andreas.rosenblad at ltv.se andreas.rosenblad at ltv.se
Mon Jan 14 02:37:53 EST 2008


cottrell at wfu.edu @ INTERNET skrev 2008-01-12 20:14:10 :

> I tend to agree with Sven that "forward selection" is not a great
> thing to add.  However, I mentioned that it might be useful for
> pedagogical purposes.  To that end I've written a function that some
> people might like to experiment with.
>
> One gives a base specification for a model, with the unconditionally
> included regressors in list0, along with a list of possible
> additional regressors, list1.  The function searches list1 for the
> regressor, x*, which gives the greatest improvement in the AIC. If
> there is such an x*, it is added to list0 and removed from list1,
> and the search is repeated.  The search stops when no further
> improvement in AIC is possible, or when list1 is exhausted,
> whichever comes first.
>
> Obviously one could modify the function to use a different criterion
> for "improvement" at each step, or make it fancier by adding a
> control parameter to select from a given menu of such criteria (e.g.
> AIC, BIC, HQC, adjusted R^2).
>
> The example below uses Ramanathan's data4-10, and contains a
> caution, namely a demonstration that the model arrived at via this
> algorithm does _not_ in fact offer the "best" AIC that can be
> achieved with the available regressors.  Neither of the variables
> INCOME or COLLEGE individually improves the AIC in relation to the
> model selected by the forward procedure, but jointly they do.
>
> function addlist (series y, list list0, list list1)
>     ols y list0 --quiet
>     aic_min = $aic
>     printf "Baseline        AIC = %g\n", aic_min
>     loop while (nelem(list1) > 0) --quiet
>        string bestx = null
>        # check each remaining additional regressor
>        loop foreach i list1 --quiet
>           ols y list0 $i --quiet
>           aic = $aic
>           if (aic < aic_min)
>       aic_min = aic
>       string bestx = "$i"
>           endif
>        endloop        if isstring(bestx)
>           printf "Adding %-8s AIC = %g\n", @bestx, aic
>           list list0 += @bestx
>           list list1 -= @bestx
>        else
>           break
>        endif
>     endloop     printf "\nMinimized AIC = %g, with this model:\n",
> aic_min     ols y list0
> end function
>
> open data4-10
> list list0 = 0
> list list1 = 2 3 4 5 6 7 8 9
> addlist(ENROLL, list0, list1)
>
> # but compare...
> ols ENROLL 0 CATHOL WHITE INCOME COLLEGE


Could you add this example script to the Gretl User's Guide, please?

Andreas



More information about the Gretl-devel mailing list