R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(qcc)
## Warning: package 'qcc' was built under R version 4.3.3
## Package 'qcc' version 2.7
## Type 'citation("qcc")' for citing this R package in publications.
library(stats)
library(MASS)
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 4.3.3
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.3.3
## corrplot 0.92 loaded
library(greybox)
## Warning: package 'greybox' was built under R version 4.3.3
## Package "greybox", v2.0.0 loaded.

Test test test…why is power point not copying…gotta go visual…

No model - how are the sets of variables related? We’ll restrict to bivariate. We want a single number that measures the strength of the relationship, -1 to 1 or 0 to 1. What do the variables look like?

Seems pretty reasonable. Now, correlation…

If both variables are numeric, we can calculate a correlation. We speak about this generally, bu it strictly refers to a linear relationship. What is the Pearson coefficient of correlation?

Easy to do in R:

data()
mtcars
##                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
## Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
## Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
## Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
## Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
## Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
## Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
## Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
## Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
## Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
## Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
## Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
## Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
## Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
## Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
## Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
## Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
## Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
## AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
## Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
## Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
## Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
## Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
## Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
## Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
## Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
## Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
## Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2
plot(mtcars$mpg,mtcars$wt,xlab="mpg",ylab="weight", main="mpg by weight")

quantify relationship

cor.test(mtcars$mpg,mtcars$wt)
## 
##  Pearson's product-moment correlation
## 
## data:  mtcars$mpg and mtcars$wt
## t = -9.559, df = 30, p-value = 1.294e-10
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.9338264 -0.7440872
## sample estimates:
##        cor 
## -0.8676594

We can also do a hypothesis test: H0: rho = 0, H1: rho != 0

qt(0.025, 30)
## [1] -2.042272

Thing is we can hack the p value by adding more and more data. Usually we know the correlation is not zero. Won’t tell you whether it’s strong relationship or not. That needs a significant amount of experience. You can always get a better p value by adding more data.

Now let’s look at all correlations:

mtcars2<-mtcars[,c(1,3,4,5,6,7)]
mtcars2
##                      mpg  disp  hp drat    wt  qsec
## Mazda RX4           21.0 160.0 110 3.90 2.620 16.46
## Mazda RX4 Wag       21.0 160.0 110 3.90 2.875 17.02
## Datsun 710          22.8 108.0  93 3.85 2.320 18.61
## Hornet 4 Drive      21.4 258.0 110 3.08 3.215 19.44
## Hornet Sportabout   18.7 360.0 175 3.15 3.440 17.02
## Valiant             18.1 225.0 105 2.76 3.460 20.22
## Duster 360          14.3 360.0 245 3.21 3.570 15.84
## Merc 240D           24.4 146.7  62 3.69 3.190 20.00
## Merc 230            22.8 140.8  95 3.92 3.150 22.90
## Merc 280            19.2 167.6 123 3.92 3.440 18.30
## Merc 280C           17.8 167.6 123 3.92 3.440 18.90
## Merc 450SE          16.4 275.8 180 3.07 4.070 17.40
## Merc 450SL          17.3 275.8 180 3.07 3.730 17.60
## Merc 450SLC         15.2 275.8 180 3.07 3.780 18.00
## Cadillac Fleetwood  10.4 472.0 205 2.93 5.250 17.98
## Lincoln Continental 10.4 460.0 215 3.00 5.424 17.82
## Chrysler Imperial   14.7 440.0 230 3.23 5.345 17.42
## Fiat 128            32.4  78.7  66 4.08 2.200 19.47
## Honda Civic         30.4  75.7  52 4.93 1.615 18.52
## Toyota Corolla      33.9  71.1  65 4.22 1.835 19.90
## Toyota Corona       21.5 120.1  97 3.70 2.465 20.01
## Dodge Challenger    15.5 318.0 150 2.76 3.520 16.87
## AMC Javelin         15.2 304.0 150 3.15 3.435 17.30
## Camaro Z28          13.3 350.0 245 3.73 3.840 15.41
## Pontiac Firebird    19.2 400.0 175 3.08 3.845 17.05
## Fiat X1-9           27.3  79.0  66 4.08 1.935 18.90
## Porsche 914-2       26.0 120.3  91 4.43 2.140 16.70
## Lotus Europa        30.4  95.1 113 3.77 1.513 16.90
## Ford Pantera L      15.8 351.0 264 4.22 3.170 14.50
## Ferrari Dino        19.7 145.0 175 3.62 2.770 15.50
## Maserati Bora       15.0 301.0 335 3.54 3.570 14.60
## Volvo 142E          21.4 121.0 109 4.11 2.780 18.60

