Skip to content

Fits a hierarchical feature regression on a 'tidyFit' R6 class. The function can be used with regress.

Usage

# S3 method for class 'hfr'
.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:

  • kappa (proportional size of regression graph)

Important method arguments (passed to m)

The hierarchical feature regression is estimated using the hfr::cv.hfr function. See ?cv.hfr for more details.

Implementation

Features are standardized by default with coefficients transformed to the original scale.

If no hyperparameter grid is provided (is.null(control$kappa)), the default is seq(0, 1, by = 0.1).

References

Pfitzinger J (2022). hfr: Estimate Hierarchical Feature Regression Models. R package version 0.5.0, https://CRAN.R-project.org/package=hfr.

See also

.fit.plsr and m methods

Author

Johann Pfitzinger

Examples

# Load data
data <- tidyfit::Factor_Industry_Returns

# Stand-alone function
fit <- m("hfr", Return ~ ., data, kappa = 0.5)
fit
#> # A tibble: 1 × 5
#>   estimator_fct `size (MB)` grid_id  model_object settings        
#>   <chr>               <dbl> <chr>    <list>       <list>          
#> 1 hfr::cv.hfr          7.39 #001|001 <tidyFit>    <tibble [1 × 1]>

# Within 'regress' function
fit <- regress(data, Return ~ ., m("hfr", kappa = c(0.1, 0.5)),
               .mask = c("Date", "Industry"))
coef(fit)
#> # A tibble: 14 × 5
#> # Groups:   model [1]
#>    model term        estimate grid_id  model_info      
#>    <chr> <chr>          <dbl> <chr>    <list>          
#>  1 hfr   (Intercept)  0.713   #001|001 <tibble [1 × 1]>
#>  2 hfr   Mkt-RF       0.294   #001|001 <tibble [1 × 1]>
#>  3 hfr   SMB         -0.0195  #001|001 <tibble [1 × 1]>
#>  4 hfr   HML          0.0199  #001|001 <tibble [1 × 1]>
#>  5 hfr   RMW          0.0267  #001|001 <tibble [1 × 1]>
#>  6 hfr   CMA          0.0292  #001|001 <tibble [1 × 1]>
#>  7 hfr   RF           0.220   #001|001 <tibble [1 × 1]>
#>  8 hfr   (Intercept)  0.0190  #001|002 <tibble [1 × 1]>
#>  9 hfr   Mkt-RF       0.977   #001|002 <tibble [1 × 1]>
#> 10 hfr   SMB         -0.00362 #001|002 <tibble [1 × 1]>
#> 11 hfr   HML          0.0820  #001|002 <tibble [1 × 1]>
#> 12 hfr   RMW          0.110   #001|002 <tibble [1 × 1]>
#> 13 hfr   CMA          0.112   #001|002 <tibble [1 × 1]>
#> 14 hfr   RF           0.905   #001|002 <tibble [1 × 1]>