Fits a Markov-Switching regression on a 'tidyFit' R6
class. The function can be used with regress
.
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).
Details
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.``
References
Sanchez-Espigares JA, Lopez-Moreno A (2021). MSwM: Fitting Markov Switching Models. R package version 1.5, https://CRAN.R-project.org/package=MSwM.
See also
.model.tvp
and m
methods
Examples
# 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
#> # A tibble: 1 × 5
#> estimator_fct `size (MB)` grid_id model_object settings
#> <chr> <dbl> <chr> <list> <list>
#> 1 MSwM::msmFit 0.102 #0010000 <tidyFit> <tibble [1 × 3]>
# Within 'regress' function
fit <- regress(data, Return ~ HML,
m("mslm", index_col = "Date", k = 2, control = ctr))
tidyr::unnest(coef(fit), model_info)
#> # A tibble: 108 × 9
#> # Groups: model [1]
#> model term estim…¹ index std.e…² Regim…³ Regim…⁴ Regim…⁵ Regim…⁶
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 mslm (Intercep… 2.99 201801 1.15 8.11e-1 0.189 3.96 -1.17
#> 2 mslm (Intercep… 0.639 201802 1.59 3.52e-1 0.648 3.96 -1.17
#> 3 mslm (Intercep… -0.926 201803 1.82 4.70e-2 0.953 3.96 -1.17
#> 4 mslm (Intercep… 1.39 201804 1.46 4.99e-1 0.501 3.96 -1.17
#> 5 mslm (Intercep… 3.04 201805 1.14 8.20e-1 0.180 3.96 -1.17
#> 6 mslm (Intercep… 0.188 201806 1.66 2.64e-1 0.736 3.96 -1.17
#> 7 mslm (Intercep… 2.70 201807 1.21 7.53e-1 0.247 3.96 -1.17
#> 8 mslm (Intercep… 3.21 201808 1.10 8.52e-1 0.148 3.96 -1.17
#> 9 mslm (Intercep… 0.163 201809 1.66 2.59e-1 0.741 3.96 -1.17
#> 10 mslm (Intercep… -1.16 201810 1.86 8.79e-4 0.999 3.96 -1.17
#> # … with 98 more rows, and abbreviated variable names ¹estimate,
#> # ²std.error, ³`Regime 1 Prob`, ⁴`Regime 2 Prob`, ⁵`Regime 1 Beta`,
#> # ⁶`Regime 2 Beta`