tidyfitR/fit.spikeslab.R
dot-fit.spikeslab.RdFits a Bayesian Spike and Slab regression or classification on a 'tidyFit' R6 class. The function can be used with regress and classify.
# S3 method for class 'spikeslab'
.fit(self, data = NULL)A fitted tidyFit class model.
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.
expected.r2
prior.df
expected.model.size
niter
In the case of classification, arguments are passed to BoomSpikeSlab::logit.spike and BoomSpikeSlab::SpikeSlabGlmPrior. Check those functions for details.
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.
Scott SL (2022). BoomSpikeSlab: MCMC for Spike and Slab Regression. R package version 1.2.5, https://CRAN.R-project.org/package=BoomSpikeSlab.
.fit.lasso, .fit.blasso and m methods
# 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 [1 × 1]>
# 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 RF 0.968 <tibble [1 × 4]>
#> 2 spikeslab RMW 0.163 <tibble [1 × 4]>
#> 3 spikeslab Mkt-RF 0.979 <tibble [1 × 4]>
#> 4 spikeslab CMA 0.144 <tibble [1 × 4]>
#> 5 spikeslab HML 0.0249 <tibble [1 × 4]>
#> 6 spikeslab (Intercept) -0.00108 <tibble [1 × 4]>
#> 7 spikeslab SMB 0 <tibble [1 × 4]>