Ang. [Gretl-devel] forward selection procedure and foreach loops
by andreas.rosenblad@ltv.se
cottrell(a)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
16 years, 11 months
Re: Re: [Gretl-devel] remove unsignificant variables
by andreas.rosenblad@ltv.se
cottrell(a)wfu.edu @ INTERNET skrev 2008-01-11 15:56:25 :
> On Fri, 11 Jan 2008, Sven Schreiber wrote:
>
> > Am 11.01.2008 08:49, andreas.rosenblad(a)ltv.se schrieb:
> > > So it is a backward selection precedure. It's great that it has
> been added,
> > > I have missed it. Could you add a forward selection procedure too,
please?
> > > In case you mean specific-to-general instead of > general-to-
> specific, I don't think that's a good idea. Or is it > something
> else that you have in mind?
>
> The procedure that been added recently fits well, I think, as an
> option to the "omit" command.
>
> The procedure to which Andreas alludes (if I understand right) might
> fit as an option to the "add" command. You could perhaps do
> something like this:
>
> list xlist = x1 x2 x3 x4 x5 x6
> ols y const
> add xlist --auto # or add xlist --auto=arg
>
> This would 1. Search xlist for the variable that is the "best"
> single addition to the model on some criterion (lowest p-value,
> greatest impact on AIC, BIC, R^2, whatever?)
>
> 2. If that "best" variable meets some threshold condition, add it
> and go to step 1; if not, stop and report the augmented model.
>
> Is that what you have in mind?
Yes, that's what I had in mind.
Andreas
16 years, 11 months
forward selection procedure and foreach loops
by Allin Cottrell
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
--
Allin Cottrell
Department of Economics
Wake Forest University, NC
16 years, 11 months
freeze (working dir menu)
by Sven Schreiber
Hi,
I just experienced gretl freezing on windows (cpu at 100%) after I
opened a new datafile (via gui) and then trying to select the new menu
item 'working directory'. However, this isn't reproducible (so far),
that's why I haven't filed a formal bug report. But maybe it's useful to
know that the new datafile was in a different directory than what was
the working dir.
-sven
16 years, 11 months
Re: Re: [Gretl-devel] remove unsignificant variables
by andreas.rosenblad@ltv.se
svetosch(a)gmx.net @ INTERNET skrev 2008-01-11 10:37:48 :
> Am 11.01.2008 08:49, andreas.rosenblad(a)ltv.se schrieb:
> > cottrell(a)wfu.edu @ INTERNET skrev 2008-01-10 19:40:46 :
> > >> On Thu, 10 Jan 2008, Ignacio Diaz-Emparanza wrote:
> >>
> >>>> ols y 0 xlist
> >>>> omit --auto
> >>>> That's perfect !!
> >>>> But, what does mean "sequenciallly" here? 1. Find the variable
> >> with the highest p-value (other than
> >> the constant).
> >> 2. Is that p-value greater than (say) 0.1? - If so, drop the
> >> variable, re-estimate the model and
> >> go to step 1.
> >> - If not, stop and report the results, including an F-test
> >> on all the variables omitted.
> > > So it is a backward selection precedure. It's great that it has
> been added,
> > I have missed it. Could you add a forward selection procedure too,
please?
> > In case you mean specific-to-general instead of general-to-
> specific, I don't think that's a good idea.
Why shouldn't it be a good idea?
Andreas
16 years, 11 months
Re: Re: [Gretl-devel] remove unsignificant variables
by andreas.rosenblad@ltv.se
cottrell(a)wfu.edu @ INTERNET skrev 2008-01-10 19:40:46 :
> On Thu, 10 Jan 2008, Ignacio Diaz-Emparanza wrote:
>
> > > ols y 0 xlist
> > > omit --auto
> > > That's perfect !!
> > > But, what does mean "sequenciallly" here? 1. Find the variable
> with the highest p-value (other than
> the constant).
> 2. Is that p-value greater than (say) 0.1? - If so, drop the
> variable, re-estimate the model and
> go to step 1.
> - If not, stop and report the results, including an F-test
> on all the variables omitted.
So it is a backward selection precedure. It's great that it has been added,
I have missed it. Could you add a forward selection procedure too, please?
Best regards,
Andreas
16 years, 11 months
set workdir
by Allin Cottrell
I was asked earlier: now that the gretl working directory is
configurable via the GUI, is/should there be a script means of
setting it?
On the general principle that anything you can do via the GUI, you
ought to be able to do via the command line if at all possible,
the answer is "yes" to the "should" branch of the question, and
now in CVS it's also "yes" to the "is" branch.
However, I'm treating this as a somewhat special "set" variable.
Most such variables are settable within user-defined functions,
but the settings are internal to the function: when the function
exits, the settings revert to what they were at the caller level.
The working directory, though, seems to me a slightly different
thing. I can't see any compelling reason for messing with this
inside functions. So it's configured as settable only at the "top
level" of command execution (console or script).
set workdir /some/path/that/exists
( or, if you must,
set workdir "c:\Some Path\That exists with holes" )
should work now, but not inside a function.
Allin.
16 years, 11 months
obsolete function packages
by Sven Schreiber
Please remove my packages py4gretl_vecm and py4gretl_vecmrestrict from
the server, they are obsoleted by gretl's new native features for VECM
analysis.
The only extra functionality of py4gretl_vecm now is that it can conduct
tests for exclusion of variables from the Gonzalo-Granger common
factors. IMHO that is not terribly important and eventually I may write
a pure gretl function for that (w/o numpy). I also plan to try to port
the remaining py4gretl functions to native gretl script eventually
(meaning when I need to update them anyway).
thanks,
sven
16 years, 11 months
directory structure in CVS
by Allin Cottrell
I've taken a first step in modifying the gretl directory
structure, in CVS and the current Windows snapshot, following the
discussions here a few days back.
I've split the old "userdir", which served both as the repository
for automatically generated files and as the default location for
explicit file input/output on the user's part, into two:
(a) "dotdir": this holds the automatic files. It is not
user-selectable (directories of this sort are rarely if ever
user-configurable). On unix-type systems it is HOME/.gretl, and
on MS Windows it is APPDATA\gretl, where "APPDATA" is a standard
Windows API thing, localized and user-ized. It may expand to
something like
"C:\Documents and Settings\cottrell\Application data"
(b) "workdir": the default path for explicit user file I/O. This
defaults to HOME/gretl on unix, and to PERSONAL\gretl on Windows.
"PERSONAL" is again localized and user-ized. It may expand to
something like
"C:\Documents and Settings\cottrell\My Documents"
Unlike dotdir, this is user-configurable. For previous gretl
installations, it inherits the old "userdir" setting; for new
installs it can be changed under Tools/Preferences, as before.
I considered using just HOME (unix) or PERSONAL (Windows) for the
default workdir (without appending "/gretl"). But gretl writes
some files to this directory without explicit GUI filename
selection (e.g. the eqnprint and tabprint commands, the gnuplot
command in batch mode), and it seemed like bad form to dump stuff
into HOME or PERSONAL directly. If you don't want to use
{HOME,PERSONAL}/gretl for this purpose, change the preference and
blow the unneeded directory away.
A couple of other changes:
(1) The Windows installer no longer prompts for, or creates, a
per-user working directory. This is handled at run-time: the
appropriate "dotdir" and default "workdir" are created for the
current user, if they don't already exist (and if the default
workdir is not contradicted by an existing registry setting).
(2) Since the CWD (current working directory) is pretty much
inscrutable on Windows, we no longer use this as the default
for the "shelldir" variable: this now defaults to the "workdir".
(You can launch GUI program from a Windows console, but I don't
think anyone but me ever does that!)
Since (a) OS X is very much GUI-oriented and (b) gretl from the OS
X dmg starts up inside Gretl.app, which is definitely not a
sensible location for writing anything, I've also arranged for
shelldir to default to workdir on OS X.
On unix, the shelldir still defaults to whatever is the CWD on
startup. This could perhaps be user-configurable (CWD vs.
workdir), but it would be a somewhat arcane item.
As I say, this is a first step. I have not yet done anything
about automatically changing workdir based on the last directory
visited via the file open/save dialog. I'm not sure that's a good
idea, though it's open for discussion.
Allin.
16 years, 12 months