先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中统计假设检验总结(一)相关推荐

  1. R中统计假设检验总结

    转载自:http://site.douban.com/182577/widget/notes/12866356/note/281050230/ 先PS一个: 考虑到这次的题目本身的特点 尝试下把说明性 ...

  2. 在R中统计数据的频数或者密度分布并图形化

    在进行数据分析之前,我们往往要首先对数据有一个大致的了解.对于统计性的数据,最好首先看看数据是如何分布,并把分布图示化,可以帮助我们确定后续的分析策略.现在,以R中著名的iris数据为例来计算其中一组 ...

  3. R中的假设检验(二)方差分析

    方差分析的原理:原本想跳过这个部分的,然而突然发现自己看懂了这些公式,就忍不住写出来. (1)Xij=X均值+(X组内均值-X均值)+(Xij-X组内均值) #Xij代表第i组第j个观察值,X均值代表 ...

  4. R中的假设检验(四)卡方检验

    最近几天没碰编程,浑身难受,日子过的浑浑噩噩,还是得每天接触下编程.相较于核磁分析,我感觉统计建模更对我的胃口.今天写卡方检验(χ2检验,chi-square test). 医学中最最常见的就是四格表 ...

  5. r语言平均值显著性检验_最全的R语言统计检验方法_数据挖掘中R语言的运用

    最全的R语言统计检验方法_数据挖掘中R语言的运用 统计检验是将抽样结果和抽样分布相对照而作出判断的工作.主要分5个步骤:建立假设 求抽样分布 选择显著性水平和否定域 计算检验统计量 判定 假设检验(h ...

  6. 《机器学习与数据科学(基于R的统计学习方法)》——2.11 R中的SQL等价表述...

    本节书摘来异步社区<机器学习与数据科学(基于R的统计学习方法)>一书中的第2章,第2.11节,作者:[美]Daniel D. Gutierrez(古铁雷斯),更多章节内容可以访问云栖社区& ...

  7. ryuyan 方差分析_【r-高级|实战|统计】R中的方差分析ANOVA

    方差分析主要通过F检验来进行效果评测,若治疗方案的F检验显著,则说明检验样本组间均值不同. ANOVA模型拟合 从函数形式上看,ANOVA和回归方法都是广义线性模型的特例.因此回归分析章节中提到的lm ...

  8. R语言使用epiDisplay包的shapiro.qqnorm函数执行Shapiro-Wilk检验并可视化QQ图、整合假设检验和可视化结果判断数据是否符合正态分布(图中包含假设检验的p值)

    R语言使用epiDisplay包的shapiro.qqnorm函数执行Shapiro-Wilk检验并可视化QQ图.整合假设检验和可视化结果判断数据是否符合正态分布(图中包含假设检验的p值) 目录

  9. bartlett方差齐性检验_基于R实现统计中的检验方法方差分析

    作者:徐涛,19年应届毕业生,专注于珊瑚礁研究,喜欢用R各种清洗数据. 知乎: https://www.zhihu.com/people/parkson-19/posts 前言 方差分析(均数的显著性 ...

最新文章

  1. linux shell下获取cpu温度
  2. 输入输出 原理 java_java输入输出,书写规范,运行原理,跨平台原理(复习)...
  3. JZOJ 5477. 【NOIP2017提高组正式赛】宝藏
  4. [COGS2426][HZOI 2016]几何
  5. wdk1703+vs2015编译的诡异问题
  6. 各种卷积类型Convolution
  7. php 判断当前协议,JavaScript 判断当前协议是http还是https
  8. 计算机二级公共基础知识笔记
  9. mysql execute 存储过程_Mysql存储过程调用
  10. 栈实现二叉树的前中后序遍历
  11. Hybird App 应用开发中5个必备知识点复习
  12. matlab 双均线,一个典型的双均线策略
  13. FTP Server端的使用
  14. cifar 10 最高正确率
  15. js时间戳转时间年月日时分秒
  16. CorelDRAW版本限制使用关闭永久禁止联网登录弹窗口错误修复教程
  17. Python在振动信号处理中的应用(十一):倒频谱(Cepstrum)计算
  18. 你想要了解的黑客入门知识在这里
  19. JAVA计算机毕业设计学生实验报告管理系统Mybatis+源码+数据库+lw文档+系统+调试部署
  20. 本地搭建gitlab环境,配置邮件通知和基本操作

热门文章

  1. 算法(5)-leetcode-explore-learn-数据结构-字符串
  2. 进程锁 读写文件的小例子 C++代码
  3. codeforces 271A-C语言解题报告
  4. c++面向对象高级编程 学习十一 类模板、函数模板、成员模板
  5. 警惕 十种短命的生活方式
  6. 初探 C# GPU 通用计算技术
  7. SIP与RTP综合应用5-RTP解包过程
  8. Intellij IDEA Debug调试技巧
  9. Linux 基本操作--文件查看 (day3)
  10. NodeJS在CentOs7下安装