Skip to content

Fits a Bayesian Spike and Slab regression or classification on a 'tidyFit' R6 class. The function can be used with regress and classify.

Usage

# S3 method for spikeslab
.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)

In the case of regression, arguments are passed to BoomSpikeSlab::lm.spike and BoomSpikeSlab::SpikeSlabPrior. Check those functions for details.

BoomSpikeSlab::SpikeSlabPrior

  • expected.r2

  • prior.df

  • expected.model.size

BoomSpikeSlab::lm.spike

  • niter

In the case of classification, arguments are passed to BoomSpikeSlab::logit.spike and BoomSpikeSlab::SpikeSlabGlmPrior. Check those functions for details.

BoomSpikeSlab::logit.spike

  • niter

I advise against the use of BoomSpikeSlab::SpikeSlabGlmPrior at the moment, since it appears to be buggy.

The function provides wrappers for BoomSpikeSlab::lm.spike and BoomSpikeSlab::logit.spike. See ?lm.spike and ?logit.spike for more details.

Implementation

Prior arguments are passed to BoomSpikeSlab::SpikeSlabPrior and BoomSpikeSlab::SpikeSlabGlmPrior (the function automatically identifies which arguments are for the prior, and which for BoomSpikeSlab::lm.spike or BoomSpikeSlab::logit.spike).

BoomSpikeSlab::logit.spike is automatically selected when using classify.

References

Scott SL (2022). BoomSpikeSlab: MCMC for Spike and Slab Regression. R package version 1.2.5, https://CRAN.R-project.org/package=BoomSpikeSlab.

See also

.fit.lasso, .fit.blasso and m methods

Author

Johann Pfitzinger

Examples

# Load data
data <- tidyfit::Factor_Industry_Returns

# Stand-alone function
fit <- m("spikeslab", Return ~ ., data, niter = 100)
fit
#> # A tibble: 1 × 5
#>   estimator_fct           `size (MB)` grid_id  model_object settings
#>   <chr>                         <dbl> <chr>    <list>       <list>  
#> 1 BoomSpikeSlab::lm.spike        1.92 #0010000 <tidyFit>    <tibble>

# Within 'regress' function
fit <- regress(data, Return ~ ., m("spikeslab", niter = 100),
               .mask = c("Date", "Industry"))
coef(fit)
#> # A tibble: 7 × 4
#> # Groups:   model [1]
#>   model     term         estimate model_info      
#>   <chr>     <chr>           <dbl> <list>          
#> 1 spikeslab Mkt-RF       0.980    <tibble [1 × 4]>
#> 2 spikeslab RF           0.950    <tibble [1 × 4]>
#> 3 spikeslab RMW          0.160    <tibble [1 × 4]>
#> 4 spikeslab CMA          0.156    <tibble [1 × 4]>
#> 5 spikeslab HML          0.0153   <tibble [1 × 4]>
#> 6 spikeslab SMB         -0.000326 <tibble [1 × 4]>
#> 7 spikeslab (Intercept)  0.00451  <tibble [1 × 4]>