# R kemungkinan normal (normal probability) V3

Sep 1st, 2014
331
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2.     # Hitung Z score & probability
4.     # Samarinda, Indonesia, Agustus 2014
5.     #
6.     # Creative Commons Attribution-ShareAlike 4.0
7.     #
8.     # Usage (contoh penggunaan):
9.     # mungkin(1, 0, 1, -2, 2)
10.     # mungkin(5, 200, 31, 187.4, 221.2)
11.     #
12.     # sd1 = Population standard deviation
13.     # xbar1 = Population mean
14.     # n1 = Jumlah sample (sample size)
15.     # value1 = left value
16.     # value2 = right value
17.     # Untuk nilai ekstrim (for extrme value), gunakan minimal:
18.     # kiri (left)   = -1E99
19.     # kanan (right) =  1E99
20.
21.
22.     mungkin=function(sd1,xbar1,n1,value1,value2)
23.     {
24.         es1 = sd1/(sqrt(n1))
25.         z1 = (value1-xbar1)/es1
26.         z2 = (value2-xbar1)/es1
27.         kem=pnorm(z2)-pnorm(z1)
28.
29.         cat("\n")
30.         cat( sprintf("%08s % 20.4f
31.       \r%08s % 20.4f
32.       \r%08s % 20.4g
33.       \r\n%08s % 20.4E
34.       \r%08s % 20.4E
35.       \n" ,
36.         "sd1:",sd1,"xbar1:",xbar1,"n1:",n1,"value1:",value1,"value2:",value2), fill = TRUE);
37.
38.        #cat(" \n ");
39.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2f ","Jumlah sample",                   ":", n1,     "[trunc2:]", round(n1,2)),     fill = TRUE )
40.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2f ","Population mean",                 ":", xbar1,  "[trunc2:]", round(xbar1,2)),  fill = TRUE )
41.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2f ","Population standard deviation",   ":", sd1,    "[trunc2:]", round(sd1,2)),    fill = TRUE )
42.         cat("\n")
43.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2E ","Nilai batas kiri (left)",         ":", value1, "[trunc2:]", round(value1,2)), fill = TRUE )
44.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2E ","Nilai batas kanan (right)",       ":", value2, "[trunc2:]", round(value2,2)), fill = TRUE )
45.         cat("\n")
46.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2E ","Standard Error",                  ":", es1,    "[trunc2:]", round(es1,2)),    fill = TRUE )
47.         cat("\n")
48.         cat( sprintf("%-31s %1s % 10.4g %10s % 5.2E ","Nilai Z kritis kiri (left)",      ":", z1,     "[trunc2:]", round(z1,2)),     fill = TRUE )
49.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2E ","Nilai Z kritis kanan (right)",    ":", z2,     "[trunc2:]", round(z2,2)),     fill = TRUE )
50.         cat("\n")
51.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2f ","Nilai kemungkinan (probability)", ":", kem,    "[trunc2:]", round(kem,2)),    fill = TRUE )
52.         cat( sprintf("%-31s %1s % 10.4E %10s % 5.2f ","Nilai kemungkinan dalam persen",  ":", kem*100,"[trunc2:]", round(kem*100,2)),fill = TRUE )
53.         cat("\n")
54.     }