一、参数检验
1. z-test(正态)
均值检验,方差已知
1.大样本
2.单正态总体
1 library(‘BSDA‘) 2 x = c(159, 280, 101, 212, 224, 379, 179, 264, 222, 362, 168, 250, 3 149, 260, 485, 170); 4 z.test(x, alternative = "greater", mu=225,sigma.x=98, 5 conf.level = 0.95)
alternative: 备择假设 "greater","less","two.sided"
3.双正态总体
1 sdx = sd(x); 2 sdy = sd(y); 3 z.test(x,y, mu=0,alternative = "less",sigma.x=sdx,sigma.y=sdy)
2. t-test(学生分布)
均值检验,方差未知(S代替sigma)
1.单正态总体
1 t.test(x, alternative = "greater", mu=225, conf.level = 0.95)
2.双正态总体
1 sdx = sd(x); 2 sdy = sd(y); 3 t.test(x,y,mu=0,alternative = "less",var.equal = TRUE)
3. var.test(F分布)
方差检验,单总体或双总体(多为双正态总体,单正态总体用卡方检验)
Sw, F(n1-1,n2-1)
1 library(‘DescTools‘) 2 VarTest(x,alternative="two.sided",sigma.squared=3,conf.level=0.95) 3 VarTest(x,y,alternative = "two.sided",ratio=3);
二、大样本非正态检验
prop.test
利用derta方法+中心极限定理,得到统计量的近似分布
方法同正态分布
#prop.test can be used for testing the null that the proportions (probabilities of success) in several groups are the same, or that they equal certain given values
1 prop.test(445, 500, p = 0.85, alternative = "greater")
三、非参数检验
1. K-S检验
Kolmogorov-Smirnov test
参数已知,F0连续
1 x <- rnorm(50) 2 y <- runif(30) 3 # Do x and y come from the same distribution? 4 ks.test(x, y) 5 # Does x come from another distribution 6 ks.test(x+2, "pgamma", 3, 2) # two-sided, exact 7 ks.test(x, "pnorm") 8 ks.test(x+2, "pgamma", 3, 2, alternative = "gr")
2. K-L检验
参数未知,检验是否符合正态/指数分布
1 LillieTest(rnorm(100, mean = 5, sd = 3)) 2 LillieTest(runif(100, min = 2, max = 4))
3. 卡方检验
参数已知/未知
分布连续/离散
精确度不如K-S/K-L
其根本思想就是在于比较理论频数和实际频数的吻合程度或拟合优度问题。
用处:1. 卡方拟合优度检验 F1(x)=F2(x)
2. 卡方独立性检验 F(x1,x2)=F(x1)*F(x2)
1.拟合优度检验
A为实际值,T为理论值
(https://www.jianshu.com/p/bb0bd72bc428)
例题:
1 #(1)H0:分布满足泊松分布 H1:分布不满足泊松分布 2 x=0:4 3 y=c(8,16,17,10,9) 4 real_pois=ppois(x,mean(rep(x,y)))#生成满足泊松分布的数组,与data相比 5 n=length(y) 6 p=numeric(n) 7 p[1]=real_pois[1] 8 p[n]=1-real_pois[n-1] 9 for (i in 2:(n-1)) { 10 p[i]=real_pois[i]-real_pois[i-1]#ppois生成的是F(x),为得到每个点的概率,用相减 11 } 12 chisq.test(y,p=p)#y是data的p, p是若满足泊松应符合的p 13 #p-value=0.9891>0.05 故接受原假设,即该分布满足泊松分布
原文:https://www.cnblogs.com/jiangstudy/p/12899455.html