This book is in Open Review. I want your feedback to make the book better for you and other readers. To add your annotation, select some text and then click the on the pop-up menu. To see the annotations of others, click the button in the upper right hand corner of the page

9.4 Mixed scales

Finally, when we have two variables measured in different scales, the general recommendation is to use the measure of association for the lower scale. For example, if we have the nominal variable colour and the ordinal variable size (both related to T-shirts people prefer), we should use Cramer’s V in order to measure the relation between them:

cramer(colour,size)
## Cramer's V: 0.1632
## Chi^2 statistics = 5.7241, df: 4, p-value: 0.2207

Similarly, if we have a numerical and ordinal variables, we should use one of the measures for ordinal scales.

However, in some cases we might be able to use a different measure of association. One of those is called multiple correlation coefficient and can be calculated for variables in numerical vs categorical scales. This coefficient can be calculated using different principles, the simplest of which is constructing a regression model (discussed later in Section 11) of numerical variable from the dummy variables (see Section 13) created from the categorical one and then extracting the square root of coefficient of determination (discussed in Section 10.4). The resulting coefficient lies between 0 and 1, where 1 implies perfect linear relation between the two variables and 0 implies no linear relation between them. mcor() function from greybox implements this:

mcor(mtcars$am, mtcars$mpg)
## Multiple correlations value: 0.5998
## F-statistics = 16.8603, df: 1, df resid: 30, p-value: 3e-04

Based on the value above, we can conclude that the type of transmission has a linear relation with the mileage. This aligns with what we have already discovered earlier, in preliminary analysis section (Section 5.2) in Figure 5.15.

Finally, there is a function assoc() (aka association()) in greybox package, which will automatically select the necessary measure of association based on the type of a variable and produce three matrices: 1. measures of association, 2. p-values for testing H\(_0\) that there measure is equal to zero, 3. names of functions used for each pair. Here how it works for the mtcarsData example:

assoc(mtcarsData)
## 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"