# Canonical Correlation Analysis in R

Psy444: Multivariate Analysis

# Canonical Correlation Analysis

• $$r_{\xi\eta}$$ is the canonical correlation.
• The values associated with the straight arrows are canonical function coefficients. These can be unstandardized or standardized.
• The correlation between each $$x$$ and $$\xi$$ (or each $$y$$ and $$\eta$$) is a canonical structure coefficient (also known as a canonical loading).
• The correlation of each variable with its opposite canonical variate is the canonical cross-loading.

# Canonical Correlation Analysis

• $$\xi_1$$ and $$\eta_1$$ are the first canonical variate pair.
• $$\xi_2$$ and $$\eta_2$$ are the second canonical variate pair.
• $$\xi_3$$ and $$\eta_3$$ are the second canonical variate pair.

## How many pairs?

1. Count the number of variables on the left
2. Count the number of variables on the right.
3. Choose the smaller number.

# Data

How are personality and career interests related?

## Personality

1. Openness to Experience (0)
2. Conscientiousness (C)
3. Extraversion (E)
4. Agreeablness (A)
5. Neuroticism (N)

## Career Interests

1. Realistic
2. Investigative
3. Artistic
4. Social
5. Enterprising
6. Conventional

glimpse(d)
## Observations: 500
## Variables: 55
## $O1 (dbl) 3, 3, 4, 2, 5, 2, 2, 4, 2, 4, 4, 5, 3, 4, 4, 3, 3, 3, ... ##$ O2      (dbl) 4, 4, 4, 3, 3, 2, 2, 4, 2, 5, 3, 4, 3, 3, 4, 3, 3, 3, ...
## $O3 (dbl) 4, 3, 3, 4, 4, 1, 2, 3, 4, 3, 3, 4, 4, 4, 3, 4, 3, 3, ... ##$ O4      (dbl) 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 4, 5, 4, 3, 4, 3, 3, 5, ...
## $O5 (dbl) 4, 3, 5, 4, 3, 2, 3, 2, 1, 4, 2, 4, 4, 4, 3, 3, 2, 5, ... ##$ C1      (dbl) 2, 4, 3, 3, 4, 3, 4, 4, 1, 3, 4, 5, 3, 3, 3, 2, 2, 4, ...
## $C2 (dbl) 2, 3, 3, 2, 2, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 2, 4, 4, ... ##$ C3      (dbl) 4, 4, 3, 4, 3, 4, 5, 3,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2, 3, 4, 2, 4, 2, 4, 3, 2, 4, 3, 3, 2, 4, ... ##$ Conv4   (dbl) 3, 2, 2, 3, 3, 4, 3, 2, 4, 2, 4, 3, 3, 4, 3, 5, 3, 4, ...
## $Conv5 (dbl) 3, 3, 3, 3, 2, 4, 4, 2, 4, 1, 3, 4, 2, 4, 2, 4, 4, 4, ... # Make Composite Scores d <- d %>% rowwise %>% mutate(O = mean(O1:O5), C = mean(C1:C5), E = mean(E1:E5), A = mean(A1:A5), N = mean(N1:N5), Real = mean(Real1:Real5), Invest = mean(Invest1:Invest5), Art = mean(Art1:Art5), Soc = mean(Soc1:Soc5), Ent = mean(Ent1:Ent5), Conv = mean(Conv1:Conv5)) glimpse(d) ## Observations: 500 ## Variables: 66 ##$ O1      (dbl) 3, 3, 4, 2, 5, 2, 2, 4, 2, 4, 4, 5, 3, 4, 4, 3, 3, 3, ...
## $O2 (dbl) 4, 4, 4, 3, 3, 2, 2, 4, 2, 5, 3, 4, 3, 3, 4, 3, 3, 3, ... ##$ O3      (dbl) 4, 3, 3, 4, 4, 1, 2, 3, 4, 3, 3, 4, 4, 4, 3, 4, 3, 3, ...
## $O4 (dbl) 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 4, 5, 4, 3, 4, 3, 3, 5, ... ##$ O5      (dbl) 4, 3, 5, 4, 3, 2, 3, 2, 1, 4, 2, 4, 4, 4, 3, 3, 2, 5, ...
## $C1 (dbl) 2, 4, 3, 3, 4, 3, 4, 4, 1, 3, 4, 5, 3, 3, 3, 2, 2, 4, ... ##$ C2      (dbl) 2, 3, 3, 2, 2, 3, 4, 3, 2, 2, 3, 4, 3, 3, 4, 2, 4, 4, ...
## $C3 (dbl) 4, 4, 3, 4, 3, 4, 5, 3, 1, 3, 4, 4, 3, 3, 5, 3, 3, 3, ... ##$ C4      (dbl) 3, 4, 3, 3, 3, 3, 4, 4, 1, 3, 3, 5, 3, 3, 3, 3, 2, 4, ...
## $C5 (dbl) 2, 4, 2, 3, 3, 4, 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 3, 3, 3, 2, 4, 4, 2, 4, 1, 3, 4, 2, 4, 2, 4, 4, 4, ...
## $O (dbl) 3.5, 3.0, 4.5, 3.0, 4.0, 2.0, 2.5, 3.0, 1.5, 4.0, 3.0,... ##$ C       (dbl) 2.0, 4.0, 2.5, 3.0, 3.5, 3.5, 4.0, 4.0, 1.0, 3.0, 3.5,...
## $E (dbl) 2.5, 3.5, 3.5, 3.5, 4.0, 2.5, 3.0, 1.0, 2.5, 3.0, 3.5,... ##$ A       (dbl) 2.5, 2.0, 3.0, 3.0, 3.0, 3.0, 3.5, 2.5, 2.0, 3.0, 3.0,...
## $N (dbl) 4.0, 2.5, 4.5, 4.5, 3.0, 2.0, 2.5, 5.0, 2.5, 3.0, 2.5,... ##$ Real    (dbl) 3.5, 3.0, 2.0, 4.0, 2.0, 3.0, 3.5, 3.0, 2.0, 3.5, 4.5,...
## $Invest (dbl) 4.5, 3.5, 3.5, 2.0, 5.0, 3.0, 2.5, 4.0, 3.5, 4.0, 3.0,... ##$ Art     (dbl) 2.5, 4.5, 3.5, 3.0, 3.0, 3.5, 4.0, 3.5, 3.0, 3.0, 4.0,...
## $Soc (dbl) 3.5, 3.5, 3.5, 3.0, 5.0, 3.0, 3.5, 2.5, 2.5, 2.5, 3.5,... ##$ Ent     (dbl) 2.5, 4.0, 3.0, 3.0, 4.0, 3.0, 3.0, 2.5, 3.0, 3.0, 3.0,...
## $Conv (dbl) 3.0, 2.5, 3.0, 3.0, 2.0, 3.0, 3.5, 2.0, 3.0, 2.0, 3.5,... # Means tabular((Heading("Openness") * O + Heading("Conscientiousness") * C + Heading("Extraversion") * E + Heading("Agreeableness") * A + Heading("Neuroticism") * N + Heading("Realistic") * Real + Heading("Investigative") * Invest + Heading("Artistic") * Art + Heading("Social") * Soc + Heading("Enterprising") * Ent + Heading("Conscientiousness") * Conv) ~ (Heading("Mean") * mean + Heading("SD") * sd), data = d) %>% pander Mean SD Openness 3.079 0.8848 Conscientiousness 3.005 0.9023 Extraversion 2.987 0.8624 Agreeableness 2.973 0.8742 Neuroticism 3.001 0.9296 Realistic 2.994 0.8470 Investigative 3.017 0.9386 Artistic 3.045 0.8245 Social 2.970 0.8858 Enterprising 2.981 0.8841 Conscientiousness 2.988 0.8794 # Correlations Correlations O C E A N Real Invest Art Soc Ent Conv O 1.00 -0.04 -0.03 -0.01 0.08 -0.22 0.46 0.13 -0.21 0.01 -0.40 C -0.04 1.00 0.01 -0.02 0.01 -0.01 -0.06 0.02 0.00 -0.02 0.04 E -0.03 0.01 1.00 0.01 0.01 -0.16 -0.05 0.02 0.36 0.42 -0.24 A -0.01 -0.02 0.01 1.00 -0.01 -0.02 -0.03 -0.07 0.37 -0.24 0.02 N 0.08 0.01 0.01 -0.01 1.00 -0.13 0.08 0.01 -0.02 0.00 0.02 Real -0.22 -0.01 -0.16 -0.02 -0.13 1.00 -0.13 -0.05 -0.02 -0.16 0.21 Invest 0.46 -0.06 -0.05 -0.03 0.08 -0.13 1.00 0.16 -0.13 0.05 -0.35 Art 0.13 0.02 0.02 -0.07 0.01 -0.05 0.16 1.00 -0.02 0.01 -0.16 Soc -0.21 0.00 0.36 0.37 -0.02 -0.02 -0.13 -0.02 1.00 0.14 -0.04 Ent 0.01 -0.02 0.42 -0.24 0.00 -0.16 0.05 0.01 0.14 1.00 -0.19 Conv -0.40 0.04 -0.24 0.02 0.02 0.21 -0.35 -0.16 -0.04 -0.19 1.00 $\boldsymbol{R = \color{crimson}{R_{yy}^{-1}}\color{mediumorchid}{R_{yx}}\color{mediumslateblue}{R_{xx}^{-1}}\color{mediumorchid}{R_{xy}}}$ # CCA in R RR <- cor(d %>% select(O:Conv)) Rxx <- RR[1:5,1:5] Rxy <- RR[1:5,6:11] Ryx <- RR[6:11,1:5] Ryy <- RR[6:11,6:11] R <- solve(Rxx) %*% Rxy %*% solve(Ryy) %*% Ryx eigR <- eigen(R) eigR$values %>% sqrt
## [1] 0.59918571 0.55666788 0.44743001 0.14183147 0.05395729
stats::cancor(d %>% select(O:N), d %>% select(Real:Conv))
## $cor ## [1] 0.59918571 0.55666788 0.44743001 0.14183147 0.05395729 ## ##$xcoef
##           [,1]          [,2]          [,3]         [,4]          [,5]
## O -0.042365365  0.0175209651  0.0202567473  0.006314563  0.0057077921
## C  0.002090304 -0.0026685496  0.0002552101 -0.008958323  0.0487317453
## E  0.014677456  0.0492558562 -0.0072403103 -0.001525741  0.0014331585
## A  0.021817591 -0.0002448915  0.0462538507  0.002949064  0.0006587467
## N -0.001618015 -0.0006996963  0.0044036849 -0.047231222 -0.0090697465
##
## $ycoef ## [,1] [,2] [,3] [,4] [,5] ## Real 0.0054688028 -0.010253587 -0.013044536 0.0435915609 -0.020523660 ## Invest -0.0232964026 0.001639117 0.020352117 -0.0113800551 -0.034520571 ## Art -0.0039539600 0.001052180 -0.005856128 -0.0028821732 0.034020338 ## Soc 0.0341416046 0.019468822 0.029440269 -0.0006578113 -0.008072264 ## Ent 0.0008303629 0.027996118 -0.039909621 -0.0080325811 -0.016023389 ## Conv 0.0142574231 -0.024797861 -0.009315809 -0.0386895979 -0.018327107 ## [,6] ## Real -0.01881239 ## Invest -0.02032761 ## Art -0.04300802 ## Soc -0.01389816 ## Ent -0.00742458 ## Conv -0.02115815 ## ##$xcenter
##     O     C     E     A     N
## 3.079 3.005 2.987 2.973 3.001
##
## $ycenter ## Real Invest Art Soc Ent Conv ## 2.994 3.017 3.045 2.970 2.981 2.988 # CCA using the candisc package library(candisc) cca <- candisc::cancor(d %>% select(O:N), d %>% select(Real:Conv)) cca %>% summary ## ## Canonical correlation analysis of: ## 5 X variables: O, C, E, A, N ## with 6 Y variables: Real, Invest, Art, Soc, Ent, Conv ## ## CanR CanRSQ Eigen percent cum scree ## 1 0.59919 0.359024 0.56012 43.6607 43.66 ****************************** ## 2 0.55667 0.309879 0.44902 35.0007 78.66 ************************ ## 3 0.44743 0.200194 0.25030 19.5108 98.17 ************* ## 4 0.14183 0.020116 0.02053 1.6002 99.77 * ## 5 0.05396 0.002911 0.00292 0.2276 100.00 ## ## Test of H0: The canonical correlations in the ## current row and all that follow are zero ## ## CanR WilksL F df1 df2 p.value ## 1 0.59919 0.34567 19.8523 30 1958.0 0.000000 ## 2 0.55667 0.53929 16.6388 20 1626.1 0.000000 ## 3 0.44743 0.78144 10.5786 12 1299.4 0.000000 ## 4 0.14183 0.97703 1.9165 6 984.0 0.075272 ## 5 0.05396 0.99709 2 ## ## Raw canonical coefficients ## ## X variables: ## Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 ## O 0.946371 -0.3913887 -0.452501 -0.141057 0.127502 ## C -0.046694 0.0596109 -0.005701 0.200114 1.088585 ## E -0.327870 -1.1002925 0.161736 0.034082 0.032014 ## A -0.487368 0.0054705 -1.033233 -0.065877 0.014715 ## N 0.036144 0.0156300 -0.098371 1.055066 -0.202603 ## ## Y variables: ## Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 ## Real -0.122164 0.229048 0.29139 -0.973762 -0.45846 ## Invest 0.520402 -0.036615 -0.45463 0.254211 -0.77113 ## Art 0.088325 -0.023504 0.13082 0.064383 0.75996 ## Soc -0.762666 -0.434901 -0.65765 0.014694 -0.18032 ## Ent -0.018549 -0.625386 0.89151 0.179434 -0.35794 ## Conv -0.318487 0.553942 0.20810 0.864260 -0.40940 CanCorTable(cca) Canonical Correlation Analysis Variate Canonical $$R$$ Canonical $$R^2$$ Eigenvalues Percent Cumulative Percent 1 0.6 0.36 0.56 43.66 43.66 2 0.56 0.31 0.45 35 78.66 3 0.45 0.2 0.25 19.51 98.17 4 0.14 0.02 0.02 1.6 99.77 5 0.05 0 0 0.23 100 CanCorTestTable(cca) Test of H0: The canonical correlations in the current row and all that follow are zero. Variate Canonical $$R$$ Wilks $$\Lambda$$ $$F$$ $$df_1$$ $$df_2$$ $$p$$ 1 0.6 0.35 19.85 30 1958 <.001 2 0.56 0.54 16.64 20 1626 <.001 3 0.45 0.78 10.58 12 1299 <.001 4 0.14 0.98 1.92 6 984 .08 5 0.05 1 2 cca$coef$X %>% pander Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 O 0.95 -0.39 -0.45 -0.14 0.13 C -0.05 0.06 -0.01 0.2 1.09 E -0.33 -1.1 0.16 0.03 0.03 A -0.49 0.01 -1.03 -0.07 0.01 N 0.04 0.02 -0.1 1.06 -0.2 coef(cca, type = "x", standardize = TRUE) %>% pander Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 O 0.84 -0.35 -0.4 -0.12 0.11 C -0.04 0.05 -0.01 0.18 0.98 E -0.28 -0.95 0.14 0.03 0.03 A -0.43 0 -0.9 -0.06 0.01 N 0.03 0.01 -0.09 0.98 -0.19 cca$coef$Y %>% pander Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 Real -0.12 0.23 0.29 -0.97 -0.46 Invest 0.52 -0.04 -0.45 0.25 -0.77 Art 0.09 -0.02 0.13 0.06 0.76 Soc -0.76 -0.43 -0.66 0.01 -0.18 Ent -0.02 -0.63 0.89 0.18 -0.36 Conv -0.32 0.55 0.21 0.86 -0.41 coef(cca, type = "y", standardize = TRUE) %>% pander Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 Real -0.1 0.19 0.25 -0.82 -0.39 Invest 0.49 -0.03 -0.43 0.24 -0.72 Art 0.07 -0.02 0.11 0.05 0.63 Soc -0.68 -0.39 -0.58 0.01 -0.16 Ent -0.02 -0.55 0.79 0.16 -0.32 Conv -0.28 0.49 0.18 0.76 -0.36 cca$scores$X %>% head ## Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 ## [1,] 0.8716545 0.3241857 0.12690738 0.8080730022 -1.2653006 ## [2,] 0.1666804 -0.4873709 1.16766515 -0.2367484281 1.1766785 ## [3,] 1.2411964 -1.1271398 -0.73251009 1.2957499355 -0.6554353 ## [4,] -0.2017064 -0.5102513 -0.05660839 1.6073918197 -0.3023965 ## [5,] 0.5031669 -1.4454258 -0.28353588 0.0008349319 0.6893096 ## [6,] -0.9339136 0.9721603 0.47723349 -0.8232410167 0.5888861 cca$scores$Y %>% head ## Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 ## [1,] 0.262691970 0.15136827 -1.37294201 -0.21896565 -1.7180624 ## [2,] 0.111441209 -1.18859836 0.43084582 -0.02050890 0.4700094 ## [3,] 0.004585782 -0.49178518 -0.77882673 1.14156575 0.3217535 ## [4,] -0.683174690 0.25043526 0.74932166 -1.22681307 0.2717045 ## [5,] -0.103033996 -2.36663483 -1.82923723 0.82790678 -1.4339415 ## [6,] 0.003553713 -0.02697958 0.06870495 0.03335125 0.3390156 plot(cca, which = 1) plot(cca, which = 2) plot(cca, which = 3) plot(cca, which = 4) plot(cca, which = 5) cor(cbind(cca$scores$X,cca$scores$Y)) %>% pander Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 Xcan1 1 0 0 0 0 0.6 0 0 0 0 Xcan2 0 1 0 0 0 0 0.56 0 0 0 Xcan3 0 0 1 0 0 0 0 0.45 0 0 Xcan4 0 0 0 1 0 0 0 0 0.14 0 Xcan5 0 0 0 0 1 0 0 0 0 0.05 Ycan1 0.6 0 0 0 0 1 0 0 0 0 Ycan2 0 0.56 0 0 0 0 1 0 0 0 Ycan3 0 0 0.45 0 0 0 0 1 0 0 Ycan4 0 0 0 0.14 0 0 0 0 1 0 Ycan5 0 0 0 0 0.05 0 0 0 0 1 cca$structure$X.xscores %>% pander Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 O 0.86 -0.31 -0.4 -0.05 0.06 C -0.06 0.06 0.03 0.19 0.98 E -0.32 -0.94 0.14 0.04 0.03 A -0.44 0 -0.9 -0.07 -0.01 N 0.1 -0.02 -0.11 0.97 -0.17 cca$structure$X.yscores %>% pander Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 O 0.51 -0.17 -0.18 -0.01 0 C -0.04 0.03 0.01 0.03 0.05 E -0.19 -0.52 0.06 0.01 0 A -0.26 0 -0.4 -0.01 0 N 0.06 -0.01 -0.05 0.14 -0.01 cca$structure$Y.yscores %>% pander Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 Real -0.22 0.4 0.22 -0.73 -0.35 Invest 0.7 -0.21 -0.39 0.1 -0.44 Art 0.22 -0.11 0.02 0.01 0.59 Soc -0.73 -0.48 -0.43 -0.02 -0.11 Ent -0.02 -0.73 0.61 0.16 -0.24 Conv -0.45 0.66 0.24 0.46 -0.22 cca$structure$Y.xscores %>% pander Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 Real -0.13 0.22 0.1 -0.1 -0.02 Invest 0.42 -0.12 -0.18 0.01 -0.02 Art 0.13 -0.06 0.01 0 0.03 Soc -0.44 -0.27 -0.19 0 -0.01 Ent -0.01 -0.41 0.27 0.02 -0.01 Conv -0.27 0.37 0.11 0.07 -0.01 # Interpreting CCA PersonalityNames <- c("Openness", "Conscientiousness", "Extraversion", "Agreeableness", "Neuroticism") InterestNames <- c("Realistic", "Investigative", "Artistic", "Social", "Enterprising", "Conventional") CanCorCoefTable(cca, type = "standardized", xNames = PersonalityNames, yNames = InterestNames, xSet = "Personality", ySet = "Interests") Standardized Canonical Function Coefficients CV1 CV2 CV3 CV4 CV5 Personality Openness 0.84 -0.35 -0.40 -0.12 0.11 Conscientiousness -0.04 0.05 -0.01 0.18 0.98 Extraversion -0.28 -0.95 0.14 0.03 0.03 Agreeableness -0.43 0.00 -0.90 -0.06 0.01 Neuroticism 0.03 0.01 -0.09 0.98 -0.19 Interests Realistic -0.10 0.19 0.25 -0.82 -0.39 Investigative 0.49 -0.03 -0.43 0.24 -0.72 Artistic 0.07 -0.02 0.11 0.05 0.63 Social -0.68 -0.39 -0.58 0.01 -0.16 Enterprising -0.02 -0.55 0.79 0.16 -0.32 Conventional -0.28 0.49 0.18 0.76 -0.36 CanCorCoefTable(cca, type = "structure", xNames = PersonalityNames, yNames = InterestNames, xSet = "Personality", ySet = "Interests") Canonical Structure Coefficients CV1 CV2 CV3 CV4 CV5 Personality Openness 0.86 -0.31 -0.40 -0.05 0.06 Conscientiousness -0.06 0.06 0.03 0.19 0.98 Extraversion -0.32 -0.94 0.14 0.04 0.03 Agreeableness -0.44 -0.00 -0.90 -0.07 -0.01 Neuroticism 0.10 -0.02 -0.11 0.97 -0.17 Interests Realistic -0.22 0.40 0.22 -0.73 -0.35 Investigative 0.70 -0.21 -0.39 0.10 -0.44 Artistic 0.22 -0.11 0.02 0.01 0.59 Social -0.73 -0.48 -0.43 -0.02 -0.11 Enterprising -0.02 -0.73 0.61 0.16 -0.24 Conventional -0.45 0.66 0.24 0.46 -0.22 heplot(cca) ## Vector scale factor set to 5 heplot(cca, which = c(1,3)) ## Vector scale factor set to 5 heplot(cca, which = c(2,3))  ## Vector scale factor set to 5 # Redundancy Analysis Proportion of variance in X explained by Y and vice-versa redundancy(cca) ## ## Redundancies for the X variables & total X canonical redundancy ## ## Xcan1 Xcan2 Xcan3 Xcan4 Xcan5 total X|Y ## 0.0747962 0.0606826 0.0399535 0.0039899 0.0005762 0.1799984 ## ## Redundancies for the Y variables & total Y canonical redundancy ## ## Ycan1 Ycan2 Ycan3 Ycan4 Ycan5 total Y|X ## 0.0790428 0.0734242 0.0273120 0.0026057 0.0003814 0.1827662 # Multivariate Multiple Regression mxy <- lm(cbind(Real, Invest, Art, Soc, Ent, Conv) ~ O + C + E + A + N, d) mxy %>% manovaTable MANOVA Table Factor df Pillai’s Trace $$F$$ $$df_1$$ $$df_2$$ $$p$$ O 1 0.33 40.4 6 489 <.001 C 1 0.01 0.43 6 489 .86 E 1 0.31 36.99 6 489 <.001 A 1 0.23 24.9 6 489 <.001 N 1 0.02 1.83 6 489 .09 mxy %>% manovaUnivariateTable Univariate Analyses Outcome Predictor $$b$$ $$\sigma_b$$ $$t$$ $$p$$ Real Intercept 4.53 0.28 16.26 <.001 O -0.2 0.04 -4.95 <.001 C -0.02 0.04 -0.47 .64 E -0.16 0.04 -3.76 <.001 A -0.03 0.04 -0.63 .53 N -0.1 0.04 -2.49 .01 Invest Intercept 1.7 0.28 5.95 <.001 O 0.48 0.04 11.44 <.001 C -0.05 0.04 -1.11 .27 E -0.03 0.04 -0.8 .42 A -0.02 0.04 -0.54 .59 N 0.05 0.04 1.16 .25 Art Intercept 2.73 0.28 9.74 <.001 O 0.12 0.04 2.89 .004 C 0.02 0.04 0.51 .61 E 0.02 0.04 0.53 .60 A -0.06 0.04 -1.44 .15 N 0 0.04 -0.06 .95 Soc Intercept 1.43 0.25 5.61 <.001 O -0.2 0.04 -5.21 <.001 C 0 0.04 -0.03 .98 E 0.36 0.04 9.32 <.001 A 0.36 0.04 9.52 <.001 N 0 0.04 -0.05 .96 Ent Intercept 2.46 0.26 9.31 <.001 O 0.02 0.04 0.47 .64 C -0.03 0.04 -0.8 .42 E 0.44 0.04 10.93 <.001 A -0.25 0.04 -6.28 <.001 N -0.01 0.04 -0.17 .86 Conv Intercept 4.73 0.27 17.78 <.001 O -0.41 0.04 -10.26 <.001 C 0.03 0.04 0.78 .44 E -0.26 0.04 -6.49 <.001 A 0.02 0.04 0.42 .68 N 0.05 0.04 1.34 .18 library(lm.beta) lm.beta(mxy) %$% standardized.coefficients %>% pander
Real Invest Art Soc Ent Conv
(Intercept) 0 0 0 0 0 0
O -0.19 0.46 0.11 -0.19 0.02 -0.38
C -0.02 -0.05 0.02 0 -0.03 0.03
E -0.15 -0.03 0.02 0.35 0.43 -0.26
A -0.03 -0.02 -0.06 0.36 -0.25 0.02
N -0.1 0.05 0 0 -0.01 0.05
pairs(mxy)