協方差分析是方差分析、回歸分析和協方差的結合體。
我覺得這種分析思想非常實用,尤其是對confounder雲集的生物學數據。
回顧:
什么是協方差?co-vary
協方差和相關性?standardize
協方差分析最經典的一個例子就是GWAS中移除SNP中的人種因素。
If you are worried about leaving out covariates you could regress out them first and analyse the residuals against the Snps.
在實驗設計中,協變量是獨立變量,實驗者不能操縱,但仍影響實驗結果。
我想知道溫度對於降水量的影響,但是海拔高度、經緯度、當地濕度等變量也會影響降水量。那么,在我的研究中,溫度就是自變量,降水量是應變量,而海拔高度、經緯度和當地濕度就是協變量。
> input <- mtcars[,c("am","mpg","hp")] > print(head(input)) am mpg hp Mazda RX4 1 21.0 110 Mazda RX4 Wag 1 21.0 110 Datsun 710 1 22.8 93 Hornet 4 Drive 0 21.4 110 Hornet Sportabout 0 18.7 175 Valiant 0 18.1 105 > # Get the dataset. > input <- mtcars > # Create the regression model. > result <- aov(mpg~hp*am,data = input) > print(summary(result)) Df Sum Sq Mean Sq F value Pr(>F) hp 1 678.4 678.4 77.391 1.50e-09 *** am 1 202.2 202.2 23.072 4.75e-05 *** hp:am 1 0.0 0.0 0.001 0.981 Residuals 28 245.4 8.8 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > # Get the dataset. > input <- mtcars > # Create the regression model. > result <- aov(mpg~hp+am,data = input) > print(summary(result)) Df Sum Sq Mean Sq F value Pr(>F) hp 1 678.4 678.4 80.15 7.63e-10 *** am 1 202.2 202.2 23.89 3.46e-05 *** Residuals 29 245.4 8.5 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > # Get the dataset. > input <- mtcars > # Create the regression models. > result1 <- aov(mpg~hp*am,data = input) > result2 <- aov(mpg~hp+am,data = input) > # Compare the two models. > print(anova(result1,result2)) Analysis of Variance Table Model 1: mpg ~ hp * am Model 2: mpg ~ hp + am Res.Df RSS Df Sum of Sq F Pr(>F) 1 28 245.43 2 29 245.44 -1 -0.0052515 6e-04 0.9806
參考:
Analysis of Covariance (ANCOVA) easily explained
Analysis of Covariance (ANCOVA) with Two Groups