Calculates Pearson's correlation coefficient on a 'tidyFit' R6
class. The function can be used with regress
.
# S3 method for class 'cor'
.fit(self, data = NULL)
A fitted 'tidyFit' class model.
Hyperparameters:
None. Cross validation not applicable.
Important method arguments (passed to m
)
The function provides a wrapper for stats::cor.test
. See ?cor.test
for more details.
Implementation
Results can be viewed using coef
.
.fit.chisq
and m
methods
# Load data
data <- tidyfit::Factor_Industry_Returns
# Stand-alone function
fit <- m("cor", Return ~ `Mkt-RF` + HML + SMB, data)
fit
#> # A tibble: 1 × 5
#> estimator_fct `size (MB)` grid_id model_object settings
#> <chr> <dbl> <chr> <list> <list>
#> 1 stats::cor.test 0.00984 #0010000 <tidyFit> <tibble [1 × 0]>
# Within 'regress' function
fit <- regress(data, Return ~ ., m("cor"), .mask = c("Date", "Industry"))
tidyr::unnest(coef(fit), model_info)
#> # A tibble: 6 × 10
#> # Groups: model [1]
#> model term estimate statistic p.value parameter conf.low conf.high method
#> <chr> <chr> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <chr>
#> 1 cor Mkt-RF 0.784 106. 0 7078 0.775 0.793 Pearson…
#> 2 cor SMB 0.210 18.1 2.86e-71 7078 0.187 0.232 Pearson…
#> 3 cor HML -0.104 -8.79 1.83e-18 7078 -0.127 -0.0808 Pearson…
#> 4 cor RMW -0.0957 -8.09 7.18e-16 7078 -0.119 -0.0725 Pearson…
#> 5 cor CMA -0.240 -20.8 5.22e-93 7078 -0.261 -0.218 Pearson…
#> 6 cor RF -0.0152 -1.28 2.00e- 1 7078 -0.0385 0.00808 Pearson…
#> # ℹ 1 more variable: alternative <chr>