The "adalasso" package implements the adaptive Lasso idea, which uses different
penalties (weights) for different regressors when running a Lasso regression.
Under certain conditions on those weights, the results will have the so-called
Oracle property, as opposed to the standard Lasso approach.

The main reference is:
Hui Zou (2006), The Adaptive Lasso and Its Oracle Properties, 
Journal of the American Statistical Association, 101:476, 1418-1429,
https://doi.org/10.1198/016214506000000735

Concerning the terminology, we call "weights" or "penalty weights" the `wᵢ`
values that show up in the augmented penalty term of the adaptive Lasso:  

```
... + λ ∑ᵢ (wᵢ |βᵢ|)
```
[The same in pseudo-LaTeX: ... + \lambda \sum_i (w_i |\beta_i|).]
If the user doesn't supply those weights, this package estimates them (before
scaling) as the inverse absolute values of a 1st-stage regression.

# adalasso (public function)

## Arguments:

- series	`y`	dependent variable
- list	`X`	regressor list (without constant term)
- bundle	`parms`	containing various options, also for the underlying Lasso routine with gretl's regls (optional, see below)

The bundle passed as the third argument ('parms') primarily serves to pass on
the regular options for the underlying Lasso routine; for details please
consult the documentation for gretl's 'regls' addon (e.g., under Model / Other 
linear models / Regularized Least Squares / click on the Help button, then in
the new window in the last text line there is a link to 'regls.pdf'). If you're
happy with the defaults, then this bundle argument can be omitted.

In addition, there are three specialized choices that you can add to this
bundle:

- `penaltyweights` (matrix): If you know beforehand what the different
  penalties for the regressors should be, you can specify them in this vector.
  Otherwise they will be determined automatically by the routine with the help
  of a 1st-stage regression (see the `stage1estim` option). Note that the
  weights are understood in relative terms and will be internally rescaled.

- `stage1estim` (string): If this is "ols", then a plain OLS regression will be
  performed for the 1st stage. Since the OLS coefficients are (asymptotically)
  unbiased, they would fulfill the requirement for the Oracle property of the
  adaptive Lasso. Obviously, however, it is infeasible for `T<K` (where
  `K = nelem(X)`). Everything else (or omitting this option) triggers a ridge
  regression with automatic shrinkage determination.

- `stdize` (boolean, default `TRUE`): Although this is a regular and not a specialized choice,
  in the adaptive Lasso it has a bit of a special meaning. It would not make
  much sense to first apply the weights and then let the normal Lasso routine
  standardize the transformed regressors, as this would wash out the weighting
  step. Therefore, if `stdize` is active (set to 1 or `TRUE`), then the variables are first standardized and only afterwards are the weights applied. 

What you _cannot_ do in this bundle is to request a ridge regression with the
'ridge' element, or set the 'alpha' element to a non-unity value (which would
normally request an elastic-net estimation). Only a Lasso estimation is 
possible in the main step.


## Returns a bundle with the following elements:

- `weightsource` (string): Describes how the used weights were determined. The 
    term "ridge" signals that they were estimated based on a first-stage ridge
    regression. The alternative is that the user passed her own weights (in the
    input option `penaltyweights`, see above), then the code is "caller". 

- `B` (matrix): This holds the re-transformed coefficients where the scaling
    induced by the penalty weights (and the possible standardization) is
    undone. Apart from the re-scaling this item comes directly from the 
    underlying estimation, with predictors in rows and penalties in columns;
    see regls's documentation for more details. 

- In particular, the standard regls output elements `nzb` (matrix) and `nzX`
    (list) are also present and derived from the re-transformed `B`. They hold 
    only those coefficients and variables that are retained in the "best"
    model. The criterion to choose the "best" model fit is as usual with regls,
    see the regls help for the appropriate switches in the `parms` bundle.   

- `wzb` (matrix/vector with `nelem(X)+1` elements): This item corresponds to `nzb` and stands for the "with zeros beta", i.e. the coefficient vector including those elements that were set to zero. This should make comparisons more convenient. It is just a copy of the relevant column of `B`, but an NA element is added at the top, where otherwise the intercept would be shown.

- Finally, all other output (bundle members) from gretl's regls addon is simply
    passed on by this package and is, therefore, included and available.

Note that an intercept is never estimated in this package; even when the data
are not standardized, they are always demeaned before estimation.

# Changelog:

- January 2026, v0.2: fix a stupid typo bug which prevented the use of ols in the first estimation stage; work around a regls bug with some MPI constellations before gretl 2026a; add the wzb element to the return bundle; turn this help into markdown; require gretl 2023b because of internal syntax update ('empty')
- January 2023, v0.1: first release

## To do:

- add a dedicated GUI interface, plus perhaps a menu attachment to a model window 

- re-calculate and provide the implied intercept at the end
