Chapter 07-Basic statistics(Part4 t-tests&&nonparametric tests of group difference)
一. 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)的更多相关文章
- 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 ...
- Spark MLlib 之 Basic Statistics
Spark MLlib提供了一些基本的统计学的算法,下面主要说明一下: 1.Summary statistics 对于RDD[Vector]类型,Spark MLlib提供了colStats的统计方法 ...
- Chapter 06—Basic graphs
三. 柱状图(Histogram) 1. hist():画柱状图 ·breaks(可选项):控制柱状图的小柱子的条数: ·freq=FALSE:基于概率(probability),而非频率(frequ ...
- Chapter 04—Basic Data Management
1. 创建新的变量 variable<-expression expression:包含一组大量的操作符和函数.常用的算术操作符如下表: 例1:根据已知变量,创建新变量的三种途径 > my ...
- Chapter 2 Basic Elements of JAVA
elaborate:详细说明 Data TypesJava categorizes data into different types, and only certain operationscan ...
- [Node & Tests] Intergration tests for Authentication
For intergration tests, always remember when you create a 'mass' you should aslo clean up the 'mass' ...
- Parametric Statistics
1.What are “Parametric Statistics”? 统计中的参数指的是总体的一个方面,而不是统计中的一个方面,后者指的是样本的一个方面.例如,总体均值是一个参数,而样本均值是一个统 ...
- 吴裕雄--天生自然 R语言开发学习:基本统计分析(续三)
#---------------------------------------------------------------------# # R in Action (2nd ed): Chap ...
- 吴裕雄--天生自然 R语言开发学习:基本统计分析
#---------------------------------------------------------------------# # R in Action (2nd ed): Chap ...
随机推荐
- CSPS模拟 65
cbx又A两题%%% T1比较水,只需要想到lcm以内的数都只能被唯一凑出就可以. T2比较shi,毕竟std复杂度都不正确的题是不能称之为完整的题的. 那么再感受一下T3满满的恶意 起点已经固定了, ...
- CF600E Lomsat gelral——线段树合并/dsu on tree
题目描述 一棵树有$n$个结点,每个结点都是一种颜色,每个颜色有一个编号,求树中每个子树的最多的颜色编号的和. 这个题意是真的窒息...具体意思是说,每个节点有一个颜色,你要找的是每个子树中颜色的众数 ...
- 『题解』洛谷P1314 聪明的质监员
更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Portal3: Vijos Description 小T是一名质量监督员,最近负责检验一批矿产的质量.这 ...
- transformer模型简介
Transformer模型由<Attention is All You Need>提出,有一个完整的Encoder-Decoder框架,其主要由attention(注意力)机制构成.论文地 ...
- 关于@Autowired 与@Resource的
@Autowired注解是spring自己定义的,@Resource是由JSR-250规范定义的注解. @Resource的作用相当于@Autowired,只不过@Autowired按byType自动 ...
- 【Spring】Spring的定时任务注解@Scheduled原来如此简单
1 简介 定时任务的实现非常多,JDK的Timer.Spring提供的轻量级的Scheduled Task.QuartZ和Linux Cron等,还有一些分布式的任务调度框架.本文主要介绍Schedu ...
- Mssql 查询某记录前后N条
Sqlserver 查询指定记录前后N条,包括当前数据 条件 [ID] 查询 [N]条 select * from [Table] where ID in (select top ([N]+1) ID ...
- nyoj 35-表达式求值(stack, 栈的应用)
35-表达式求值 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:37 submit:53 题目描述: ACM队的mdd想做一个计算器,但是,他要做的 ...
- 设置 DNS 服务器转发试验
一.主节点的配置 1.yum install bind -y 安装 DNS 服务 2.vim /etc/named.conf 编辑 DNS 的配置文件 3. vim /etc/named.rfc191 ...
- python:爬虫0
什么是网页爬虫,也叫网页蜘蛛.把互联网比作一个蜘蛛网,有好多节点,这个蜘蛛在网上爬来爬去,对对网页中的每个关键字进行建立索引,然后建立索引数据库,经过复杂的排序算法后,这些算法的结果将按照相关度的高低 ...