|||
使用R语言进行两组数据显著性t检验(入门级)
熊荣川
六盘水师范学院
实例一 两组数据显著性t检验 (随机赋值模拟)
|
输入 |
注释 |
> |
expend <- c(rnorm(10)) |
随机产生10个正态分布的数据 |
> |
stature<- c("obese","lean","obese","lean","obese","lean","obese","lean","obese","lean") |
|
> |
d <- data.frame(expend,stature) |
数据框赋值 |
> |
t.test(expend~stature) |
T检验 |
结果 |
Welch Two Sample t-test
data: expend by stature t = -9e-04, df = 7.985, p-value = 0.9993 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -1.204426 1.203442 sample estimates: mean in group lean mean in group obese 0.04850100 0.04899317 |
不显著 因为我们是交替给两组数据赋值,当然不显著 |
实例二 两组数据显著性t检验 (区间赋值模拟)
|
输入 |
注释 |
> |
rm(stature, d) |
清空stature和d的原值 |
> |
stature<- c("lean","lean","lean","lean","lean","obese","obese","obese","obese","obese") |
为stature进行区间赋值 |
> |
d <- data.frame(expend,stature) |
数据框赋值 |
> |
t.test(expend~stature) |
T检验 |
结果 |
Welch Two Sample t-test
data: expend by stature t = -1.4237, df = 5.974, p-value = 0.2046 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -1.8056111 0.4781883 sample estimates: mean in group lean mean in group obese -0.2831086 0.3806028 |
不显著 区间赋值属于有规律的赋值,显著性提高 |
实例三 实际导入数据显著性t检验
|
输入 |
|
> |
data<-read.csv("D:\ziliao\zhuanye\R bear\vocal cords.csv") |
读入表格 |
> |
grah <- data[,1] |
第一列值赋给grah |
> |
torm <- data[,2] |
第二列值赋给torm |
> |
d <- data.frame(grah, torm) |
数据框赋值 |
> |
T检验 | |
结果 |
Welch Two Sample t-test
data: grah and torm t = 6.4396, df = 11.45, p-value = 3.995e-05 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 67.89471 137.89651 sample estimates: mean of x mean of y 174.93756 72.04194 |
显著 |
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-8-17 05:15
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社