Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hitung zCImean confidence interval
- # Confidence Interval calculation, Normal distribution (Z)
- #
- # Sunu Pradana
- # Samarinda, Indonesia, Agustus 2014
- #
- # Creative Commons Attribution-ShareAlike 4.0
- #
- # Usage (contoh penggunaan):
- # zCImean(95,10,2,33)
- #
- #
- # CI = confidence interval (arbitrary, usually, 90, 95, or 99)
- # xbar1 = point estimate of population mean by sample mean
- # sigma = population standard deviation
- # n = Jumlah sample (sample size)
- #
- #
- #
- #
- zCImean <- function(CI, xbar, sigma, n){
- alpha = CI/100
- two.tail.alpha <- alpha/2
- two.tail.alpha <- 1-alpha
- one.tail.alpha <- two.tail.alpha/2
- left.tail.alpha <- one.tail.alpha
- right.tail.alpha <- 1-one.tail.alpha
- left.z.value <- qnorm(left.tail.alpha)
- right.z.value <- qnorm(right.tail.alpha)
- left.val <- xbar - ( sqrt(left.z.value^2) * ( sigma/sqrt(n) ) )
- right.val <- xbar + ( right.z.value * ( sigma/sqrt(n) ) )
- difr <- ( right.z.value * ( sigma/sqrt(n) ) )
- cat("\n")
- cat( sprintf("CI, xbar, sigma, n" ),fill = TRUE )
- cat("\n")
- cat( sprintf("%-33s %1s % 5.3f ", "alpha", ":", alpha ),fill = TRUE )
- cat( sprintf("%-33s %1s % 5.3f ", "two.tail.alpha", ":", two.tail.alpha ),fill = TRUE )
- cat( sprintf("%-33s %1s % 5.3f ", "one.tail.alpha", ":", one.tail.alpha ),fill = TRUE )
- cat("\n")
- cat( sprintf("%-33s %1s % 5.6g ", "left.z.value", ":", left.z.value ),fill = TRUE )
- cat( sprintf("%-33s %1s % 5.6g ", "left.z.value", ":", round(left.z.value,2) ),fill = TRUE )
- cat("\n")
- cat( sprintf("%-33s %1s % 5.6g ", "right.z.value", ":", right.z.value ),fill = TRUE )
- cat( sprintf("%-33s %1s % 5.6g ", "right.z.value", ":", round(right.z.value,2)),fill = TRUE )
- cat("\n")
- cat( sprintf("%-33s %1s % 4.6g ", "differ val", ":", round(difr,1)),fill = TRUE )
- cat("\n")
- cat( sprintf("%-33s %1s % 5.6g %12s %-5.4g %-2s ", "left.val", ":", left.val, " [rounded: ", round(left.val,1), "]" ),fill = TRUE )
- cat( sprintf("%-33s %1s % 5.6g ", "Point estimate of population mean", ":", xbar ),fill = TRUE )
- cat( sprintf("%-33s %1s % 5.6g %12s %-5.4g %-2s ", "right.val", ":", right.val, " [rounded: ", round(right.val,1),"]" ),fill = TRUE )
- cat("\n")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement