Email : sausan.ramadhani@student.matanauniversity.ac.id
RPubs : https://rpubs.com/sausanramadhani/
Jurusan
: Statistika
Address : ARA Center, Matana University Tower
Jl. CBD Barat Kav, RT.1, Curug Sangereng, Kelapa Dua,
Tangerang, Banten 15810.
Right Tail: A food company argue that for each a cookie bag of their products, there is at most 2 grams of saturated fat in a single cookie. In a sample of 40 cookies, it is found that the mean amount of saturated fat per cookie is 2.1 grams. Assume that the population standard deviation is 0.25 grams. At .05 significance level, can we reject the claim?
Answer
mu0 = 2
n = 40
xbar = 2.1
sigma = 0.25
z = (xbar-mu0)/(sigma/sqrt(n))
z## [1] 2.529822
alpha = 0.05
z.alpha = qnorm(1-alpha)
z.alpha## [1] 1.644854
pnorm(z, lower.tail = FALSE) # Z test in right tailed## [1] 0.005706018
library(BSDA)
zsum.test(mean.x=xbar, sigma.x = sigma, n.x = n,
alternative = "greater", mu = mu0,
conf.level = 0.95)##
## One-sample z-Test
##
## data: Summarized x
## z = 2.5298, p-value = 0.005706
## alternative hypothesis: true mean is greater than 2
## 95 percent confidence interval:
## 2.034981 NA
## sample estimates:
## mean of x
## 2.1
To test the hypothesis that the mean systolic blood pressure in a certain population equals 140 mmHg. The standard deviation has a known value of 20 and a data set of 55 patients is available.
#Blood_pressure dataset
no <- seq(1:55)
status <- c(rep(0, 25), rep(1, 30))
mmhg <- c(120,115,94,118,111,102,102,131,104,107,115,139,115,113,114,105,
115,134,109,109,93,118,109,106,125,150,142,119,127,141,149,144,
142,149,161,143,140,148,149,141,146,159,152,135,134,161,130,125,
141,148,153,145,137,147,169)
blood_pressure <-data.frame(no,status,mmhg)
blood_pressure## no status mmhg
## 1 1 0 120
## 2 2 0 115
## 3 3 0 94
## 4 4 0 118
## 5 5 0 111
## 6 6 0 102
## 7 7 0 102
## 8 8 0 131
## 9 9 0 104
## 10 10 0 107
## 11 11 0 115
## 12 12 0 139
## 13 13 0 115
## 14 14 0 113
## 15 15 0 114
## 16 16 0 105
## 17 17 0 115
## 18 18 0 134
## 19 19 0 109
## 20 20 0 109
## 21 21 0 93
## 22 22 0 118
## 23 23 0 109
## 24 24 0 106
## 25 25 0 125
## 26 26 1 150
## 27 27 1 142
## 28 28 1 119
## 29 29 1 127
## 30 30 1 141
## 31 31 1 149
## 32 32 1 144
## 33 33 1 142
## 34 34 1 149
## 35 35 1 161
## 36 36 1 143
## 37 37 1 140
## 38 38 1 148
## 39 39 1 149
## 40 40 1 141
## 41 41 1 146
## 42 42 1 159
## 43 43 1 152
## 44 44 1 135
## 45 45 1 134
## 46 46 1 161
## 47 47 1 130
## 48 48 1 125
## 49 49 1 141
## 50 50 1 148
## 51 51 1 153
## 52 52 1 145
## 53 53 1 137
## 54 54 1 147
## 55 55 1 169
Answer
mu0 = 140
n = 55
xbar = mean(blood_pressure$mmhg)
sigma = 20
z = (xbar-mu0)/(sigma/sqrt(n))
z## [1] -3.708099
alpha = .05 # .05 significance level
z.half.alpha = qnorm(1-alpha/2) # per-one tail .025 significance level
c(-z.half.alpha, z.half.alpha)## [1] -1.959964 1.959964
2*pnorm(-abs(z)) # Z test in two tails## [1] 0.0002088208
zsum.test(mean.x=xbar, sigma.x = 20, n.x = 55,
alternative = "two.sided", mu = mu0,
conf.level = 0.95)##
## One-sample z-Test
##
## data: Summarized x
## z = -3.7081, p-value = 0.0002088
## alternative hypothesis: true mean is not equal to 140
## 95 percent confidence interval:
## 124.7144 135.2856
## sample estimates:
## mean of x
## 130
Garuda-food Indonesia claims that for each a cookie bag states of their product, there is at most 2 grams of saturated fat in a single cookie. In a sample of 40 cookies, it is found that the mean amount of saturated fat per cookie is 2.1 grams. Assume that the sample standard deviation is 0.3 gram. At .05 significance level, can we reject the claim?
Answer
mu0 = 2
n = 40
xbar = 2.1
s = 0.3
t = (xbar-mu0)/(s/sqrt(n))
t## [1] 2.108185
alpha = 0.05
t.alpha = qt(1-alpha, df = n-1)
t.alpha## [1] 1.684875
pt(t, df=n-1, lower.tail = FALSE) # t test in right tailed## [1] 0.020746
To test the hypothesis that the mean systolic blood pressure in a certain population equals 140 mmHg. The standard deviation has a known value of 20 and a data set of 55 patients is available.
#Blood_pressure dataset
no <- seq(1:55)
status <- c(rep(0, 25), rep(1, 30))
mmhg <- c(120,115,94,118,111,102,102,131,104,107,115,139,115,113,114,105,
115,134,109,109,93,118,109,106,125,150,142,119,127,141,149,144,
142,149,161,143,140,148,149,141,146,159,152,135,134,161,130,125,
141,148,153,145,137,147,169)
blood_pressure <-data.frame(no,status,mmhg)
blood_pressure## no status mmhg
## 1 1 0 120
## 2 2 0 115
## 3 3 0 94
## 4 4 0 118
## 5 5 0 111
## 6 6 0 102
## 7 7 0 102
## 8 8 0 131
## 9 9 0 104
## 10 10 0 107
## 11 11 0 115
## 12 12 0 139
## 13 13 0 115
## 14 14 0 113
## 15 15 0 114
## 16 16 0 105
## 17 17 0 115
## 18 18 0 134
## 19 19 0 109
## 20 20 0 109
## 21 21 0 93
## 22 22 0 118
## 23 23 0 109
## 24 24 0 106
## 25 25 0 125
## 26 26 1 150
## 27 27 1 142
## 28 28 1 119
## 29 29 1 127
## 30 30 1 141
## 31 31 1 149
## 32 32 1 144
## 33 33 1 142
## 34 34 1 149
## 35 35 1 161
## 36 36 1 143
## 37 37 1 140
## 38 38 1 148
## 39 39 1 149
## 40 40 1 141
## 41 41 1 146
## 42 42 1 159
## 43 43 1 152
## 44 44 1 135
## 45 45 1 134
## 46 46 1 161
## 47 47 1 130
## 48 48 1 125
## 49 49 1 141
## 50 50 1 148
## 51 51 1 153
## 52 52 1 145
## 53 53 1 137
## 54 54 1 147
## 55 55 1 169
Answer
mu0 = 140
n = 55
xbar = mean(blood_pressure$mmhg)
s = 20
t = (xbar-mu0)/(s/sqrt(n))
t## [1] -3.708099
alpha = .05 # .05 significance level
z.half.alpha = qnorm(1-alpha/2) # per-one tail .025 significance level
c(-z.half.alpha, z.half.alpha)## [1] -1.959964 1.959964
2*pt(t, df=n-1)## [1] 0.0004938793
Right tail: Garuda-food Indonesia claims that for each a cookie bag states of their product, there is at most 2 grams of saturated fat in a single cookie. Assume the actual mean amount of saturated fat per cookie is 2.075 grams and the sample standard deviation is 0.25 grams. At .05 significance level, what is the probability of having a type II error for a sample size of 35 cookies?
Answer
mu0 = 2
mu = 2.075
sigma = 0.25
alpha = 0.05
n = 35
sem = sigma/sqrt(n)
sem## [1] 0.04225771
q = qnorm(alpha, mean=mu0, sd=sem)
q## [1] 1.930492
pnorm(q, mean=mu, sd=sem, lower.tail = FALSE)## [1] 0.9996865
Under same assumptions as case 27, if actual mean population weight is 14.9 kg, what is the probability of type II errors? What is the power of the hypothesis test?
Answer
mu0 = 15.4
mu = 14.9
sigma = 2.5
alpha = 0.05
n = 35
sem = sigma/sqrt(n)
sem## [1] 0.4225771
I = c(alpha/2, 1-alpha/2)
q = qnorm(I, mean=mu0, sd=sem)
q## [1] 14.57176 16.22824
p = pnorm(q, mean=mu, sd=sem)
p## [1] 0.2186537 0.9991644