R語言典型相關(guān)分析(Canonical Correlation analysis, CCA)的一些參考資料

典型相關(guān)分析(Canonical Correlation analysis, CCA)是研究兩組變量之間相關(guān)關(guān)系的一種統(tǒng)計方法。如果每組變量中只包含一個變量,相關(guān)關(guān)系可以用相關(guān)系數(shù)來度量。但是每組變量中變量個數(shù)大于1時,比如A組溫度和濕度兩個變量,B組樹高胸徑兩個變量,度量這兩組變量之間的相關(guān)關(guān)系,可以利用主成分的思想,把兩組變量的相關(guān)關(guān)系分別轉(zhuǎn)化成兩個綜合變量的最大可能的相關(guān)關(guān)系,就是典型相關(guān)分析(CCA)。
——摘自《應(yīng)用統(tǒng)計分析與R語言實戰(zhàn)》

例子和R語言實現(xiàn)

第一個小實例:《應(yīng)用統(tǒng)計分析與R語言實戰(zhàn)》第八章第6小節(jié)例題

  • 目的:研究兒童形態(tài)與肺通氣功能的關(guān)系
    數(shù)據(jù)
健康兒童形態(tài) 肺通氣功能
身高 x1 (cm) 肺活量 y1 (L)
體重 x2 (kg) 靜息通氣 y2 (L)
胸圍 x3 (cm) 每分鐘最大通氣量 y3 (L)
  • 代碼
df<-read.table("clipboard",header=T)
df
ndat<-scale(df)
A<-ndat[,1:3]
B<-ndat[,4:6]
res.ca<-cancor(A,B,xcenter=FALSE,ycenter = FALSE)
res.ca

第二個小實例

  • 原文地址
    https://stats.idre.ucla.edu/r/dae/canonical-correlation-analysis/
  • 數(shù)據(jù)集
    600個大學(xué)新生(college freshman),四個學(xué)術(shù)變量(academic variables): Read; Write; math; Science。性別。3個心理變量(psychological variables): locus_of_Control;self_ Concept; Motivation。(這三個變量具體是什么含義我不太明白,有時間可以多看看心理學(xué)方面的書)

研究人員感興趣的是(Researchers are intersted in)心理變量和學(xué)術(shù)變量還有性別之間的關(guān)系是怎樣的?特別的(In particular)。研究人員感興趣的是需要多少維度(how many dimensions (canonical variables))來理解兩組變量之間的關(guān)系

  • 安裝需要用到的包并加載
install.packages("GGally")
install.packages("CCA")
library(ggplot2)
library(GGally)
library(CCA)
  • 讀入數(shù)據(jù)
mm<-read.csv("https://stats.idre.ucla.edu/stat/data/mmreg.csv")
head(mm)
colnames(mm)<-c("Control","Concept","Motivation","Read","Write","Math","Science","Gender")
summary(mm)
xtabs(~Gender,data=mm)
#輸出結(jié)果
Gender
  0   1 
273 327 
#
psych<-mm[,1:3]
acad<-mm[,4:8]
  • 查看兩組變量內(nèi)和組間的相關(guān)性,使用到的是CCA包中的matcor函數(shù)(we will look at the correlations within and between the two sets of variables using the matcor function from the CCA package.)
library(CCA)
matcor(psych,acad)
#輸出結(jié)果
$Xcor
             Control   Concept Motivation
Control    1.0000000 0.1711878  0.2451323
Concept    0.1711878 1.0000000  0.2885707
Motivation 0.2451323 0.2885707  1.0000000

$Ycor
               Read     Write       Math    Science      Gender
Read     1.00000000 0.6285909  0.6792757  0.6906929 -0.04174278
Write    0.62859089 1.0000000  0.6326664  0.5691498  0.24433183
Math     0.67927568 0.6326664  1.0000000  0.6495261 -0.04821830
Science  0.69069291 0.5691498  0.6495261  1.0000000 -0.13818587
Gender  -0.04174278 0.2443318 -0.0482183 -0.1381859  1.00000000

$XYcor
             Control     Concept Motivation        Read      Write
Control    1.0000000  0.17118778 0.24513227  0.37356505 0.35887684
Concept    0.1711878  1.00000000 0.28857075  0.06065584 0.01944856
Motivation 0.2451323  0.28857075 1.00000000  0.21060992 0.25424818
Read       0.3735650  0.06065584 0.21060992  1.00000000 0.62859089
Write      0.3588768  0.01944856 0.25424818  0.62859089 1.00000000
Math       0.3372690  0.05359770 0.19501347  0.67927568 0.63266640
Science    0.3246269  0.06982633 0.11566948  0.69069291 0.56914983
Gender     0.1134108 -0.12595132 0.09810277 -0.04174278 0.24433183
                 Math     Science      Gender
Control     0.3372690  0.32462694  0.11341075
Concept     0.0535977  0.06982633 -0.12595132
Motivation  0.1950135  0.11566948  0.09810277
Read        0.6792757  0.69069291 -0.04174278
Write       0.6326664  0.56914983  0.24433183
Math        1.0000000  0.64952612 -0.04821830
Science     0.6495261  1.00000000 -0.13818587
Gender     -0.0482183 -0.13818587  1.00000000

小實例二

http://my.ilstu.edu/~wjschne/444/CanonicalCorrelation.html#(1)

小實例三

http://ecology.msu.montana.edu/labdsv/R/labs/lab12/lab12.html#cats

小實例四

http://www.sthda.com/english/articles/31-principal-component-methods-in-r-practical-guide/113-ca-correspondence-analysis-in-r-essentials/

小實例五

http://userweb.eng.gla.ac.uk/umer.ijaz/bioinformatics/ecological.html
好長的R代碼,必須要重復(fù)這篇

參考文獻

歡迎大家關(guān)注我的公眾號
小明的數(shù)據(jù)分析筆記本

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容