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.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/462306.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux中如何快速进入某个目录

http://blog.csdn.net/qinglu000/article/details/17247283 1. 如果偶尔进的话可用tab键加速目录输入速度。 2. 如果经常进某个目录可设置环境变量例如$DIRPATH/usr/bin&#xff0c;通过cd $DIRPATH的方式进入。 3. 更简单可以通过alias 命令注册一个快捷命令如alias uucd /us…

事务的四大特性和隔离级别

1.事务的四大特性(ACID)&#xff1a;指数据库事务正确执行的四个基本要素的缩写。包含&#xff1a;原子性&#xff08;Atomicity&#xff09;、一致性&#xff08;Consistency&#xff09;、隔离性&#xff08;Isolation&#xff09;、持久性&#xff08;Durability&#xff09…

改造MUC实现Openfire群

我的Openfire群实现思路&#xff1a; 1、群和群成员&#xff0c;要保存到表中。 2、拉取群列表和群成员列表&#xff0c;均从DB中查询返回。 3、抛弃老外的“进房间&#xff0c;要发Presence ”。只要此人一上线&#xff0c;就模似一个Presence进行joinRoom&#xff0c;进入他的…

如何在Windows环境下的VS中安装使用Google Protobuf完成SOCKET通信

http://blog.csdn.net/whuancai/article/details/11994341 如何在Windows环境下的VS中安装使用Google Protobuf完成SOCKET通信 原文出自&#xff1a;http://blog.csdn.net/monkey_d_meng/article/details/5894910 尊重作者&#xff1a;MONKEY_D_MENG 最近一段时间&#xff0c;由…

14 Scroll 滚动搜索

Scroll的用法&#xff1a;第一次搜的时候&#xff0c;要指定 快照保留时间1min&#xff0c;分页的大小&#xff1a;2条/页&#xff1b;对于第一次搜索&#xff0c;ES会返回一个这个scroll的id&#xff1b;下次再搜的时候&#xff0c;就带着这个scrollid去搜就行了&#xff0c;不…

解决IE6透明PNG图片的代码

使用方法1.下载DD_belatedPNG.js文件&#xff08;官方网站&#xff1a;http://www.dillerdesign.com/experiment/DD_belatedPNG/&#xff09;. 2.在网页中head区引用,如下:<!--[if IE 6]><script src"DD_belatedPNG.js" mce_src"DD_belatedPNG.js"…

LVS+Keepalived负载均衡方式总结

1、负载均衡器、服务器集群直连方式&#xff08;lb_kind DR&#xff09;http://network.51cto.com/art/201006/206831.htmhttp://www.myhack58.com/Article/sort099/sort0102/2012/35640_4.htm负载均衡器最简洁安装可以直接#yum ipvsadm keepalived根据51cto.com网站知道要分别…

VS2008中使用JSONCPP方法小结

http://sourceforge.net/projects/jsoncpp/?sourcetyp_redirect C要使用JSON来解析数据&#xff0c;一般采用jsoncpp. 下载jsoncpp后&#xff0c;按ReadMe文档的说法是要先安装的&#xff0c;但是安装比较麻烦。然而事实上&#xff0c;我们并不需要安装&#xff0c;就可以直接…

SQL条件语句(IF, CASE WHEN, IF NULL)

1.IF 表达式&#xff1a;IF( expr1 , expr2 , expr3 ) expr1条件&#xff0c;条件为true&#xff0c;则值是expr2 &#xff0c;false&#xff0c;值就是expr3 SELECT o.id,u.account,catagory.name,orderTime,detail.amount,periodtime,if(direction0,看涨,看跌) directionNam…

Forensic Challenge 9 - Mobile Malware

使用智能手机的人越来越多&#xff0c;对智能手机的安全研究也慢慢开始成为重点。The honey project有一个Mobile malware的挑战赛&#xff0c; 带你走进Mobile Malwares的世界。参见&#xff1a; Forensic Challenge 9 - "Mobile Malware" 样本&#xff1a; fc9fil…

如何在Windows下编译OpenSSL

OpenSSL是一个开源的第三方库&#xff0c;它实现了SSL&#xff08;Secure SocketLayer&#xff09;和TLS&#xff08;Transport Layer Security&#xff09;协议&#xff0c;被广泛企业应用所采用。对于一般的开发人员而言&#xff0c;在 http://slproweb.com/products/Win32Op…

《团队名称》第八次团队作业:Alpha冲刺day5

项目内容这个作业属于哪个课程2016计算机科学与工程学院软件工程(西北师范大学)这个作业的要求在哪里实验十二 团队作业8—软件测试与ALPHA冲刺团队名称快活帮作业学习目标 &#xff08;1&#xff09;掌握软件测试基础技术。 &#xff08;2&#xff09;学习迭代式增量软件开发过…

(转)C# 把我所积累的类库全部分享给博友(附件已经上传)

http://files.cnblogs.com/LsGW/Common.zip转载于:https://www.cnblogs.com/meetrice/archive/2012/01/02/2310428.html

Oracle的resetlogs机制浅析

alter database open resetlogs 这个命令我想大家都很熟悉了&#xff0c;那有没有想过这个resetlogs选项为什么要用&#xff1f;什么时候用&#xff1f;它的原理机制是什么&#xff1f;他都起哪些作用&#xff1f;我们都知道数据在启动时候是要做一致性检查的&#xff0c;oracl…

前端的小图标获取

搜索iconfont&#xff0c;里面有很多图标&#xff0c;鼠标移到想要的图标上&#xff0c;然后点击一个类似购物车的图标&#xff0c;然后添加到项目&#xff0c;下载到本地&#xff0c;有一个使用指南的html&#xff0c;然后参照上面的改就好。 把下载好的.css和.eot文件拖到css…

LINQ学习笔记(9) LINQ to Objects---查询内存中对象的集合

从这一篇开始要总结的是LINQ在实际中的应用&#xff0c;首先要总结的是LINQ to Objects&#xff0c;也就是LINQ与程序对象的配合使用。 其中程序对象集合最典型就是与数组的配合使用,如下示例&#xff1a; 1 class Program 2 { 3 static void Main(string[] args) …

$JavaScript(3)

41、渐进增强和优雅降级 渐进增强 &#xff1a;针对低版本浏览器进行构建页面&#xff0c;保证最基本的功能&#xff0c;然后再针对高级浏览器进行效果、交互等改进和追加功能达到更好的用户体验。 优雅降级 &#xff1a;一开始就构建完整的功能&#xff0c;然后再针对低版本浏…

[恢]hdu 1846

2011-12-23 06:07:41 地址&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid1846 题意&#xff1a;中文。 mark&#xff1a;考虑n%(m1)是否为0。 代码&#xff1a; # include <stdio.h>int main (){int T, n, m ; scanf ("%d", &T) ;while (T--)…

转:Yupoo(又拍网)的系统架构

Yupoo!&#xff08;又拍网&#xff09; 是目前国内最大的图片服务提供商&#xff0c;整个网站构建于大量的开源软件之上。以下为其使用到的开源软件信息&#xff1a; 操作系统&#xff1a;CentOS、MacOSX、Ubuntu 服务器&#xff1a;Apache、Nginx、Squid 数据库&#xff1a;…

搭建golang webcron 定时任务管理平台

获取源码 $ go get github.com/lisijie/webcron 打开配置文件 conf/app.conf&#xff0c;修改相关配置。 创建数据库webcron&#xff0c;再导入install.sql $ mysql -u username -p -D webcron < install.sql 运行 $ ./webcron 或 $ nohup ./webcron 2>&1 > error…