沉闷科学的掘墓人分享 http://blog.sciencenet.cn/u/Bearjazz

博文

使用R语言进行两组数据显著性t检验(入门级)

已有 46204 次阅读 2011-12-28 10:17 |个人分类:我的研究|系统分类:科研笔记| R语言, t检验, 显著性, 入门级

使用R语言进行两组数据显著性t检验(入门级)

 

熊荣川

六盘水师范学院

xiongrongchuan@126.com

 

实例一 两组数据显著性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)

清空statured的原值

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.test(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

显著

 



https://blog.sciencenet.cn/blog-508298-522860.html

上一篇:使用phyloxml修饰系统发育树
下一篇:使用R语言检验样本平均值是否有别于某一水平
收藏 IP: 210.75.236.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (3 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-13 10:03

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部