Skip to content

Fits a linear regression with variable selection using a genetic algorithm on a 'tidyFit' R6 class. The function can be used with regress.

Usage

# S3 method for genetic
.fit(self, data = NULL)

Arguments

self

a tidyFit R6 class.

data

a data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).

Value

A fitted tidyFit class model.

Details

Hyperparameters:

None. Cross validation not applicable.

Important method arguments (passed to m)

  • statistic

  • populationSize

  • numGenerations

  • minVariables

  • maxVariables

The function provides a wrapper for gaselect::genAlg. See ?genAlg for more details.

Implementation

Control arguments are passed to gaselect::genAlgControl (the function automatically identifies which arguments are for the control object, and which for gaselect::genAlg).

gaselect::evaluatorLM is used as the evaluator with the relevant arguments automatically identified by the function.

References

Kepplinger D (2023). gaselect: Genetic Algorithm (GA) for Variable Selection from High-Dimensional Data. R package version 1.0.21, https://CRAN.R-project.org/package=gaselect.

See also

.fit.lm, .fit.bayes and m methods

Author

Johann Pfitzinger

Examples

# Load data
data <- tidyfit::Factor_Industry_Returns

# Stand-alone function
fit <- m("genetic", Return ~ ., data)
fit
#> # A tibble: 1 × 5
#>   estimator_fct    `size (MB)` grid_id  model_object settings        
#>   <chr>                  <dbl> <chr>    <list>       <list>          
#> 1 gaselect::genAlg        1.94 #0010000 <tidyFit>    <tibble [1 × 6]>

# Within 'regress' function
fit <- regress(data, Return ~ ., m("genetic"),
               .mask = c("Date", "Industry"))
coef(fit)
#> # A tibble: 6 × 4
#> # Groups:   model [1]
#>   model   term        estimate model_info      
#>   <chr>   <chr>          <dbl> <list>          
#> 1 genetic (Intercept)  -0.0243 <tibble [1 × 3]>
#> 2 genetic Mkt-RF        0.979  <tibble [1 × 3]>
#> 3 genetic HML           0.0628 <tibble [1 × 3]>
#> 4 genetic RMW           0.156  <tibble [1 × 3]>
#> 5 genetic CMA           0.114  <tibble [1 × 3]>
#> 6 genetic RF            0.997  <tibble [1 × 3]>