and what are the correlations?

cor(mtcars2)
##             mpg       disp         hp        drat         wt        qsec
## mpg   1.0000000 -0.8475514 -0.7761684  0.68117191 -0.8676594  0.41868403
## disp -0.8475514  1.0000000  0.7909486 -0.71021393  0.8879799 -0.43369788
## hp   -0.7761684  0.7909486  1.0000000 -0.44875912  0.6587479 -0.70822339
## drat  0.6811719 -0.7102139 -0.4487591  1.00000000 -0.7124406  0.09120476
## wt   -0.8676594  0.8879799  0.6587479 -0.71244065  1.0000000 -0.17471588
## qsec  0.4186840 -0.4336979 -0.7082234  0.09120476 -0.1747159  1.00000000

Let’s get a plot:

library(corrplot)
corrplot::corrplot(cor(mtcars2))

#here, the corrplot::corrplot tells R where to find the library

A little more clear but a little busy. We can get rid of the bubbles, and clean up the plot as below.

library(corrplot)
corrplot::corrplot(cor(mtcars2), type="upper",method="number")

Yeah, that’s a little better.

What about a weak correlation?

plot (mtcars$mpg,mtcars$qsec)

If we wanted additional information about the strength of correlations, we can get the p values. Need new package Hmisc.

#install.packages("Hmisc")
library(Hmisc)
Hmisc::rcorr(as.matrix(mtcars2))
##        mpg  disp    hp  drat    wt  qsec
## mpg   1.00 -0.85 -0.78  0.68 -0.87  0.42
## disp -0.85  1.00  0.79 -0.71  0.89 -0.43
## hp   -0.78  0.79  1.00 -0.45  0.66 -0.71
## drat  0.68 -0.71 -0.45  1.00 -0.71  0.09
## wt   -0.87  0.89  0.66 -0.71  1.00 -0.17
## qsec  0.42 -0.43 -0.71  0.09 -0.17  1.00
## 
## n= 32 
## 
## 
## P
##      mpg    disp   hp     drat   wt     qsec  
## mpg         0.0000 0.0000 0.0000 0.0000 0.0171
## disp 0.0000        0.0000 0.0000 0.0000 0.0131
## hp   0.0000 0.0000        0.0100 0.0000 0.0000
## drat 0.0000 0.0000 0.0100        0.0000 0.6196
## wt   0.0000 0.0000 0.0000 0.0000        0.3389
## qsec 0.0171 0.0131 0.0000 0.6196 0.3389

Moving right along now…

Spearmans looks for a monotonic relationship. Rank the data, get rid of the data, analyze the ranks.

Order x’s and y’s. Then throw out the data.

