.fit.mslm | R Documentation |
tidyfit
Fits a Markov-Switching regression on a 'tidyFit' R6
class. The function can be used with regress
.
## S3 method for class 'mslm'
.fit(self, data = NULL)
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). |
Hyperparameters:
None. Cross validation not applicable.
Important method arguments (passed to m
)
k
(the number of regimes)
sw
(logical vector indicating which coefficients switch)
control
(additional fitting parameters)
The function provides a wrapper for MSwM::msmFit
. See ?msmFit
for more details.
Implementation
Note that only the regression method with 'lm' is implemented at this stage.
An argument index_col
can be passed, which allows a custom index to be added to coef(m("mslm"))
(e.g. a date index).
If no sw
argument is passed, all coefficients are permitted to switch between regimes.“
A fitted 'tidyFit' class model.
Johann Pfitzinger
Sanchez-Espigares JA, Lopez-Moreno A (2021). MSwM: Fitting Markov Switching Models. R package version 1.5, https://CRAN.R-project.org/package=MSwM.
.fit.tvp
and m
methods
# Load data
data <- tidyfit::Factor_Industry_Returns
data <- dplyr::filter(data, Industry == "HiTec", Date >= 201801)
data <- dplyr::select(data, -Industry)
ctr <- list(maxiter = 100, parallelization = FALSE)
# Stand-alone function
fit <- m("mslm", Return ~ HML, data, index_col = "Date", k = 2, control = ctr)
fit
# Within 'regress' function
fit <- regress(data, Return ~ HML,
m("mslm", index_col = "Date", k = 2, control = ctr))
tidyr::unnest(coef(fit), model_info)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.