r语言 第13天 一般统计 241页

1  summary函数   给出几个统计值

对于matrix  返回一列一列的

对于 dataframe  也是

对于factor  返回counts,不是预期

对于list   返回的不是预期

可以使用lapply

> lapply(vec.list, summary) 


相关频率

例如  mean(after > before) 

即   符合逻辑的个数/总的个数


制表因素和创建列联表
使用table函数

对各个factor 计数

 xtabs 函数也可以


计算自变量的独立性

> summary(table(fac1,fac2)) 


计算一个数据的分位数

> quantile(vec, f)

> quantile(vec, c(.05, .95))        

5%        95% 

0.04575003 0.95122306 


> quantile(vec)         

0%         25%         50%         75%        100% 

0.001285589 0.260075658 0.479866042 0.734801500 0.997817661 


> mean(vec < x)


 Converting Data to Z-Scores 
> scale(x)        x为 vectors, matrices, and data frames

等价于  > (y - mean(x)) / sd(x)


t Test

> t.test(x, mu=m)


平均的置信区间

> t.test(x, conf.level=0.99)
 

中位数的置信区间

> wilcox.test(x, conf.int=TRUE) 

Testing a Sample Proportion 

> prop.test(x, n, p) 


形成一定比例的置信区间

> prop.test(n, x) 


Testing for Normality 
> shapiro.test(x) 

Testing for Runs 

2值数据  是否为随机数

> library(tseries) 

> runs.test(as.factor(s)) 

例子:

> library(tseries) 

> s <- sample(c(0,1), 100, replace=T) 

> runs.test(as.factor(s))

 比较两个样本的平均数

> t.test(x, y) 


1   > cor.test(x, y) 

     > cor.test(x, y, method="Spearman") 

2    Testing Groups for Equal Proportions 

> ns <- c(ns1, ns2, ..., nsN) 

> nt <- c(nt1, nt2, ..., ntN) 

> prop.test(ns, nt)


3  > pairwise.t.test(x,f) 

4  Testing Two Samples for the Same Distribution 

    > ks.test(x, y) 





















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值