cor(mtcars$mpg,mtcars$wt,method="spearman")
## [1] -0.886422
cor.test(mtcars$mpg,mtcars$wt,method="spearman")
## Warning in cor.test.default(mtcars$mpg, mtcars$wt, method = "spearman"): Cannot
## compute exact p-value with ties
## 
##  Spearman's rank correlation rho
## 
## data:  mtcars$mpg and mtcars$wt
## S = 10292, p-value = 1.488e-11
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## -0.886422
cor(mtcars2,method="spearman")
##             mpg       disp         hp        drat         wt        qsec
## mpg   1.0000000 -0.9088824 -0.8946646  0.65145546 -0.8864220  0.46693575
## disp -0.9088824  1.0000000  0.8510426 -0.68359210  0.8977064 -0.45978176
## hp   -0.8946646  0.8510426  1.0000000 -0.52012499  0.7746767 -0.66660602
## drat  0.6514555 -0.6835921 -0.5201250  1.00000000 -0.7503904  0.09186863
## wt   -0.8864220  0.8977064  0.7746767 -0.75039041  1.0000000 -0.22540120
## qsec  0.4669358 -0.4597818 -0.6666060  0.09186863 -0.2254012  1.00000000
Hmisc::rcorr(as.matrix(mtcars2), type="spearman")
##        mpg  disp    hp  drat    wt  qsec
## mpg   1.00 -0.91 -0.89  0.65 -0.89  0.47
## disp -0.91  1.00  0.85 -0.68  0.90 -0.46
## hp   -0.89  0.85  1.00 -0.52  0.77 -0.67
## drat  0.65 -0.68 -0.52  1.00 -0.75  0.09
## wt   -0.89  0.90  0.77 -0.75  1.00 -0.23
## qsec  0.47 -0.46 -0.67  0.09 -0.23  1.00
## 
## n= 32 
## 
## 
## P
##      mpg    disp   hp     drat   wt     qsec  
## mpg         0.0000 0.0000 0.0000 0.0000 0.0071
## disp 0.0000        0.0000 0.0000 0.0000 0.0081
## hp   0.0000 0.0000        0.0023 0.0000 0.0000
## drat 0.0000 0.0000 0.0023        0.0000 0.6170
## wt   0.0000 0.0000 0.0000 0.0000        0.2148
## qsec 0.0071 0.0081 0.0000 0.6170 0.2148

Do the graphs:

cor(mtcars$mpg,mtcars$wt,method="spearman")
## [1] -0.886422
corrplot::corrplot(cor(mtcars2,method="spearman"), type="upper",method="number")

In this example, there isn’t a lot of difference between Pearsons and Spearmans.

Another example:

#install.packages(MASS)
library(MASS)
data("Boston")
head(Boston)
##      crim zn indus chas   nox    rm  age    dis rad tax ptratio  black lstat
## 1 0.00632 18  2.31    0 0.538 6.575 65.2 4.0900   1 296    15.3 396.90  4.98
## 2 0.02731  0  7.07    0 0.469 6.421 78.9 4.9671   2 242    17.8 396.90  9.14
## 3 0.02729  0  7.07    0 0.469 7.185 61.1 4.9671   2 242    17.8 392.83  4.03
## 4 0.03237  0  2.18    0 0.458 6.998 45.8 6.0622   3 222    18.7 394.63  2.94
## 5 0.06905  0  2.18    0 0.458 7.147 54.2 6.0622   3 222    18.7 396.90  5.33
## 6 0.02985  0  2.18    0 0.458 6.430 58.7 6.0622   3 222    18.7 394.12  5.21
##   medv
## 1 24.0
## 2 21.6
## 3 34.7
## 4 33.4
## 5 36.2
## 6 28.7
plot(Boston$medv,Boston$lstat,xlab="median home value", ylab="% below poverty")

Curvy…maybe we should try Spearman’s…also lots of spread, non constant variance

cor(Boston$medv,Boston$lstat)
## [1] -0.7376627
cor(Boston$medv,Boston$lstat, method="spearman")
## [1] -0.8529141

Stronger correlation: nonlinear relationship, non-constant variance

Ok, what if we have classification, non-numerical. Let’s look at Cramer’s V:

Cramers V, useful for categorical vs. categorical. Like to have at least 5 observations per cell. An example:

#install.packages("greybox")
library(greybox)
greybox::tableplot(mtcars$am,mtcars$gear) #ignore ordinality of variables

greybox::tableplot(mtcars$am,mtcars$gear)

greybox::cramer(mtcars$am,mtcars$gear)
## Cramer's V: 0.7808
## Chi^2 statistics = 20.9447, df: 2, p-value: 0
greybox::tableplot(mtcars$am,mtcars$vs)

