[关闭]
@Macux 2015-12-01T06:45:03.000000Z 字数 1664 阅读 1888

R语言_置换检验

R语言_学习笔记


1、置换检验的作用:


2、 我一般这样用它:


3、我怎么用它:

  1. > library(mvtnorm)
  2. > library(TH.data)
  3. > library(multcomp)
  4. > library(coin)
  5. > library(MASS)
  6. > oneway_test(yield~N,data=npk,distribution=approximate(B=9999))
  7. Approximative 2-Sample Permutation Test
  8. data: yield by N (0, 1)
  9. Z = -2.2288, p-value = 0.0243
  10. alternative hypothesis: true mu is not equal to 0

由于样本容量只有24,如果直接用单因素方差分析来做,结果虽然也许也是显著不同,但很难让人信服。

情况二:已经事先将数据分好组,并放在不同的向量中。

  1. > library(MASS)
  2. > library(coin)
  3. > wilcoxsign_test(U1~U2,data=UScrime,distribution="exact")
  4. Exact Wilcoxon-Signed-Rank Test
  5. data: y by x (neg, pos)
  6. stratified by block
  7. Z = 5.9691, p-value = 1.421e-14
  8. alternative hypothesis: true mu is not equal to 0
  1. > library(MASS)
  2. > library(coin)
  3. > library(reshape)
  4. > attach(UScrime)
  5. > UScrime <- rename(UScrime,c(y="y24"))
  6. > cor.test(y24,Ed)
  7. Pearson's product-moment correlation
  8. data: y24 and Ed
  9. t = 2.2882, df = 45, p-value = 0.02688
  10. alternative hypothesis: true correlation is not equal to 0
  11. 95 percent confidence interval:
  12. 0.03931263 0.55824793
  13. sample estimates:
  14. cor
  15. 0.3228349

从结果上看,仿佛y24和Ed的相关性很显著,相关系数为0.3228349也具有不错的可信度。但是

  1. > spearman_test(y24~Ed,data=UScrime,distribution=approximate(B=99999))
  2. Approximative Spearman Correlation Test
  3. data: y24 by Ed
  4. Z = 1.7341, p-value = 0.08317
  5. alternative hypothesis: true mu is not equal to 0

用置换检验分析该数据集,得出的结论y24和Ed的相关系数不显著不为0。从样本容量来看,我们更应倾向于选择相信置换检验的分析结果。

(增添的Iter栏列出的是要达到判停准则所需的迭代次数。)

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注