Skip to content

Calculates Pearson's correlation coefficient on a 'tidyFit' R6 class. The function can be used with regress.

Usage

# S3 method for class 'cor'
.fit(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)

The function provides a wrapper for stats::cor.test. See ?cor.test for more details.

Implementation

Results can be viewed using coef.

See also

.fit.chisq and m methods

Author

Johann Pfitzinger

Examples

# 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
#>   <chr> <chr>     <dbl>     <dbl>    <dbl>     <int>    <dbl>     <dbl>
#> 1 cor   Mkt-RF   0.784     106.   0             7078   0.775    0.793  
#> 2 cor   SMB      0.210      18.1  2.86e-71      7078   0.187    0.232  
#> 3 cor   HML     -0.104      -8.79 1.83e-18      7078  -0.127   -0.0808 
#> 4 cor   RMW     -0.0957     -8.09 7.18e-16      7078  -0.119   -0.0725 
#> 5 cor   CMA     -0.240     -20.8  5.22e-93      7078  -0.261   -0.218  
#> 6 cor   RF      -0.0152     -1.28 2.00e- 1      7078  -0.0385   0.00808
#> # ℹ 2 more variables: method <chr>, alternative <chr>