Jawaban :
ci_norm = function(rata , sigma, n , type = "z"){
if(type == "z"){
ci_upper = rata+(1.96*sigma/sqrt(n))
ci_lower = rata-(1.96*sigma/sqrt(n))
}else{
ci_upper = rata+(qt(0.975,n-1)*sigma/sqrt(n))
ci_lower = rata-(qt(0.975,n-1)*sigma/sqrt(n))
}
res = cbind(ci_lower,ci_upper)
res
}
ci_norm(1200000,600000,16)
## ci_lower ci_upper
## [1,] 906000 1494000
Jawaban :
ci_norm(1200000,600000,16, type = "t")
## ci_lower ci_upper
## [1,] 880282.6 1519717
Jawaban :
pakan_a = c(4.6, 5.0,4.7,4.1,4.0, 3.8,3.6,4.8,3.8, 4.2)
pakan_b = c(6.5 , 5.9 ,7.0,6.4 , 6.3,8.0,4.6 , 3.9 , 4.2 ,4.5,5.8,3.9)
n_a = nrow(pakan_a)
n_b = nrow(pakan_b)
xbar_a = mean(pakan_a)
xbar_b = mean(pakan_b)
sd_ab = sd(c(pakan_a,pakan_b))
sd_a = sd(pakan_a)
sd_b = sd(pakan_b)
print(cbind(xbar_a,sd_a,xbar_b,sd_b,sd_ab))
## xbar_a sd_a xbar_b sd_b sd_ab
## [1,] 4.26 0.4835057 5.583333 1.339493 1.222658
t.test(pakan_a, pakan_b,var.equal = T)
##
## Two Sample t-test
##
## data: pakan_a and pakan_b
## t = -2.9575, df = 20, p-value = 0.007784
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.2566851 -0.3899816
## sample estimates:
## mean of x mean of y
## 4.260000 5.583333
Perbedaan produktivitas susu dari sapi dengan pakan B lebih besar dari A dengan selisih [-2.2566851, -0.389981].
t.test(pakan_a, pakan_b,var.equal = F)
##
## Welch Two Sample t-test
##
## data: pakan_a and pakan_b
## t = -3.1825, df = 14.282, p-value = 0.006508
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.2135084 -0.4331583
## sample estimates:
## mean of x mean of y
## 4.260000 5.583333
Perbedaan produktivitas susu dari sapi dengan pakan B lebih besar dari A dengan selisih [ -2.2135084, -0.4331583].
Jawaban :
p = 11/200
sigma = sqrt(p*(1-p))
ci_norm(p,sigma, 200)
## ci_lower ci_upper
## [1,] 0.02340355 0.08659645
Selang kepercayaan proporsi kemasan rusak sebesar [0.02340355 ,0.08659645] lebih baik dari yang sebelumnya 10%.
p = 15/40
sigma = sqrt(p*(1-p))
ci_norm(p,sigma, 40)
## ci_lower ci_upper
## [1,] 0.2249688 0.5250312
Jawaban :
prop.test(x = c(275,100),n =c(500,250) )
##
## 2-sample test for equality of proportions with continuity
## correction
##
## data: c(275, 100) out of c(500, 250)
## X-squared = 14.406, df = 1, p-value = 0.0001473
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## 0.07223823 0.22776177
## sample estimates:
## prop 1 prop 2
## 0.55 0.40
Jawaban :
a = c(4.8,4,5,4.6,5.4,4.9,4.3,5.2,5.1,4.7,5.4,5.8)
b = c(5.5,4.1,5.2,4.5,5,5.3,4.8,4.5,6,4.7,5.3,5.4)
t.test(pakan_a, pakan_b,var.equal = F)
##
## Welch Two Sample t-test
##
## data: pakan_a and pakan_b
## t = -3.1825, df = 14.282, p-value = 0.006508
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.2135084 -0.4331583
## sample estimates:
## mean of x mean of y
## 4.260000 5.583333