第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > 协方差分析 | ANCOVA (Analysis of Covariance) | R代码

协方差分析 | ANCOVA (Analysis of Covariance) | R代码

时间:2022-12-01 06:40:28

相关推荐

协方差分析 | ANCOVA (Analysis of Covariance) | R代码

协方差分析是方差分析、回归分析和协方差的结合体。

我觉得这种分析思想非常实用,尤其是对confounder云集的生物学数据。

回顾:

什么是协方差?co-vary

协方差和相关性?standardize

协方差分析最经典的一个例子就是GWAS中移除SNP中的人种因素。

If you are worried about leaving out covariates you could regress out them first andanalyse the residuals against the Snps.

在实验设计中,协变量是独立变量,实验者不能操纵,但仍影响实验结果。

我想知道温度对于降水量的影响,但是海拔高度、经纬度、当地湿度等变量也会影响降水量。那么,在我的研究中,温度就是自变量,降水量是应变量,而海拔高度、经纬度和当地湿度就是协变量。

> input <- mtcars[,c("am","mpg","hp")]> print(head(input))am mpg hpMazda RX41 21.0 110Mazda RX4 Wag1 21.0 110Datsun 710 1 22.8 93Hornet 4 Drive0 21.4 110Hornet Sportabout 0 18.7 175Valiant 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.00.0 0.001 0.981 Residuals 28 245.48.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.48.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 TableModel 1: mpg ~ hp * amModel 2: mpg ~ hp + amRes.Df RSS Df Sum of SqF Pr(>F)128 245.43 229 245.44 -1 -0.0052515 6e-04 0.9806

参考:

R - Analysis of Covariance

Analysis of Covariance (ANCOVA) easily explained

Analysis of Covariance (ANCOVA) with Two Groups

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。