Unit1 - 2 Solved
Unit1 - 2 Solved
– ω
∗
–
∗
∗
∗
•
1
–
•
•
•
•
•
µ µ0 →=
2
H 0 : µ = µ0 H 0 : µ = µ0 H 0 : µ ↑ µ0 H 0 : µ = µ0 H 0 : µ ↓ µ0
H0 : µ →= µ0 H 0 : µ < µ0 H 0 : µ > µ0
• ε2
•
X̄ ↔ µ0
ZCalc =
→ω
n
• X̄
• X̄
µ0 →ω
n
•
3
•
– P (Z > Zcalc )
∗ Zcalc
– P (Z < Zcalc )
∗ Zcalc
– 2 ↘ P (Z < ↔|Zcalc |)
∗ ↘ Zcalc
• ε2
•
X̄ ↔ µ0
Tcalc =
→S
n
• ε2
S2
•
n↔1 n
• T calc ↗ Tn↑1
•
4
– P (Tn↑1 > Tcalc )
∗ Tcalc
– P (Tn↑1 < Tcalc )
∗ Tcalc
– 2 ↘ P (Tn↑1 < ↔|Tcalc |)
∗ ↘ Tcalc
R code
•
–
–
–
• H0
• Ha
•
• ω
5
Testing Our Understanding of 1.2.1
Example 1
6
df=50-1
t_cv1=qt(p = .025,df = df) #-2.009575
t_cv2=qt(.975,49) #2.009575
t_ts=(295-300)/(20/50ˆ.5) #-1.767767
pvalue=2*pt(-abs(t_ts),df) #0.08332616
tsum.test(mean.x = 295,s.x = 20,n.x = 50,alternative = "two.sided",mu = 300,conf.level =
##
## One-sample t-Test
##
## data: Summarized x
## t = -1.7678, df = 49, p-value = 0.08333
## alternative hypothesis: true mean is not equal to 300
## 95 percent confidence interval:
## 289.3161 300.6839
## sample estimates:
## mean of x
## 295
7
Example 2
8
df=20-1
t_cv=qt(p = .01,df = df) #-2.539483
t_ts=(108-110)/(10/20ˆ.5) #-0.8944272
pvalue=pt(t_ts,df) #0.1911421
tsum.test(mean.x = 108,s.x = 10,n.x = 20,alternative = "less",mu = 110,conf.level = .99)
##
## One-sample t-Test
##
## data: Summarized x
## t = -0.89443, df = 19, p-value = 0.1911
## alternative hypothesis: true mean is less than 110
## 99 percent confidence interval:
## NA 113.6785
## sample estimates:
## mean of x
## 108
9
1.2.2: How to Test Hypotheses for a
Proportion
•
•
H0 : p = p 0 H0 : p = p 0 H0 : p ↑ p 0 H0 : p = p 0 H0 : p ↓ p 0
H0 : p →= p0 H 0 : p < p0 H 0 : p > p0
10
STEP 3: Analyze Sample Data
•
•
p̂ ↔ p0
ZCalc = !
p0 (1↑p0 )
n
• p̂
• ! p̂
p0 (1↑p0 )
p0 n
•
!
p0 (1↑p0 )
• Z ↗ N (0, 1) p̂ ↗ N (p0 , n
)
•
– P (Z > Zcalc )
∗ Zcalc
– P (Z < Zcalc )
∗ Zcalc
– 2 ↘ P (Z < ↔|Zcalc |)
∗ ↘ Zcalc
11
STEP 4: Interpret Results
•
R code
•
–
∗
12
Testing Our Understanding of 1.2.2
Example 3
13
z_cv1=qnorm(p = .025)#-1.959964
p_cv1=qnorm(.025,.8,(.8*.2/100)ˆ.5)#0.7216014
z_cv2=qnorm(.975)#1.959964
p_cv2=qnorm(.975,.8,(.8*.2/100)ˆ.5)#0.8783986
z_ts=(.73-.8)/(.8*.2/100)ˆ.5#1.75
pvalue=min(2*pnorm(z_ts),2*pnorm(-1*z_ts))#0.08011831
prop.test(x = 73,n = 100,p = 0.8,alternative = "two.sided",conf.level = .95,correct = F)
##
## 1-sample proportions test without continuity correction
##
## data: 73 out of 100, null probability 0.8
## X-squared = 3.0625, df = 1, p-value = 0.08012
## alternative hypothesis: true p is not equal to 0.8
## 95 percent confidence interval:
## 0.6356788 0.8073042
## sample estimates:
## p
## 0.73
14
Example 4
15
z_cv=qnorm(p = .05) #-1.644854
p_cv=qnorm(.05,.8,(.8*.2/100)ˆ.5) #0.7342059
z_ts=(.73-.8)/(.8*.2/100)ˆ.5 #1.75
pvalue=pnorm(z_ts) #0.04005916
prop.test(x = 73,n = 100,p = 0.8,alternative = "less",conf.level = .95,correct = F)
##
## 1-sample proportions test without continuity correction
##
## data: 73 out of 100, null probability 0.8
## X-squared = 3.0625, df = 1, p-value = 0.04006
## alternative hypothesis: true p is less than 0.8
## 95 percent confidence interval:
## 0.000000 0.796252
## sample estimates:
## p
## 0.73
16
Extra Examples
Example 5
17
data <- read.csv("https://raw.githubusercontent.com/DanikaLipman/Stat217/refs/heads/main
data
## x X
## 1 1 13645
## 2 2 13157
## 3 3 13153
## 4 4 12965
## 5 5 12764
## 6 6 12664
## 7 7 11665
## 8 8 10565
## 9 9 12665
## 10 10 12765
data$x
## [1] 1 2 3 4 5 6 7 8 9 10
data$X
## [1] 13645 13157 13153 12965 12764 12664 11665 10565 12665 12765
##
## One-sample t-Test
##
## data: Summarized x
## t = -1.4938, df = 9, p-value = 0.08471
## alternative hypothesis: true mean is less than 13015
## 95 percent confidence interval:
## NA 13109.07
## sample estimates:
## mean of x
## 12600.8
18
t.test(x = data$X,alternative = "less",
mu = 13015,conf.level = .95)
##
## One Sample t-test
##
## data: data$X
## t = -1.4938, df = 9, p-value = 0.08471
## alternative hypothesis: true mean is less than 13015
## 95 percent confidence interval:
## -Inf 13109.07
## sample estimates:
## mean of x
## 12600.8
ad.test(data$X)
##
## Anderson-Darling normality test
##
## data: data$X
## A = 0.80446, p-value = 0.02394
19
Example 6
##
## One-sample z-Test
##
## data: Summarized x
## z = 2.0667, p-value = 0.03877
## alternative hypothesis: true mean is not equal to 8
## 95 percent confidence interval:
## 8.032011 9.207989
## sample estimates:
## mean of x
## 8.62
20
Example 7
##
## 1-sample proportions test without continuity correction
##
## data: 126 out of 300, null probability 0.45
## X-squared = 1.0909, df = 1, p-value = 0.1481
## alternative hypothesis: true p is less than 0.45
## 95 percent confidence interval:
## 0.0000000 0.4673817
## sample estimates:
## p
## 0.42
21
22
Example 8
p ↑ 0.5
ω = 0.05
##
## 1-sample proportions test without continuity correction
##
## data: 0.46 * 400 out of 400, null probability 0.5
## X-squared = 2.56, df = 1, p-value = 0.0548
## alternative hypothesis: true p is less than 0.5
## 95 percent confidence interval:
## 0.0000000 0.5011212
## sample estimates:
## p
## 0.46
23
24
34
Copyright© Scott Robison all rights reserved 12/23