Fits a robust linear regression on a 'tidyFit' R6
class. The function can be used with regress
.
Details
Hyperparameters:
None. Cross validation not applicable.
Important method arguments (passed to m
)
method
(estimation algorithm, e.g. 'M', 'MM')
The function provides a wrapper for MASS::rlm
. See ?rlm
for more details.
Implementation“
An argument vcov.
can be passed in control or to ...
in m
to estimate the model with robust standard errors. vcov.
can be one of "BS", "HAC", "HC" and "OPG" and is passed to the sandwich
package.
References
W. N. Venables and B. D. Ripley (2002).
Modern Applied Statistics with S. 4th ed., Springer, New York.
URL https://www.stats.ox.ac.uk/pub/MASS4/.
Examples
# Load data
data <- tidyfit::Factor_Industry_Returns
fit <- regress(data, Return ~ ., m("robust"), .mask = c("Date", "Industry"))
coef(fit)
#> # A tibble: 7 × 4
#> # Groups: model [1]
#> model term estimate model_info
#> <chr> <chr> <dbl> <list>
#> 1 robust (Intercept) -0.0999 <tibble [1 × 2]>
#> 2 robust Mkt-RF 0.977 <tibble [1 × 2]>
#> 3 robust SMB 0.0283 <tibble [1 × 2]>
#> 4 robust HML 0.0485 <tibble [1 × 2]>
#> 5 robust RMW 0.193 <tibble [1 × 2]>
#> 6 robust CMA 0.119 <tibble [1 × 2]>
#> 7 robust RF 1.07 <tibble [1 × 2]>
# With robust standard errors
fit <- m("robust", Return ~ `Mkt-RF` + HML + SMB, data, vcov. = "HAC")
tidyr::unnest(coef(fit), model_info)
#> # A tibble: 4 × 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 0.380 0.0377 10.1 5.89e-24
#> 2 Mkt-RF 0.951 0.0126 75.2 0
#> 3 HML 0.0971 0.0255 3.81 1.40e- 4
#> 4 SMB -0.0112 0.0196 -0.572 5.67e- 1