greybox::cramer(mtcars$am,mtcars$vs)
## Cramer's V: 0
## Chi^2 statistics = 0.3475, df: 1, p-value: 0.5555

How about binary by numerical?

plot(mtcars$mpg,mtcars$am)

cor.test(mtcars$mpg,mtcars$am)
## 
##  Pearson's product-moment correlation
## 
## data:  mtcars$mpg and mtcars$am
## t = 4.1061, df = 30, p-value = 0.000285
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3175583 0.7844520
## sample estimates:
##       cor 
## 0.5998324

So, some relationship between these variables. Next association, numerical vs. categorical

Now x is a category and y is a numerical variable. We need a beta for each category, with coefficients 0 (it is not a cat) and 1 (it us a cat). R tells us the strength of the relationship. Back to mtcars:

mtcars
##                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
## Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
## Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
## Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
## Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
## Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
## Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
## Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
## Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
## Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
## Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
## Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
## Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
## Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
## Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
## Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
## Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
## Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
## AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
## Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
## Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
## Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
## Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
## Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
## Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
## Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
## Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
## Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2
greybox::mcor(mtcars$gear,mtcars$mpg)
## Multiple correlations value: 0.6551
## F-statistics = 10.9007, df: 2, df resid: 29, p-value: 3e-04
plot (mtcars$gear,mtcars$mpg)

summary(lm(mpg~factor(gear),data=mtcars))
## 
## Call:
## lm(formula = mpg ~ factor(gear), data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.7333 -3.2333 -0.9067  2.8483  9.3667 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     16.107      1.216  13.250 7.87e-14 ***
## factor(gear)4    8.427      1.823   4.621 7.26e-05 ***
## factor(gear)5    5.273      2.431   2.169   0.0384 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.708 on 29 degrees of freedom
## Multiple R-squared:  0.4292, Adjusted R-squared:  0.3898 
## F-statistic:  10.9 on 2 and 29 DF,  p-value: 0.0002948
#all associations
str(mtcars)
## 'data.frame':    32 obs. of  11 variables:
##  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
##  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
##  $ disp: num  160 160 108 258 360 ...
##  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
##  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
##  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
##  $ qsec: num  16.5 17 18.6 19.4 17 ...
##  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
##  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
##  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
##  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
greybox::assoc(mtcars)
## Associations: 
## values:
##          mpg    cyl    disp      hp    drat      wt    qsec     vs     am
## mpg   1.0000 0.8558 -0.8476 -0.7762  0.6812 -0.8677  0.4187 0.6640 0.5998
## cyl   0.8558 1.0000  0.9152  0.8449  0.7018  0.7826  0.5913 0.7889 0.4643
## disp -0.8476 0.9152  1.0000  0.7909 -0.7102  0.8880 -0.4337 0.7104 0.5912
## hp   -0.7762 0.8449  0.7909  1.0000 -0.4488  0.6587 -0.7082 0.7231 0.2432
## drat  0.6812 0.7018 -0.7102 -0.4488  1.0000 -0.7124  0.0912 0.4403 0.7127
## wt   -0.8677 0.7826  0.8880  0.6587 -0.7124  1.0000 -0.1747 0.5549 0.6925
## qsec  0.4187 0.5913 -0.4337 -0.7082  0.0912 -0.1747  1.0000 0.7445 0.2299
## vs    0.6640 0.7889  0.7104  0.7231  0.4403  0.5549  0.7445 1.0000 0.0000
## am    0.5998 0.4643  0.5912  0.2432  0.7127  0.6925  0.2299 0.0000 1.0000
## gear  0.6551 0.4820  0.7671  0.6638  0.8319  0.6587  0.6334 0.5728 0.7808
## carb  0.6667 0.4847  0.5605  0.7873  0.3344  0.6129  0.6695 0.5733 0.1864
##        gear   carb
## mpg  0.6551 0.6667
## cyl  0.4820 0.4847
## disp 0.7671 0.5605
## hp   0.6638 0.7873
## drat 0.8319 0.3344
## wt   0.6587 0.6129
## qsec 0.6334 0.6695
## vs   0.5728 0.5733
## am   0.7808 0.1864
## gear 1.0000 0.3217
## carb 0.3217 1.0000
## 
## p-values:
##         mpg    cyl   disp     hp   drat     wt   qsec     vs     am   gear
## mpg  0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0171 0.0000 0.0003 0.0003
## cyl  0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0020 0.0000 0.0126 0.0012
## disp 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0131 0.0000 0.0004 0.0000
## hp   0.0000 0.0000 0.0000 0.0000 0.0100 0.0000 0.0000 0.0000 0.1798 0.0002
## drat 0.0000 0.0001 0.0000 0.0100 0.0000 0.0000 0.6196 0.0117 0.0000 0.0000
## wt   0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.3389 0.0010 0.0000 0.0003
## qsec 0.0171 0.0020 0.0131 0.0000 0.6196 0.3389 0.0000 0.0000 0.2057 0.0006
## vs   0.0000 0.0000 0.0000 0.0000 0.0117 0.0010 0.0000 0.0000 0.5555 0.0022
## am   0.0003 0.0126 0.0004 0.1798 0.0000 0.0000 0.2057 0.5555 0.0000 0.0000
## gear 0.0003 0.0012 0.0000 0.0002 0.0000 0.0003 0.0006 0.0022 0.0000 0.0000
## carb 0.0065 0.0066 0.0662 0.0001 0.6607 0.0242 0.0061 0.0090 0.2838 0.0857
##        carb
## mpg  0.0065
## cyl  0.0066
## disp 0.0662
## hp   0.0001
## drat 0.6607
## wt   0.0242
## qsec 0.0061
## vs   0.0090
## am   0.2838
## gear 0.0857
## carb 0.0000
## 
## types:
##      mpg       cyl      disp      hp        drat      wt        qsec     
## mpg  "none"    "mcor"   "pearson" "pearson" "pearson" "pearson" "pearson"
## cyl  "mcor"    "none"   "mcor"    "mcor"    "mcor"    "mcor"    "mcor"   
## disp "pearson" "mcor"   "none"    "pearson" "pearson" "pearson" "pearson"
## hp   "pearson" "mcor"   "pearson" "none"    "pearson" "pearson" "pearson"
## drat "pearson" "mcor"   "pearson" "pearson" "none"    "pearson" "pearson"
## wt   "pearson" "mcor"   "pearson" "pearson" "pearson" "none"    "pearson"
## qsec "pearson" "mcor"   "pearson" "pearson" "pearson" "pearson" "none"   
## vs   "mcor"    "cramer" "mcor"    "mcor"    "mcor"    "mcor"    "mcor"   
## am   "mcor"    "cramer" "mcor"    "mcor"    "mcor"    "mcor"    "mcor"   
## gear "mcor"    "cramer" "mcor"    "mcor"    "mcor"    "mcor"    "mcor"   
## carb "mcor"    "cramer" "mcor"    "mcor"    "mcor"    "mcor"    "mcor"   
##      vs       am       gear     carb    
## mpg  "mcor"   "mcor"   "mcor"   "mcor"  
## cyl  "cramer" "cramer" "cramer" "cramer"
## disp "mcor"   "mcor"   "mcor"   "mcor"  
## hp   "mcor"   "mcor"   "mcor"   "mcor"  
## drat "mcor"   "mcor"   "mcor"   "mcor"  
## wt   "mcor"   "mcor"   "mcor"   "mcor"  
## qsec "mcor"   "mcor"   "mcor"   "mcor"  
## vs   "none"   "cramer" "cramer" "cramer"
## am   "cramer" "none"   "cramer" "cramer"
## gear "cramer" "cramer" "none"   "cramer"
## carb "cramer" "cramer" "cramer" "none"
greybox::spread(mtcars)

Finally….