R-独立性检验实例
数据:gwas.csv文件(两列表现型和基因型的表格,包含标题)
问题描述:
- 读入gwas.csv数据,得到phenotype与genotype的列联表后,进行分析不同表现型的基因型是否一致。
- 基因型分为AA,Aa和aa 3种。
代码实现:
data = read.csv("gwas.csv", header = T)
x = table(data)
x
y = x
y[, 2] = x[, 3]+x[, 2] #将a/A和A/a合并为a/A列
y = y[, -3] #去掉A/a列
y
chisq.test(y) #原假设phenotype与genotype相互独立
结果展示:
> x
genotype
phenotype a/a a/A A/a A/A
case 64 24 76 36
control 98 84 0 18
>
> y
genotype
phenotype a/a a/A A/A
case 64 100 36
control 98 84 18
>
> chisq.test(y) #原假设phenotype与genotype相互独立
Pearson's Chi-squared test
data: y
X-squared = 14.527, df = 2, p-value = 0.0007006
结果表明,不同表现型的基因型不一致。