Skip to content

Fits a Bayesian time-varying regression on a 'tidyFit' R6 class. The function can be used with regress.

Usage

# S3 method for tvp
.model(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)

  • mod_type

  • niter (number of MCMC iterations)

The function provides a wrapper for shrinkTVP::shrinkTVP. See ?shrinkTVP for more details.

Implementation

An argument index_col can be passed, which allows a custom index to be added to coef(m("tvp")) (e.g. a date index, see Examples).

References

Peter Knaus, Angela Bitto-Nemling, Annalisa Cadonna and Sylvia Frühwirth-Schnatter (2021). Shrinkage in the Time-Varying Parameter Model Framework Using the R Package shrinkTVP. Journal of Statistical Software 100(13), 1--32. doi:10.18637/jss.v100.i13 .

See also

Author

Johann Pfitzinger

Examples

# Load data
data <- tidyfit::Factor_Industry_Returns
data <- dplyr::filter(data, Industry == "HiTec")
data <- dplyr::select(data, -Industry)

# Stand-alone function (using low niter for illustration)
fit <- m("tvp", Return ~ ., data, index_col = "Date", niter = 50)
fit
#> # A tibble: 1 × 5
#>   estimator_fct        `size (MB)` grid_id  model_object settings        
#>   <chr>                      <dbl> <chr>    <list>       <list>          
#> 1 shrinkTVP::shrinkTVP        1.59 #0010000 <tidyFit>    <tibble [1 × 3]>

# Within 'regress' function (using low niter for illustration)
fit <- regress(data, Return ~ ., m("tvp", niter = 50, index_col = "Date"))
tidyr::unnest(coef(fit), model_info)
#> # A tibble: 4,956 × 7
#> # Groups:   model [1]
#>    model term        estimate upper    lower posterior.sd  index
#>    <chr> <chr>          <dbl> <dbl>    <dbl>        <dbl>  <dbl>
#>  1 tvp   (Intercept)    0.375 0.812 -0.0734         0.304 196307
#>  2 tvp   (Intercept)    0.380 0.787 -0.138          0.313 196308
#>  3 tvp   (Intercept)    0.402 0.864 -0.0319         0.309 196309
#>  4 tvp   (Intercept)    0.395 0.857 -0.0920         0.341 196310
#>  5 tvp   (Intercept)    0.395 0.898 -0.0280         0.315 196311
#>  6 tvp   (Intercept)    0.418 0.940 -0.0235         0.310 196312
#>  7 tvp   (Intercept)    0.410 0.889 -0.00979        0.300 196401
#>  8 tvp   (Intercept)    0.409 0.870 -0.00367        0.294 196402
#>  9 tvp   (Intercept)    0.385 0.868 -0.105          0.342 196403
#> 10 tvp   (Intercept)    0.369 0.847 -0.0956         0.345 196404
#> # … with 4,946 more rows