一. t-tests

这一部分我们使用分布在MASS包中的UScrime数据集。它是关于美国47个州在1960年时,关于惩罚制度对犯罪率的影响。

Prob:监禁(坐牢)的概率;

U1:14到24岁的城市那你的失业率;

U2:35到39岁的城市男子的失业率;

So:an indicator variable for Southern states

1. 独立的t-test(independent t-test)

t.test(y~x,data)

t.tset(y1,y2)

例01:

> library(MASS)
> t.test(Prob~So,data=UScrime) Welch Two Sample t-test data: Prob by So
t = -3.8954, df = 24.925, p-value = 0.0006506
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.03852569 -0.01187439
sample estimates:
mean in group 0 mean in group 1
0.03851265 0.06371269

注意:可以摒弃南方的州和非南方的州有相同的犯罪率,因为p<0.01。

2.依赖的t-test

t.test(y1,y2,paired=TRUE)

·y1和y2是两个有依赖关系的组的数值向量。

例02:

> library(MASS)
> sapply(UScrime[c("U1","U2")],function(x)(c(mean=mean(x),sd=sd(x))))
U1 U2
mean 95.46809 33.97872
sd 18.02878 8.44545
> with(UScrime,t.test(U1,U2,paired=TRUE)) Paired t-test data: U1 and U2
t = 32.4066, df = 46, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
57.67003 65.30870
sample estimates:
mean of the differences
61.48936

二. nonparametric tests of group difference

1. 比较两组

如果两组是独立的,应该使用Wilcoxon rank sum去评估自变量是否是来自相同概率分布的样本。

wilcox.test(y~x,data)

wilcox.test(y1,y2)

例03:

> with(UScrime,by(Prob,So,median))
So: 0
[1] 0.038201
--------------------------------------------------------
So: 1
[1] 0.055552
> wilcox.test(Prob~So,data=UScrime) Wilcoxon rank sum test data: Prob by So
W = 81, p-value = 8.488e-05
alternative hypothesis: true location shift is not equal to 0

例04:

> sapply(UScrime[c("U1","U2")],median)
U1 U2
92 34
> with(UScrime,wilcox.test(U1,U2,paired=TRUE)) Wilcoxon signed rank test with continuity correction data: U1 and U2
V = 1128, p-value = 2.464e-09
alternative hypothesis: true location shift is not equal to 0

2.比较多于两组

Kruskal-Wallis test:

kruskal.test(y~A,data)

·A:a grouping variable with two or more levels, if just two levels, equivalent to Mann-Whitney;

·y:a numeric outcome variable;

Friedman test:

friedman.test(y~A|B,data)

·B: a blocking variable that identifies matched observations.

npmc包中的npmc()函数:期待输入两列的数据,分别叫var(the dependent variable)和class(the grouping variable).

Chapter 07-Basic statistics(Part4 t-tests&&nonparametric tests of group difference)的更多相关文章

  1. Intro to Python for Data Science Learning 8 - NumPy: Basic Statistics

    NumPy: Basic Statistics from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/ch ...

  2. Spark MLlib 之 Basic Statistics

    Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...

  3. Chapter 06—Basic graphs

    三. 柱状图(Histogram) 1. hist():画柱状图 ·breaks(可选项):控制柱状图的小柱子的条数: ·freq=FALSE:基于概率(probability),而非频率(frequ ...

  4. Chapter 04—Basic Data Management

    1. 创建新的变量 variable<-expression expression:包含一组大量的操作符和函数.常用的算术操作符如下表: 例1:根据已知变量,创建新变量的三种途径 > my ...

  5. Chapter 2 Basic Elements of JAVA

    elaborate:详细说明 Data TypesJava categorizes data into different types, and only certain operationscan ...

  6. [Node & Tests] Intergration tests for Authentication

    For intergration tests, always remember when you create a 'mass' you should aslo clean up the 'mass' ...

  7. Parametric Statistics

    1.What are “Parametric Statistics”? 统计中的参数指的是总体的一个方面,而不是统计中的一个方面,后者指的是样本的一个方面.例如,总体均值是一个参数,而样本均值是一个统 ...

  8. 吴裕雄--天生自然 R语言开发学习:基本统计分析(续三)

    #---------------------------------------------------------------------# # R in Action (2nd ed): Chap ...

  9. 吴裕雄--天生自然 R语言开发学习:基本统计分析

    #---------------------------------------------------------------------# # R in Action (2nd ed): Chap ...

随机推荐

  1. 关于ReentrantLock 中的lockInterruptibly方法的简单探究

    今天在看Lock,都知道相比于synchronized,多了公平锁,可中断等优秀性能. 但是说到可中断这个特点,看到很多博客是这么描述的: “与synchronized关键字不同,获取到锁的线程能够响 ...

  2. 【原创】go语言学习(二十一)Select和线程安全

    目录 select语义介绍和使用 线程安全介绍 互斥锁介绍和实战 读写锁介绍和实战 原子操作介绍 select语义介绍和使用 1.多channel场景 A. 多个channel同时需要读取或写入,怎么 ...

  3. UVA12433 【Rent a Car】

    这题应该算是比较难的一道网络流的题,(但却在我校OJ考试上出现了),但是大家只要能理解此图的建边方式就行. 假设有5天的租车需求,虚拟出2*n+2 即 12个节点,0为源点,12为汇点. 1,源点到1 ...

  4. [LLL邀请赛]参观路线(图论+dfs)

    emmmm....学校的oj被查水表了,扒不到原题面,所以.... 但是我还是扒到了题面... 题目大意:给定一个完全图,删掉其中一些边,然后求其字典序最小的遍历顺序 有点像去年day2T1啊.... ...

  5. 树上神奇 逆 逆序对(我的叫法)hh的小纸条 重中之重!!!!!

    HH是一位十分爱好数学的大佬,尤其喜爱数数,一天百无聊赖的他写下了一个1-N的排列,并且在小纸条上记下了每个数前面有多少个数比他小,但HH不小心忘记了这个排列.现在只有当时记下的小纸条,现在请你还原出 ...

  6. Docker变量的相关总结

    一.AVG与ENV 1.在Dockerfile中,使用ARG与ENV的区别 ARG:ARG定义的变量用于构建Docker镜像,在通过build把Dockerfile构建成镜像后,ARG定义的变量便不在 ...

  7. 大数据之路week01--day02_2 集合方面的总结

    (初稿 太晚了,明天再进行补充) 1.对象数组(掌握) (1)数组既可以存储基本数据类型,也可以存储引用类型.它存储引用类型的时候的数组就叫对象数组. (2)案例: 用数组存储5个学生对象,并遍历数组 ...

  8. 字符串(str)

    把字符连成串串. 在python中⽤用', ", ''', """引起来的内容被称为字符串串. 字符串是不可变的对象,所以任何操作对原字符串是不会有任何影响的 ...

  9. .net 上传文件:超过了最大请求长度

    修改 web.config: 该方法是.net框架限制 添加: <system.web> ... ... <httpRuntime   ... maxRequestLength=&q ...

  10. Spring简单的示例

    参考资料:https://how2j.cn/k/spring/spring-ioc-di/87.html.https://www.w3cschool.cn/wkspring/dgte1ica.html ...