设为首页 加入收藏

TOP

R的两均值比较检验(非参数检验)(二)
2017-10-09 13:35:23 】 浏览:9096
Tags:均值 比较 检验 参数
difference in means is not equal to 0
95 percent confidence interval:
-23.106033 -9.657011
sample estimates:
mean in group jan mean in group aug
5.25000 21.63152

 

 

Exact Two-Sample Fisher-Pitman Permutation Test

data: temp by month (aug, jan)
Z = 4.5426, p-value = 0.0001744
alternative hypothesis: true mu is not equal to 0

 

 

Asymptotic Two-Sample Fisher-Pitman Permutation Test

data: temp by month (aug, jan)
Z = 4.5426, p-value = 5.557e-06
alternative hypothesis: true mu is not equal to 0

 

Approximative Two-Sample Fisher-Pitman Permutation Test

data: temp by month (aug, jan)
Z = 4.5426, p-value < 2.2e-16
alternative hypothesis: true mu is not equal to 0

2.3相关系数置换检验

spearsman_test

对学生成绩,基于数学和物理成绩的spearsman相关系数进行置换检验

ReportCard<-read.table(file="ReportCard.txt",header=TRUE,sep=" ")
Tmp<-ReportCard[complete.cases(ReportCard),]
cor.test(Tmp[,5],Tmp[,7],alternative="two.side",method="spearman")
#是让你的模拟能够可重复出现,因为很多时候我们需要取随机数,但这段代码再跑一次的时候,结果就不一样
#了,如果需要重复出现的模拟结果的话,就可以用set.seed()。在调试程序或者做展示的时候,结果的可重#复性是很重要的. 12345是种子数
set.seed(12345)
spearman_test(math~phy,data=Tmp,distribution=approximate(B=1000))

  

sample estimates:
rho
0.7651233

Approximative Spearman Correlation Test

data: math by phy
Z = 5.7766, p-value < 2.2e-16
alternative hypothesis: true rho is not equal to 0

 

2.4卡方分布置换检验

对于学生的成绩,在性别和平均分等级列联表上,采用置换检验,看性别与平均分两个变量是否是独立的

Tmp<-ReportCard[complete.cases(ReportCard),]
CrossTable<-table(Tmp[,c(2,12)])  #编制性别和平均分等级的列联表
chisq.test(CrossTable,correct=FALSE)
chisq_test(sex~avScore,data=Tmp,distribution="asymptotic")
set.seed(12345)
chisq_test(sex~avScore,data=Tmp,distribution=approximate(B=1000))

 

> CrossTable
avScore
sex B C D E
F 2 13 10 3
M 2 11 12 5

Pearson's Chi-squared test

data: CrossTable
X-squared = 0.78045, df = 3, p-value = 0.8541

Asymptotic Pearson Chi-Squared Test

data: sex by avScore (B, C, D, E)
chi-squared = 0.78045, df = 3, p-value = 0.8541

 

Approximative Pearson Chi-Squared Test

data: sex by avScore (B, C, D, E)
chi-squared = 0.78045, p-value = 0.922

原假设:有关,不应拒绝原假设。

2.5两配对样本置换检验

wilcoxsign_test

ReportCard<-read.table(file="ReportCard.txt",header=TRUE,sep=" ")
ReportCard<-na.omit(ReportCard)
wilcox.test(ReportCard$chi,ReportCard$math,paired=TRUE)
wilcoxsign_test(chi~math,data=ReportCard,distribution="asymptotic")

  

Wilcoxon signed rank test with continuity correction

data: ReportCard$chi and ReportCard$math
V = 1695.5, p-value = 8.021e-11
alternative hypothesis: true location shift is not equal to 0

 

Asymptotic Wilcoxon-Pratt Signed-Rank Test

data: y by x (pos, neg)
stratified by block
Z = 6.5041, p-value = 7.817e-11
alternative hypothesis: true mu is not equal to 0

量结论一致

3.两样本均值差的自举检验

3.1概述

两样本均值的置换检验可以检验出两个总体的均值是否存在显著差异,但对总体均值差的置信区间估计比较困难。置信区间的估计,是以样本均值差的抽样分布已知且对称为前提的,若无法保证这个前提,则可采用自举发进行检验。

3.2.R实现

1.编写用户自定义函数

例如,对两样本均值的自举法检验:分别计算两个样本的均值并返回

DiffMean<-function(DataSet,indices){
 ReSample<-DataSet[indices,]#从Dataset中抽取indices决定的观测形成自举样本
 diff<-tapply(ReSample[,1],INDEX=as.factor(ReSample[,2]),FUN=mean)
#表示以自举样本第2列分组标识,分别计算自举样本第1列的均值。
 return(diff[1]-diff[2])
}
#第一列是待检验变量,第二列为观测来自总体的标识。indices包括了n个元素的随机位置向量,它
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Akka(18): Stream:组合数据流.. 下一篇Akka(19): Stream:组合数据流..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目