R中统计假设检验总结(一)
先PS一个:
考虑到这次的题目本身的特点 尝试下把说明性内容都直接作为备注写在语句中 另外用于说明的部分例子参考了我的教授Guy Yollin在Financial Data Analysis and Modeling with R这门课课件上的例子 部分参考了相关package的帮助文档中的例子 下面正题
- 戌
![]() |
> # Assume the predetermined significance level is 0.05.
假设预定的显着性水平是0.05。
> # 1 Shapiro-Wilk Test
> # Null hypothesis:
零假设:
> # The sample came from a normally distributed population.
样本来自正态分布总体
> install.packages("stats")
> library(stats)
> # args() function displays the argument names and corresponding default values of a function or primitive.
args()函数显示一个函数的参数名称和相应的默认值。
> args(shapiro.test)
function (x)
NULL
> # Example 1:
> # Test random sample from a normal distribution.
测试来自正态分布的随机抽样。
> set.seed(1)
> x <- rnorm(150)
> res <- shapiro.test(x)
> res$p.value # > 0.05
[1] 0.7885523
> # Conclusion: We are unable to reject the null hypothesis.
结论:我们无法拒绝零假设。
> # Example 2:
> # Test daily observations of S&P 500 from 1981-01 to 1991-04.
测试S&P500指数从1981-01到1991-04的日观察值。
> install.packages("Ecdat")
> library(Ecdat)
> data(SP500)
> class(SP500)
[1] "data.frame"
> SPreturn = SP500$r500 # use the $ to index a column of the data.frame
用$符号取出数据框中的一列
> (res <- shapiro.test(SPreturn))
Shapiro-Wilk normality test
data: SPreturn
W = 0.8413, p-value < 2.2e-16
> names(res)
[1] "statistic" "p.value" "method" "data.name"
> res$p.value # < 0.05
[1] 2.156881e-46
> # Conclusion: We should reject the null hypothesis.
结论:我们应该拒绝零假设。
> # 2 Jarque-Bera Test
> # Null hypothesis:
> # The skewness and the excess kurtosis of samples are zero.
样本的偏度和多余峰度均为零
> install.packages("tseries")
> library(tseries)
> args(jarque.bera.test)
function (x)
NULL
> # Example 1:
> # Test random sample from a normal distribution
> set.seed(1)
> x <- rnorm(150)
> res <- jarque.bera.test(x)
> names(res)
[1] "statistic" "parameter" "p.value" "method" "data.name"
> res$p.value # > 0.05
X-squared
0.8601533
> # Conclusion: We should not reject the null hypothesis.
> # Example 2:
> # Test daily observations of S&P 500 from 1981–01 to 1991–04
> install.packages("Ecdat")
> library(Ecdat)
> data(SP500)
> class(SP500)
[1] "data.frame"
> SPreturn = SP500$r500 # use the $ to index a column of the data.frame
> (res <- jarque.bera.test(SPreturn))
Jarque Bera Test
data: SPreturn
X-squared = 648508.6, df = 2, p-value < 2.2e-16
> names(res)
[1] "statistic" "parameter" "p.value" "method" "data.name"
> res$p.value # < 0.05
X-squared
0
> # Conclusion: We should reject the null hypothesis.
> # 3 Correlation Test
> # Null hypothesis:
> # The correlation is zero.
样本相关性为0
> install.packages("stats")
> library(stats)
> args(getS3method("cor.test","default"))
function (x, y, alternative = c("two.sided", "less", "greater"),
method = c("pearson", "kendall", "spearman"), exact = NULL,
conf.level = 0.95, continuity = FALSE, ...)
NULL
> # x, y: numeric vectors of the data to be tested
x, y: 进行测试的数据的数值向量
> # alternative: controls two-sided test or one-sided test
alternative: 控制进行双侧检验或单侧检验
> # method: "pearson", "kendall", or "spearman"
> # conf.level: confidence level for confidence interval
conf.level: 置信区间的置信水平
> # Example:
> # Test the correlation between the food industry and the market portfolio.
测试在食品行业的收益和市场投资组合之间的相关性。
> data(Capm,package="Ecdat")
> (res <- cor.test(Capm$rfood,Capm$rmrf))
Pearson's product-moment correlation
皮尔逊积矩相关
data: Capm$rfood and Capm$rmrf
t = 27.6313, df = 514, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
备择假设:真正的相关性不等于0
95 percent confidence interval:
95%置信区间
0.7358626 0.8056348
sample estimates:
样本估计
cor
0.7730767
> names(res)
[1] "statistic" "parameter" "p.value" "estimate"
[5] "null.value" "alternative" "method" "data.name"
[9] "conf.int"
> res$p.value # < 0.05
[1] 0
> # Conclusion: We should reject the null hypothesis.
R中统计假设检验总结(一)的更多相关文章
- 简单介绍一下R中的几种统计分布及常用模型
统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...
- 在 R 中估计 GARCH 参数存在的问题
目录 在 R 中估计 GARCH 参数存在的问题 GARCH 模型基础 估计 GARCH 参数 fGarch 参数估计的行为 结论 译后记 在 R 中估计 GARCH 参数存在的问题 本文翻译自< ...
- 【转载】R中有关数据挖掘的包
下面列出了可用于数据挖掘的R包和函数的集合.其中一些不是专门为了数据挖掘而开发,但数据挖掘过程中这些包能帮我们不少忙,所以也包含进来. 1.聚类 常用的包: fpc,cluster,pvclust,m ...
- (数据科学学习手札19)R中基本统计分析技巧总结
在获取数据,并且完成数据的清洗之后,首要的事就是对整个数据集进行探索性的研究,这个过程中会利用到各种描述性统计量和推断性统计量来初探变量间和变量内部的基本关系,本篇笔者便基于R,对一些常用的数据探索方 ...
- 【未解决】对于使用Windows的IDEA进行编译的文件,但无法在Linux系统中统计代码行数的疑问
在我学习使用Windows的IDEA的过程中,将代码文件转移到Linux虚拟机当中,但无法在Linux系统中统计代码行数. 注意:拷贝进虚拟机的文件均能编译运行. 具体过程如下: root@yogil ...
- 机器学习与数据科学 基于R的统计学习方法(基础部分)
1.1 机器学习的分类 监督学习:线性回归或逻辑回归, 非监督学习:是K-均值聚类, 即在数据点集中找出“聚类”. 另一种常用技术叫做主成分分析(PCA) , 用于降维, 算法的评估方法也不尽相同. ...
- 在 R 中估计 GARCH 参数存在的问题(基于 rugarch 包)
目录 在 R 中估计 GARCH 参数存在的问题(基于 rugarch 包) 导论 rugarch 简介 指定一个 \(\text{GARCH}(1, 1)\) 模型 模拟一个 GARCH 过程 拟合 ...
- R中字符串操作
简介 Stringr中包含3个主要的函数族 字符操作 空格处理 模式匹配 常用函数 在平常的数据分析工作中,经常要用到如下的函数 函数 操作 str_length() 获取字符串长度 str_sub( ...
- R中的统计模型
R中的统计模型 这一部分假定读者已经对统计方法,特别是回归分析和方差分析有一定的了解.后面我们还会假定读者对广义线性模型和非线性模型也有所了解.R已经很好地定义了统计模型拟合中的一些前提条件,因此我们 ...
随机推荐
- 【AtCoder】CODE FESTIVAL 2017 qual A
A - Snuke's favorite YAKINIKU -- #include <bits/stdc++.h> #define fi first #define se second # ...
- NDK 开发实例一(Android.mk环境配置下)
在我写这篇文章的时候,Android Studio已经是2.3版本了,已经集成CMake 编译工具, 用户只需在 新建项目的时候,添加选项(Include C++ support),Andr ...
- BZOJ1078 [SCOI2008]斜堆 堆
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1078 题意概括 斜堆(skew heap)是一种常用的数据结构.它也是二叉树,且满足与二叉堆相同的 ...
- ubuntu16系统中pycharm下使用git将代码提交到github仓库
1 在系统中安装git,在terminal中输入以下命令 sudo apt-get update sudo apt-get install git 2 对git进行配置,在terminal中输入以下命 ...
- linux 编译内核 /boot空间不足?
/boot空间一般分配100M的空间,本来是够用的,由于频繁的更新导致旧的不再使用的内核文件也保留在boot空间里,占着位置,所以把这些不用的内核文件下载掉boot空间就能释放出一部分, 具体做法为 ...
- PHP函数之array_chunk
有时候需要对数组进行按分页处理,之前的做法是计算出数组大小,按分页计算出偏移量,再从起始偏移量处开始遍历页大小个数据.现在不用这么麻烦了,原来PHP函数里有个现成的函数array_chunk可以配合我 ...
- 什么?作为程序员的你还不知道怎么访问 Google
今天就一个目的,让你可以FQ成功,其他人我不知道,但就程序员来说,不能使用 Google 那真是一大损失,当然还有对所有人适用的 YouTobu 这个视频网站,资源多的没话说,别的不说,学习英语很方便 ...
- STL中实现 iterator trail 的编程技巧
STL中实现 iterator trail 的编程技巧 <泛型编程和 STL>笔记及思考. 这篇文章主要记录在 STL 中迭代器设计过程中出现的编程技巧,围绕的 STL 主题为 (迭代器特 ...
- python 入门总结(一)
自然语言用双引号,机器语言用单引号 例如dict的key 单行注释 # 多行注释 ''' ''' 输入print %s 字符串的占位符 %d 数字的占位符 如语句中有占位符那么所有的%都是占位符,可以 ...
- 每天刷Web面试题(前10天汇总)
一.算法题部分 1. 如何获取浏览器URL中查询字符串中的参数? function getParamsWithUrl(url) { var args = url.split('?'); ...
