hypothesis test

 1 # z test with known sigma, normal or large samples
 2 library('BSDA')
 3 x = c(159, 280, 101, 212, 224, 379, 179, 264, 222, 362, 168, 250,
 4       149, 260, 485, 170);
 5 z.test(x, alternative = "greater", mu=225,sigma.x=98,
 6        conf.level = 0.95)
 7 #标准正态分布
 8 # one of "greater", "less" or "two.sided",单侧/双侧
 9 # sigma.x must be known
10 
11 
12 # t test with unknown sigma, normal
13 # t分布检验
14 t.test(x, alternative = "greater", mu=225, conf.level = 0.95)
15 
16 # two samples,z-test and t-test
17 sdx = sd(x);
18 sdy = sd(y);
19 z.test(x,y, mu=0,alternative = "less",sigma.x=sdx,sigma.y=sdy)
20 t.test(x,y,mu=0,alternative = "less",var.equal = TRUE)
21 
22 
23 
24 # one and two samples, variance
25 library('DescTools')
26 VarTest(x,alternative="two.sided",sigma.squared=3,conf.level=0.95)
27 VarTest(x,y,alternative = "two.sided",ratio=3);
28 
29 a2q
30 #non-normal
31 #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
32 prop.test(445, 500, p = 0.85, alternative = "greater")
33 
34 
35 #非参数统计
36 # Nonparametric test, ks-test
37 x <- rnorm(50)
38 y <- runif(30)
39 # Do x and y come from the same distribution?
40 ks.test(x, y)
41 # Does x come from another distribution
42 ks.test(x+2, "pgamma", 3, 2) # two-sided, exact
43 ks.test(x, "pnorm")
44 ks.test(x+2, "pgamma", 3, 2, alternative = "gr")
45 
46 #Nonparametric,lillie.test
47 LillieTest(rnorm(100, mean = 5, sd = 3))
48 LillieTest(runif(100, min = 2, max = 4))
49 
50 #Nonparametric 

 

上一篇:机器学习中的假设和数理统计中的假设检验


下一篇:题解 【Cpdeforces755A】 PolandBall and Hypothesis