先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中的几种统计分布及常用模型

    统计学上分布有很多,在R中基本都有描述.因能力有限,我们就挑选几个常用的.比较重要的简单介绍一下每种分布的定义,公式,以及在R中的展示. 统计分布每一种分布有四个函数:d――density(密度函数) ...

  2. 在 R 中估计 GARCH 参数存在的问题

    目录 在 R 中估计 GARCH 参数存在的问题 GARCH 模型基础 估计 GARCH 参数 fGarch 参数估计的行为 结论 译后记 在 R 中估计 GARCH 参数存在的问题 本文翻译自< ...

  3. 【转载】R中有关数据挖掘的包

    下面列出了可用于数据挖掘的R包和函数的集合.其中一些不是专门为了数据挖掘而开发,但数据挖掘过程中这些包能帮我们不少忙,所以也包含进来. 1.聚类 常用的包: fpc,cluster,pvclust,m ...

  4. (数据科学学习手札19)R中基本统计分析技巧总结

    在获取数据,并且完成数据的清洗之后,首要的事就是对整个数据集进行探索性的研究,这个过程中会利用到各种描述性统计量和推断性统计量来初探变量间和变量内部的基本关系,本篇笔者便基于R,对一些常用的数据探索方 ...

  5. 【未解决】对于使用Windows的IDEA进行编译的文件,但无法在Linux系统中统计代码行数的疑问

    在我学习使用Windows的IDEA的过程中,将代码文件转移到Linux虚拟机当中,但无法在Linux系统中统计代码行数. 注意:拷贝进虚拟机的文件均能编译运行. 具体过程如下: root@yogil ...

  6. 机器学习与数据科学 基于R的统计学习方法(基础部分)

    1.1 机器学习的分类 监督学习:线性回归或逻辑回归, 非监督学习:是K-均值聚类, 即在数据点集中找出“聚类”. 另一种常用技术叫做主成分分析(PCA) , 用于降维, 算法的评估方法也不尽相同. ...

  7. 在 R 中估计 GARCH 参数存在的问题(基于 rugarch 包)

    目录 在 R 中估计 GARCH 参数存在的问题(基于 rugarch 包) 导论 rugarch 简介 指定一个 \(\text{GARCH}(1, 1)\) 模型 模拟一个 GARCH 过程 拟合 ...

  8. R中字符串操作

    简介 Stringr中包含3个主要的函数族 字符操作 空格处理 模式匹配 常用函数 在平常的数据分析工作中,经常要用到如下的函数 函数 操作 str_length() 获取字符串长度 str_sub( ...

  9. R中的统计模型

    R中的统计模型 这一部分假定读者已经对统计方法,特别是回归分析和方差分析有一定的了解.后面我们还会假定读者对广义线性模型和非线性模型也有所了解.R已经很好地定义了统计模型拟合中的一些前提条件,因此我们 ...

随机推荐

  1. BZOJ1146 [CTSC2008]网络管理Network 树链剖分 主席树 树状数组

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1146 题意概括 在一棵树上,每一个点一个权值. 有两种操作: 1.单点修改 2.询问两点之间的树链 ...

  2. Python2 - 基础2 - 数据类型和模块

    一.数据类型 标准数据类型(5): Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 其中数字类型有4种: int(有符号整型) 在3 ...

  3. CSS3 根据屏幕大小显示内容(@media)

    @media (min-width: 993px) {  .footer .addZ1{display:none;}  .footer .addZ2{display:none;}  .footer . ...

  4. 004.Kickstart部署之FTP架构

    一 准备 1.1 完整架构:Kickstart+DHCP+VSFTP+TFTP+PXE 1.2 组件应用 Kickstart服务端IP:172.24.8.12 DHCP:提供客户端IP,网关,镜像路径 ...

  5. Linux 运行Python文件,不因终端关闭而终止运行

    在Linux服务器运行py文件时,有时会因为终端窗口的关闭而结束py文件的执行,这时候使用下面的命令运行py文件: $nohup python filename.py & 命令解释: nohu ...

  6. mysql5.7一键安装脚本

    0. 概述 最近鼓捣出了一个mysql安装脚本,将该脚本,mysql的my.cnf文件,mysql的安装包这三个文件放在同一个目录下面,执行sh mysql-auto-install.sh就可以完成m ...

  7. BZOJ.2069.[POI2004]ZAW(最短路Dijkstra 按位划分)

    题目链接 \(Description\) 给定一张带权图(边是双向的,但不同方向长度不同).求从1出发,至少经过除1外的一个点,再回到1的最短路.点和边不能重复经过. \(n\leq5000,m\le ...

  8. BZOJ.2639.矩形计算(二维莫队)

    题目链接 二维莫队,按x,y坐标一起分块.(x,y)的所属的块为 x/sq(n)*sq(m) + y/sq(m) 排序时按照(左下点所在块,右上点的标号)排序 排序后 先得出一个询问的答案,然后利用上 ...

  9. 本地搭建Wordpress博客网站(Windows)

    最近在写一些web功能测试的一个主题分享,里边有一个分类是数据库测试,那么数据库测试有几个点的方法,其中有一个是学会看数据库的日志.由于公司内部的数据库日志我们测试人员暂时不开放查看,所以打算自己在本 ...

  10. AppleScript脚本学习记录《二》

    关于AppleScript 说到AppleScript,可能涉及到三个含义: 1.AppleScript语言:就是苹果脚本的语言,用来编写运行于Mac系统的脚本. 2.AppleScript脚本:就是 ...