1 summary函数 给出几个统计值
对于matrix 返回一列一列的
对于 dataframe 也是
对于factor 返回counts,不是预期
对于list 返回的不是预期
可以使用lapply
> lapply(vec.list, summary)
相关频率
例如 mean(after > before)
即 符合逻辑的个数/总的个数
制表因素和创建列联表
对各个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
等价于 > (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)