Misal ingin diketahui Y = pengeluaran bulanan untuk print tugas akhir mahasiswa S1, S2, dan S3 di IPB University (dalam Rupiah), dan P = proporsi apakah mahasiswa tersebut memiliki printer pribadi atau tidak.
s = 2022
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(MCPAN)
set.seed(s)
n <- 10000
n1 <- 5000
n2 <- 4000
n3 <- 1000
Y1 <- round(rnorm(n1, 100, 10))
Y2 <- round(rnorm(n2, 500, 20))
Y3 <- round(rnorm(n3, 2000, 50))
P1 <- rbinom(n1, 1, 0.2)
P2 <- rbinom(n2, 1, 0.5)
P3 <- rbinom(n3, 1, 0.8)
r1 <- runif(n1)
r2 <- runif(n2)
r3 <- runif(n3)
S1 <- data.frame(No = c(1:n1),
Y = Y1,
P = P1,
Strata = rep('1', n1),
R = r1)
S2 <- data.frame(No = c(1:n2),
Y = Y2,
P = P2,
Strata = rep('2', n2),
R = r2)
S3 <- data.frame(No = c(1:n3),
Y = Y3,
P = P3,
Strata = rep('3', n3),
R = r3)
No <- c(1:n)
Data <- rbind(S1[,c('Strata', 'Y', 'P', 'R')], S2[,c('Strata', 'Y', 'P', 'R')], S3[,c('Strata', 'Y', 'P', 'R')])
Data <- Data[order(Data$R), ]
DataS <- cbind(No, Data[,c('Strata', 'Y', 'P')])
DataS1 <- S1[,c('No', 'Strata', 'Y', 'P')]
DataS2 <- S2[,c('No', 'Strata', 'Y', 'P')]
DataS3 <- S3[,c('No', 'Strata', 'Y', 'P')]
Data ditampilkan 10 teratas sebagai berikut:
head(DataS, 10); head(DataS1, 10); head(DataS2, 10); head(DataS3, 10)
## No Strata Y P
## 7405 1 2 465 0
## 5309 2 2 483 1
## 882 3 1 106 0
## 1105 4 1 101 1
## 5552 5 2 501 0
## 4762 6 1 92 0
## 6219 7 2 504 0
## 510 8 1 106 0
## 5757 9 2 531 1
## 4330 10 1 102 0
## No Strata Y P
## 1 1 1 109 1
## 2 2 1 88 1
## 3 3 1 91 0
## 4 4 1 86 0
## 5 5 1 97 0
## 6 6 1 71 0
## 7 7 1 89 0
## 8 8 1 103 0
## 9 9 1 107 0
## 10 10 1 102 0
## No Strata Y P
## 1 1 2 536 1
## 2 2 2 501 0
## 3 3 2 480 1
## 4 4 2 479 1
## 5 5 2 497 1
## 6 6 2 457 1
## 7 7 2 484 1
## 8 8 2 485 0
## 9 9 2 510 0
## 10 10 2 500 0
## No Strata Y P
## 1 1 3 2112 1
## 2 2 3 2028 1
## 3 3 3 2072 1
## 4 4 3 1962 1
## 5 5 3 2014 1
## 6 6 3 2076 1
## 7 7 3 1991 1
## 8 8 3 1886 0
## 9 9 3 2055 0
## 10 10 3 2025 1
sampling <- function(n, data) {
set.seed(s)
u <- c(runif(nrow(data)))
data_new <- cbind(data, u)
data_new <- data_new[order(data_new$u), ]
data_new <- head(data_new, n)
return(data_new[, c('No', 'Strata', 'Y', 'P')])
}
estimate_mean <- function(data, N){
n <- length(data)
var_data <- var(data)
mean <- sum(data)/n
var_mean <- (var_data/n)*(1-n/N)
sd_mean <- sqrt(var_mean)
confint_mean <- c(mean-qnorm(0.975, 0, 1)*sd_mean,
mean+qnorm(0.975, 0, 1)*sd_mean)
return(list(mean = mean, var_mean = var_mean, sd_mean = sd_mean, confint_mean = confint_mean))
}
estimate_proportion <- function(data, N){
n <- length(data)
prop <- sum(data)/n
var_prop <- (prop*(1-prop)/(n-1))*(1-n/N)
sd_prop <- sqrt(var_prop)
confint_prop <- c(prop-qnorm(0.975, 0, 1)*sd_prop,
prop+qnorm(0.975, 0, 1)*sd_prop)
return(list(prop = prop, var_prop = var_prop, sd_prop = sd_prop, confint_prop = confint_prop))
}
srsampling <- function(n, N, data) {
data_sampling <- sampling(n, data)
mean <- estimate_mean(data_sampling$Y, N)
proportion <- estimate_proportion(data_sampling$P, N)
#browser()
#cat('Ukuran populasi : ', N, '\n')
#cat('Ukuran contoh : ', n, '\n')
#cat('Dugaan rata-rata : ', mean$mean, '\n')
#cat('Dugaan ragam rata-rata : ', mean$var_mean, '\n')
#cat('Dugaan simpangan baku rata-rata : ', mean$sd_mean, '\n')
#cat('Dugaan selang kepercayaan 95% bagi rata-rata : ', mean$confint_mean, '\n')
#cat('Dugaan proporsi : ', proportion$prop, '\n')
#cat('Dugaan ragam proporsi : ', proportion$var_prop, '\n')
#cat('Dugaan simpangan baku proporsi : ', proportion$sd_prop, '\n')
#cat('Dugaan selang kepercayaan 95% bagi proporsi : ', proportion$confint_prop, '\n')
df <- data.frame(Method = 'SRS',
N = N,
n = n,
Mean = round(mean$mean,3),
Lower_Mean = round(mean$confint_mean[1],3),
Upper_Mean = round(mean$confint_mean[2],3),
V_Mean = round(mean$var_mean,3),
SD_Mean = round(mean$sd_mean,3),
Prop = round(proportion$prop,3),
Lower_Prop = round(proportion$confint_prop[1],3),
Upper_Prop = round(proportion$confint_prop[2],3),
V_Prop = round(proportion$var_prop,3),
SD_Prop = round(proportion$sd_prop,3))
return(list(data_sampling=data_sampling, result=df))
}
SRS_DataS1 <- srsampling(40, n1, DataS1)
SRS_DataS2 <- srsampling(40, n2, DataS2)
SRS_DataS3 <- srsampling(40, n3, DataS3)
strsampling <- function(n, alokasi){
N1 <- 5000; N2 <- 4000; N3 <- 1000; N <- 10000
if (alokasi == 'seragam'){
n1 <- n/3; n2 <- n/3; n3 <- n/3
} else if(alokasi == 'proporsional'){
n1 <- N1/N*n; n2 <- N2/N*n; n3 <- N3/N*n
}
w1 <- N1/n1; w2 <- N2/n2; w3 <- N3/n3
s1 <- srsampling(n1, N1, DataS1)
s2 <- srsampling(n2, N2, DataS2)
s3 <- srsampling(n3, N3, DataS3)
mean <- 1/N*(N1*s1$result$Mean + N2*s2$result$Mean + N3*s3$result$Mean)
var_mean <- 1/N^2*(N1^2*s1$result$V_Mean + N2^2*s2$result$V_Mean + N3^2*s3$result$V_Mean)
sd_mean <- sqrt(var_mean)
prop <- 1/N*(N1*s1$result$Prop + N2*s2$result$Prop + N3*s3$result$Prop)
var_prop <- 1/N^2*(N1^2*s1$result$V_Prop + N2^2*s2$result$V_Prop + N3^2*s3$result$V_Prop)
sd_prop <- sqrt(var_prop)
confint_mean <- c(mean-qnorm(0.975, 0, 1)*sd_mean,
mean+qnorm(0.975, 0, 1)*sd_mean)
confint_prop <- c(prop-qnorm(0.975, 0, 1)*sd_prop,
prop+qnorm(0.975, 0, 1)*sd_prop)
#print('---- Stratified Random Sampling ----')
#cat('Ukuran populasi : ', N, '\n')
#cat('Ukuran contoh : ', n, '\n')
#cat('Dugaan rata-rata : ', mean, '\n')
#cat('Dugaan ragam rata-rata : ', var_mean, '\n')
#cat('Dugaan simpangan baku rata-rata : ', sd_mean, '\n')
#cat('Dugaan selang kepercayaan rata-rata : ', confint_mean, '\n')
#cat('Dugaan proporsi : ', prop, '\n')
#cat('Dugaan ragam proporsi : ', var_prop, '\n')
#cat('Dugaan simpangan baku proporsi : ', sd_prop, '\n')
#cat('Dugaan selang kepercayaan proporsi : ', confint_prop, '\n')
#browser()
df <- data.frame(Method = paste0('STR ', alokasi),
N = N,
n = n,
Mean = round(mean,3),
Lower_Mean = round(confint_mean[1],3),
Upper_Mean = round(confint_mean[2],3),
V_Mean = round(var_mean,3),
SD_Mean = round(sd_mean),
Prop = round(prop,3),
Lower_Prop = round(confint_prop[1],3),
Upper_Prop = round(confint_prop[2],3),
V_Prop = round(var_prop,3),
SD_Prop = round(sd_prop,3))
return(list(data1 = s1$data_sampling, data2 = s2$data_sampling, data3 = s3$data_sampling, result = df))
}
library(mase)
strsampling_HT <- function(n, alokasi){
N1 <- 5000; N2 <- 4000; N3 <- 1000; N <- 10000
if (alokasi == 'seragam'){
n1 <- n/3; n2 <- n/3; n3 <- n/3
} else if(alokasi == 'proporsional'){
n1 <- N1/N*n; n2 <- N2/N*n; n3 <- N3/N*n
}
p1 <- n1/N1; p2 <- n2/N2; p3 <- n3/N3
s1 <- srsampling(n1, N1, DataS1)
s2 <- srsampling(n2, N2, DataS2)
s3 <- srsampling(n3, N3, DataS3)
ps <- c(rep(p1, n1), rep(p2, n2), rep(p3, n3))
sm1 <- c(s1$data_sampling$Y, s2$data_sampling$Y, s3$data_sampling$Y)
mest <- horvitzThompson(sm1, ps, N, var_est = T)
sm2 <- c(s1$data_sampling$P, s2$data_sampling$P, s3$data_sampling$P)
pest <- horvitzThompson(sm2, ps, N, var_est = T)
mean <- mest$pop_mean
prop <- pest$pop_mean
var_mean <- mest$pop_mean_var
var_prop <- pest$pop_mean_var
sd_mean <- sqrt(var_mean)
sd_prop <- sqrt(var_prop)
confint_mean <- c(mean-qnorm(0.975, 0, 1)*sd_mean,
mean+qnorm(0.975, 0, 1)*sd_mean)
confint_prop <- c(prop-qnorm(0.975, 0, 1)*sd_prop,
prop+qnorm(0.975, 0, 1)*sd_prop)
#print('---- Stratified Random Sampling ----')
#cat('Ukuran populasi : ', N, '\n')
#cat('Ukuran contoh : ', n, '\n')
#cat('Dugaan rata-rata : ', mean, '\n')
#cat('Dugaan ragam rata-rata : ', var_mean, '\n')
#cat('Dugaan simpangan baku rata-rata : ', sd_mean, '\n')
#cat('Dugaan selang kepercayaan rata-rata : ', confint_mean, '\n')
#cat('Dugaan proporsi : ', prop, '\n')
#cat('Dugaan ragam proporsi : ', var_prop, '\n')
#cat('Dugaan simpangan baku proporsi : ', sd_prop, '\n')
#cat('Dugaan selang kepercayaan proporsi : ', confint_prop, '\n')
#browser()
df <- data.frame(Method = paste0('STR HT ', alokasi),
N = N,
n = n,
Mean = round(mean,3),
Lower_Mean = round(confint_mean[1],3),
Upper_Mean = round(confint_mean[2],3),
V_Mean = round(var_mean,3),
SD_Mean = round(sd_mean),
Prop = round(prop,3),
Lower_Prop = round(confint_prop[1],3),
Upper_Prop = round(confint_prop[2],3),
V_Prop = round(var_prop,3),
SD_Prop = round(sd_prop,3))
return(list(data1 = s1$data_sampling, data2 = s2$data_sampling, data3 = s3$data_sampling, result = df))
}
# Populasi
Populasi <- data.frame(Method = 'Populasi',
N = 10000,
n = "-",
Mean = round(mean(DataS$Y),3),
Lower_Mean = "-",
Upper_Mean = "-",
V_Mean = round(var(DataS$Y)/10000,3),
SD_Mean = round(sqrt(var(DataS$Y)/10000),3),
Prop = round(sum(DataS$P)/10000,3),
Lower_Prop = "-",
Upper_Prop = "-",
V_Prop = round((sum(DataS$P)/10000)*(1-sum(DataS$P)/10000)/10000,3),
SD_Prop = round(sqrt((sum(DataS$P)/10000)*(1-sum(DataS$P)/10000)/10000),3))
# n = 120
SRS_DataS120 <- srsampling(120, 10000, DataS)
STR_Proporsional120 <- strsampling(120, 'proporsional')
STR_Seragam120 <- strsampling(120, "seragam")
STRHT_Seragam120 <- strsampling_HT(120, "seragam")
STRHT_Proporsional120 <- strsampling_HT(120, "proporsional")
# n = 300
SRS_DataS300 <- srsampling(300, 10000, DataS)
STR_Proporsional300 <- strsampling(300, 'proporsional')
STR_Seragam300 <- strsampling(300, "seragam")
STRHT_Seragam300 <- strsampling_HT(300, "seragam")
STRHT_Proporsional300 <- strsampling_HT(300, "proporsional")
# n = 30
SRS_DataS30 <- srsampling(30, 10000, DataS)
STR_Proporsional30 <- strsampling(30, 'proporsional')
STR_Seragam30 <- strsampling(30, "seragam")
STRHT_Seragam30 <- strsampling_HT(30, "seragam")
STRHT_Proporsional30 <- strsampling_HT(30, "proporsional")
# n = 600
SRS_DataS600 <- srsampling(600, 10000, DataS)
STR_Proporsional600 <- strsampling(600, 'proporsional')
STR_Seragam600 <- strsampling(600, "seragam")
STRHT_Seragam600 <- strsampling_HT(600, "seragam")
STRHT_Proporsional600 <- strsampling_HT(600, "proporsional")
# function
getmiuprop <- function(data_y, data_p){
n <- length(data_y)
y <- mean(data_y); vy <- var(data_y)
p <- mean(data_p); vp <- p*(1-p)
return(c(n, round(c(y, sqrt(vy), p, sqrt(vp)), 3)))
}
# all
All <- getmiuprop(DataS$Y, DataS$P)
# s1_all
S1 <- getmiuprop(DataS1$Y, DataS1$P)
# s2_all
S2 <- getmiuprop(DataS2$Y, DataS2$P)
# s3_all
S3 <- getmiuprop(DataS3$Y, DataS3$P)
# df
dfs <- data.frame(rbind(All, S1, S2, S3))
colnames(dfs) <- c('n', 'Mean', 'SB_Mean', 'Prop', 'SB_Prop')
dfs
## n Mean SB_Mean Prop SB_Prop
## All 10000 449.856 550.527 0.390 0.488
## S1 5000 100.000 9.984 0.212 0.409
## S2 4000 499.548 19.929 0.507 0.500
## S3 1000 2000.363 49.710 0.808 0.394
# s1
S1_STRS30 <- getmiuprop(STR_Seragam30$data1$Y, STR_Seragam30$data1$P)
# s2
S2_STRS30 <- getmiuprop(STR_Seragam30$data2$Y, STR_Seragam30$data2$P)
# s3
S3_STRS30 <- getmiuprop(STR_Seragam30$data3$Y, STR_Seragam30$data3$P)
# df
dfs_strs30 <- data.frame(rbind(S1_STRS30, S2_STRS30, S3_STRS30))
colnames(dfs_strs30) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strs30) <- c('S1 STRS', 'S2 STRS', 'S3 STRS')
dfs_strs30
## n Mean SD_Mean Prop SD_Prop
## S1 STRS 10 103.0 11.991 0.1 0.300
## S2 STRS 10 505.0 23.641 0.7 0.458
## S3 STRS 10 1983.8 54.195 0.7 0.458
# s1
S1_STRS120 <- getmiuprop(STR_Seragam120$data1$Y, STR_Seragam120$data1$P)
# s2
S2_STRS120 <- getmiuprop(STR_Seragam120$data2$Y, STR_Seragam120$data2$P)
# s3
S3_STRS120 <- getmiuprop(STR_Seragam120$data3$Y, STR_Seragam120$data3$P)
# df
dfs_strs120 <- data.frame(rbind(S1_STRS120, S2_STRS120, S3_STRS120))
colnames(dfs_strs120) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strs120) <- c('S1 STRS', 'S2 STRS', 'S3 STRS')
dfs_strs120
## n Mean SD_Mean Prop SD_Prop
## S1 STRS 40 100.80 10.371 0.275 0.447
## S2 STRS 40 499.90 20.928 0.575 0.494
## S3 STRS 40 1998.75 57.769 0.800 0.400
# s1
S1_STRS300 <- getmiuprop(STR_Seragam300$data1$Y, STR_Seragam300$data1$P)
# s2
S2_STRS300 <- getmiuprop(STR_Seragam300$data2$Y, STR_Seragam300$data2$P)
# s3
S3_STRS300 <- getmiuprop(STR_Seragam300$data3$Y, STR_Seragam300$data3$P)
# df
dfs_strs300 <- data.frame(rbind(S1_STRS300, S2_STRS300, S3_STRS300))
colnames(dfs_strs300) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strs300) <- c('S1 STRS', 'S2 STRS', 'S3 STRS')
dfs_strs300
## n Mean SD_Mean Prop SD_Prop
## S1 STRS 100 100.50 9.870 0.28 0.449
## S2 STRS 100 499.72 20.631 0.50 0.500
## S3 STRS 100 2000.30 52.372 0.78 0.414
# s1
S1_STRS600 <- getmiuprop(STR_Seragam600$data1$Y, STR_Seragam600$data1$P)
# s2
S2_STRS600 <- getmiuprop(STR_Seragam600$data2$Y, STR_Seragam600$data2$P)
# s3
S3_STRS600 <- getmiuprop(STR_Seragam600$data3$Y, STR_Seragam600$data3$P)
# df
dfs_strs600 <- data.frame(rbind(S1_STRS600, S2_STRS600, S3_STRS600))
colnames(dfs_strs600) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strs600) <- c('S1 STRS', 'S2 STRS', 'S3 STRS')
dfs_strs600
## n Mean SD_Mean Prop SD_Prop
## S1 STRS 200 101.340 9.898 0.275 0.447
## S2 STRS 200 499.625 19.935 0.525 0.499
## S3 STRS 200 2000.635 50.725 0.805 0.396
names2 <- c('30', '120', '300', '600')
x1 <- c(S1_STRS30[2], S1_STRS120[2], S1_STRS300[2], S1_STRS600[2])
l1 <- c(S1_STRS30[2]-2*S1_STRS30[3], S1_STRS120[2]-2*S1_STRS120[3], S1_STRS300[2]-2*S1_STRS300[3], S1_STRS600[2]-2*S1_STRS600[3])
u1 <- c(S1_STRS30[2]+2*S1_STRS30[3], S1_STRS120[2]+2*S1_STRS120[3], S1_STRS300[2]+2*S1_STRS300[3], S1_STRS600[2]+2*S1_STRS600[3])
names(x1) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x1, lower = l1, upper = u1, lines=S1[2], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 1 Metode Stratified Seragam", ylab='Dugaan rata-rata', xlab='Ukuran contoh')
p1 <- c(S1_STRS30[4], S1_STRS120[4], S1_STRS300[4], S1_STRS600[4])
l1 <- c(S1_STRS30[4]-2*S1_STRS30[5], S1_STRS120[5]-2*S1_STRS120[5], S1_STRS300[4]-2*S1_STRS300[5], S1_STRS600[4]-2*S1_STRS600[5])
u1 <- c(S1_STRS30[4]+2*S1_STRS30[5], S1_STRS120[4]+2*S1_STRS120[5], S1_STRS300[4]+2*S1_STRS300[5], S1_STRS600[4]+2*S1_STRS600[5])
names(p1) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
plotCII(p1, lower = l1, upper = u1, lines=S1[4], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 1 Metode Stratified Seragam", ylab='Dugaan proporsi', xlab='Ukuran contoh')
names2 <- c('30', '120', '300', '600')
x2 <- c(S2_STRS30[2], S2_STRS120[2], S2_STRS300[2], S2_STRS600[2])
l2 <- c(S2_STRS30[2]-2*S2_STRS30[3], S2_STRS120[2]-2*S2_STRS120[3], S2_STRS300[2]-2*S2_STRS300[3], S2_STRS600[2]-2*S2_STRS600[3])
u2 <- c(S2_STRS30[2]+2*S2_STRS30[3], S2_STRS120[2]+2*S2_STRS120[3], S2_STRS300[2]+2*S2_STRS300[3], S2_STRS600[2]+2*S2_STRS600[3])
names(x2) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x2, lower = l2, upper = u2, lines=S2[2], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 2 Metode Stratified Seragam", ylab='Dugaan rata-rata', xlab='Ukuran contoh')
p2 <- c(S2_STRS30[4], S2_STRS120[4], S2_STRS300[4], S2_STRS600[4])
l2 <- c(S2_STRS30[4]-2*S2_STRS30[5], S2_STRS120[5]-2*S2_STRS120[5], S2_STRS300[4]-2*S2_STRS300[5], S2_STRS600[4]-2*S2_STRS600[5])
u2 <- c(S2_STRS30[4]+2*S2_STRS30[5], S2_STRS120[4]+2*S2_STRS120[5], S2_STRS300[4]+2*S2_STRS300[5], S2_STRS600[4]+2*S2_STRS600[5])
names(p2) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
plotCII(p2, lower = l2, upper = u2, lines=S2[4], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 2 Metode Stratified Seragam", ylab='Dugaan proporsi', xlab='Ukuran contoh')
names2 <- c('30', '120', '300', '600')
x3 <- c(S3_STRS30[2], S3_STRS120[2], S3_STRS300[2], S3_STRS600[2])
l3 <- c(S3_STRS30[2]-2*S3_STRS30[3], S3_STRS120[2]-2*S3_STRS120[3], S3_STRS300[2]-2*S3_STRS300[3], S3_STRS600[2]-2*S3_STRS600[3])
u3 <- c(S3_STRS30[2]+2*S3_STRS30[3], S3_STRS120[2]+2*S3_STRS120[3], S3_STRS300[2]+2*S3_STRS300[3], S3_STRS600[2]+2*S3_STRS600[3])
names(x3) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x3, lower = l3, upper = u3, lines=S3[2], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 3 Metode Stratified Seragam", ylab='Dugaan rata-rata', xlab='Ukuran contoh')
p3 <- c(S3_STRS30[4], S3_STRS120[4], S3_STRS300[4], S3_STRS600[4])
l3 <- c(S3_STRS30[4]-2*S3_STRS30[5], S3_STRS120[5]-2*S3_STRS120[5], S3_STRS300[4]-2*S3_STRS300[5], S3_STRS600[4]-2*S3_STRS600[5])
u3 <- c(S3_STRS30[4]+2*S3_STRS30[5], S3_STRS120[4]+2*S3_STRS120[5], S3_STRS300[4]+2*S3_STRS300[5], S3_STRS600[4]+2*S3_STRS600[5])
names(p3) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
plotCII(p3, lower = l3, upper = u3, lines=S3[4], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 3 Metode Stratified Seragam", ylab='Dugaan proporsi', xlab='Ukuran contoh')
# s1
S1_STRP30 <- getmiuprop(STR_Proporsional30$data1$Y, STR_Proporsional30$data1$P)
# s2
S2_STRP30 <- getmiuprop(STR_Proporsional30$data2$Y, STR_Proporsional30$data2$P)
# s3
S3_STRP30 <- getmiuprop(STR_Proporsional30$data3$Y, STR_Proporsional30$data3$P)
# df
dfs_strp30 <- data.frame(rbind(S1_STRP30, S2_STRP30, S3_STRP30))
colnames(dfs_strp30) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strp30) <- c('S1 STRP', 'S2 STRP', 'S3 STRP')
dfs_strp30
## n Mean SD_Mean Prop SD_Prop
## S1 STRP 15 100.133 11.801 0.067 0.249
## S2 STRP 12 499.250 26.721 0.750 0.433
## S3 STRP 3 2022.333 23.861 0.667 0.471
# s1
S1_STRP120 <- getmiuprop(STR_Proporsional120$data1$Y, STR_Proporsional120$data1$P)
# s2
S2_STRP120 <- getmiuprop(STR_Proporsional120$data2$Y, STR_Proporsional120$data2$P)
# s3
S3_STRP120 <- getmiuprop(STR_Proporsional120$data3$Y, STR_Proporsional120$data3$P)
# df
dfs_strp120 <- data.frame(rbind(S1_STRP120, S2_STRP120, S3_STRP120))
colnames(dfs_strp120) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strp120) <- c('S1 STRP', 'S2 STRP', 'S3 STRP')
dfs_strp120
## n Mean SD_Mean Prop SD_Prop
## S1 STRP 60 100.867 10.465 0.317 0.465
## S2 STRP 48 500.875 21.833 0.583 0.493
## S3 STRP 12 1992.333 53.125 0.750 0.433
# s1
S1_STRP300 <- getmiuprop(STR_Proporsional300$data1$Y, STR_Proporsional300$data1$P)
# s2
S2_STRP300 <- getmiuprop(STR_Proporsional300$data2$Y, STR_Proporsional300$data2$P)
# s3
S3_STRP300 <- getmiuprop(STR_Proporsional300$data3$Y, STR_Proporsional300$data3$P)
# df
dfs_strp300 <- data.frame(rbind(S1_STRP300, S2_STRP300, S3_STRP300))
colnames(dfs_strp300) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strp300) <- c('S1 STRP', 'S2 STRP', 'S3 STRP')
dfs_strp300
## n Mean SD_Mean Prop SD_Prop
## S1 STRP 150 100.960 9.811 0.287 0.452
## S2 STRP 120 499.008 21.171 0.525 0.499
## S3 STRP 30 1989.500 55.812 0.800 0.400
# s1
S1_STRP600 <- getmiuprop(STR_Proporsional600$data1$Y, STR_Proporsional600$data1$P)
# s2
S2_STRP600 <- getmiuprop(STR_Proporsional600$data2$Y, STR_Proporsional600$data2$P)
# s3
S3_STRP600 <- getmiuprop(STR_Proporsional600$data3$Y, STR_Proporsional600$data3$P)
# df
dfs_strp600 <- data.frame(rbind(S1_STRP600, S2_STRP600, S3_STRP600))
colnames(dfs_strp600) <- c('n', 'Mean', 'SD_Mean', 'Prop', 'SD_Prop')
rownames(dfs_strp600) <- c('S1 STRP', 'S2 STRP', 'S3 STRP')
dfs_strp600
## n Mean SD_Mean Prop SD_Prop
## S1 STRP 300 100.587 9.902 0.260 0.439
## S2 STRP 240 500.292 20.070 0.517 0.500
## S3 STRP 60 1994.933 55.328 0.767 0.423
names2 <- c('30', '120', '300', '600')
x1 <- c(S1_STRP30[2], S1_STRP120[2], S1_STRP300[2], S1_STRP600[2])
l1 <- c(S1_STRP30[2]-2*S1_STRP30[3], S1_STRP120[2]-2*S1_STRP120[3], S1_STRP300[2]-2*S1_STRP300[3], S1_STRP600[2]-2*S1_STRP600[3])
u1 <- c(S1_STRP30[2]+2*S1_STRP30[3], S1_STRP120[2]+2*S1_STRP120[3], S1_STRP300[2]+2*S1_STRP300[3], S1_STRP600[2]+2*S1_STRP600[3])
names(x1) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x1, lower = l1, upper = u1, lines=S1[2], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 1 Metode Stratified Proporsional", ylab='Dugaan rata-rata', xlab='Ukuran contoh')
p1 <- c(S1_STRP30[4], S1_STRP120[4], S1_STRP300[4], S1_STRP600[4])
l1 <- c(S1_STRP30[4]-2*S1_STRP30[5], S1_STRP120[5]-2*S1_STRP120[5], S1_STRP300[4]-2*S1_STRP300[5], S1_STRP600[4]-2*S1_STRP600[5])
u1 <- c(S1_STRP30[4]+2*S1_STRP30[5], S1_STRP120[4]+2*S1_STRP120[5], S1_STRP300[4]+2*S1_STRP300[5], S1_STRP600[4]+2*S1_STRP600[5])
names(p1) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
plotCII(p1, lower = l1, upper = u1, lines=S1[4], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 1 Metode Stratified Proporsional", ylab='Dugaan proporsi', xlab='Ukuran contoh')
names2 <- c('30', '120', '300', '600')
x2 <- c(S2_STRP30[2], S2_STRP120[2], S2_STRP300[2], S2_STRP600[2])
l2 <- c(S2_STRP30[2]-2*S2_STRP30[3], S2_STRP120[2]-2*S2_STRP120[3], S2_STRP300[2]-2*S2_STRP300[3], S2_STRP600[2]-2*S2_STRP600[3])
u2 <- c(S2_STRP30[2]+2*S2_STRP30[3], S2_STRP120[2]+2*S2_STRP120[3], S2_STRP300[2]+2*S2_STRP300[3], S2_STRP600[2]+2*S2_STRP600[3])
names(x2) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x2, lower = l2, upper = u2, lines=S2[2], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 2 Metode Stratified Proporsional", ylab='Dugaan rata-rata', xlab='Ukuran contoh')
p2 <- c(S2_STRP30[4], S2_STRP120[4], S2_STRP300[4], S2_STRP600[4])
l2 <- c(S2_STRP30[4]-2*S2_STRP30[5], S2_STRP120[5]-2*S2_STRP120[5], S2_STRP300[4]-2*S2_STRP300[5], S2_STRP600[4]-2*S2_STRP600[5])
u2 <- c(S2_STRP30[4]+2*S2_STRP30[5], S2_STRP120[4]+2*S2_STRP120[5], S2_STRP300[4]+2*S2_STRP300[5], S2_STRP600[4]+2*S2_STRP600[5])
names(p2) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
plotCII(p2, lower = l2, upper = u2, lines=S2[4], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 2 Metode Stratified Proporsional", ylab='Dugaan proporsi', xlab='Ukuran contoh')
names2 <- c('30', '120', '300', '600')
x3 <- c(S3_STRP30[2], S3_STRP120[2], S3_STRP300[2], S3_STRP600[2])
l3 <- c(S3_STRP30[2]-2*S3_STRP30[3], S3_STRP120[2]-2*S3_STRP120[3], S3_STRP300[2]-2*S3_STRP300[3], S3_STRP600[2]-2*S3_STRP600[3])
u3 <- c(S3_STRP30[2]+2*S3_STRP30[3], S3_STRP120[2]+2*S3_STRP120[3], S3_STRP300[2]+2*S3_STRP300[3], S3_STRP600[2]+2*S3_STRP600[3])
names(x3) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x3, lower = l3, upper = u3, lines=S3[2], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 3 Metode Stratified Proporsional", ylab='Dugaan rata-rata', xlab='Ukuran contoh')
p3 <- c(S3_STRP30[4], S3_STRP120[4], S3_STRP300[4], S3_STRP600[4])
l3 <- c(S3_STRP30[4]-2*S3_STRP30[5], S3_STRP120[5]-2*S3_STRP120[5], S3_STRP300[4]-2*S3_STRP300[5], S3_STRP600[4]-2*S3_STRP600[5])
u3 <- c(S3_STRP30[4]+2*S3_STRP30[5], S3_STRP120[4]+2*S3_STRP120[5], S3_STRP300[4]+2*S3_STRP300[5], S3_STRP600[4]+2*S3_STRP600[5])
names(p3) <- names2
cols <- c('blue', 'coral', 'green', 'purple')
plotCII(p3, lower = l3, upper = u3, lines=S3[4], CIvert = T, linescol='grey', CIcol = cols, lineslwd = 1.5, CIlwd = 3, main = "Perbandingan Strata 3 Metode Stratified Proporsional", ylab='Dugaan proporsi', xlab='Ukuran contoh')
Hasil30 <- rbind(Populasi,
SRS_DataS30$result, STR_Seragam30$result, STRHT_Seragam30$result, STR_Proporsional30$result, STRHT_Proporsional30$result)
Hasil30
## Method N n Mean Lower_Mean Upper_Mean V_Mean SD_Mean
## 1 Populasi 10000 - 449.856 - - 30.308 5.505
## 2 SRS 10000 30 451.467 247.656 655.277 10813.262 103.987
## 3 STR seragam 10000 30 451.880 444.185 459.575 15.415 4.000
## 4 STR HT seragam 10000 30 451.880 375.098 528.662 1534.688 39.000
## 5 STR proporsional 10000 30 452.000 444.746 459.254 13.698 4.000
## 6 STR HT proporsional 10000 30 452.000 249.741 654.259 10649.250 103.000
## Prop Lower_Prop Upper_Prop V_Prop SD_Prop
## 1 0.39 - - 0.000 0.005
## 2 0.50 0.318 0.682 0.009 0.093
## 3 0.40 0.243 0.557 0.006 0.080
## 4 0.40 0.21 0.59 0.009 0.097
## 5 0.40 0.264 0.536 0.005 0.069
## 6 0.40 0.222 0.578 0.008 0.091
Hasil120 <- rbind(Populasi,
SRS_DataS120$result, STR_Seragam120$result, STRHT_Seragam120$result, STR_Proporsional120$result, STRHT_Proporsional120$result)
Hasil120
## Method N n Mean Lower_Mean Upper_Mean V_Mean SD_Mean
## 1 Populasi 10000 - 449.856 - - 30.308 5.505
## 2 SRS 10000 120 436.417 339.535 533.299 2443.372 49.430
## 3 STR seragam 10000 120 450.235 446.728 453.742 3.202 2.000
## 4 STR HT seragam 10000 120 450.235 412.346 488.124 373.715 19.000
## 5 STR proporsional 10000 120 450.017 445.932 454.102 4.344 2.000
## 6 STR HT proporsional 10000 120 450.017 352.141 547.892 2493.752 50.000
## Prop Lower_Prop Upper_Prop V_Prop SD_Prop
## 1 0.390 - - 0.000 0.005
## 2 0.400 0.313 0.487 0.002 0.045
## 3 0.448 0.355 0.54 0.002 0.047
## 4 0.448 0.349 0.546 0.003 0.050
## 5 0.467 0.38 0.554 0.002 0.044
## 6 0.467 0.378 0.556 0.002 0.045
Hasil300 <- rbind(Populasi,
SRS_DataS300$result, STR_Seragam300$result, STRHT_Seragam300$result, STR_Proporsional300$result, STRHT_Proporsional300$result)
Hasil300
## Method N n Mean Lower_Mean Upper_Mean V_Mean SD_Mean
## 1 Populasi 10000 - 449.856 - - 30.308 5.505
## 2 SRS 10000 300 439.840 380.073 499.607 929.881 30.494
## 3 STR seragam 10000 300 450.168 448.067 452.269 1.150 1.000
## 4 STR HT seragam 10000 300 450.168 426.496 473.84 145.869 12.000
## 5 STR proporsional 10000 300 449.033 446.446 451.62 1.742 1.000
## 6 STR HT proporsional 10000 300 449.033 387.949 510.118 971.320 31.000
## Prop Lower_Prop Upper_Prop V_Prop SD_Prop
## 1 0.390 - - 0.000 0.005
## 2 0.390 0.336 0.444 0.001 0.028
## 3 0.418 0.361 0.475 0.001 0.029
## 4 0.418 0.357 0.479 0.001 0.031
## 5 0.434 0.385 0.482 0.001 0.025
## 6 0.433 0.378 0.489 0.001 0.028
Hasil600 <- rbind(Populasi,
SRS_DataS600$result, STR_Seragam600$result, STRHT_Seragam600$result, STR_Proporsional600$result, STRHT_Proporsional600$result)
Hasil600
## Method N n Mean Lower_Mean Upper_Mean V_Mean SD_Mean
## 1 Populasi 10000 - 449.856 - - 30.308 5.505
## 2 SRS 10000 600 426.333 385.615 467.052 431.604 20.775
## 3 STR seragam 10000 600 450.584 449.167 452 0.522 1.000
## 4 STR HT seragam 10000 600 450.584 434.22 466.947 69.708 8.000
## 5 STR proporsional 10000 600 449.904 448.141 451.666 0.809 1.000
## 6 STR HT proporsional 10000 600 449.903 407.288 492.518 472.744 22.000
## Prop Lower_Prop Upper_Prop V_Prop SD_Prop
## 1 0.390 - - 0 0.005
## 2 0.387 0.349 0.424 0 0.019
## 3 0.428 0.388 0.468 0 0.020
## 4 0.428 0.385 0.471 0 0.022
## 5 0.414 0.372 0.455 0 0.021
## 6 0.413 0.375 0.452 0 0.020
names <- c('SRS 30', 'STRS 30', 'STRS-HT 30', 'STRP 30', 'STRP-HT 30',
'SRS 120', 'STRS 120', 'STRS-HT 120', 'STRP 120', 'STRP-HT 120',
'SRS 300', 'STRS 300', 'STRS-HT 300', 'STRP 300', 'STRP-HT 300',
'SRS 600', 'STRS 600', 'STRS-HT 600', 'STRP 600', 'STRP-HT 60')
x30 <- c(SRS_DataS30$result$Mean, STR_Seragam30$result$Mean, STRHT_Seragam30$result$Mean,
STR_Proporsional30$result$Mean, STRHT_Proporsional30$result$Mean)
x120 <- c(SRS_DataS120$result$Mean, STR_Seragam120$result$Mean, STRHT_Seragam120$result$Mean,
STR_Proporsional120$result$Mean, STRHT_Proporsional120$result$Mean)
x300 <- c(SRS_DataS300$result$Mean, STR_Seragam300$result$Mean, STRHT_Seragam300$result$Mean,
STR_Proporsional300$result$Mean, STRHT_Proporsional300$result$Mean)
x600 <- c(SRS_DataS600$result$Mean, STR_Seragam600$result$Mean, STRHT_Seragam600$result$Mean,
STR_Proporsional600$result$Mean, STRHT_Proporsional600$result$Mean)
x <- c(x30, x120, x300, x600)
l30 <- c(SRS_DataS30$result$Lower_Mean, STR_Seragam30$result$Lower_Mean, STRHT_Seragam30$result$Lower_Mean,
STR_Proporsional30$result$Lower_Mean, STRHT_Proporsional30$result$Lower_Mean)
l120 <- c(SRS_DataS120$result$Lower_Mean, STR_Seragam120$result$Lower_Mean, STRHT_Seragam120$result$Lower_Mean,
STR_Proporsional120$result$Lower_Mean, STRHT_Proporsional120$result$Lower_Mean)
l300 <- c(SRS_DataS300$result$Lower_Mean, STR_Seragam300$result$Lower_Mean, STRHT_Seragam300$result$Lower_Mean,
STR_Proporsional300$result$Lower_Mean, STRHT_Proporsional300$result$Lower_Mean)
l600 <- c(SRS_DataS600$result$Lower_Mean, STR_Seragam600$result$Lower_Mean, STRHT_Seragam600$result$Lower_Mean,
STR_Proporsional600$result$Lower_Mean, STRHT_Proporsional600$result$Lower_Mean)
lower <- c(l30, l120, l300, l600)
u30 <- c(SRS_DataS30$result$Upper_Mean, STR_Seragam30$result$Upper_Mean, STRHT_Seragam30$result$Upper_Mean,
STR_Proporsional30$result$Upper_Mean, STRHT_Proporsional30$result$Upper_Mean)
u120 <- c(SRS_DataS120$result$Upper_Mean, STR_Seragam120$result$Upper_Mean, STRHT_Seragam120$result$Upper_Mean,
STR_Proporsional120$result$Upper_Mean, STRHT_Proporsional120$result$Upper_Mean)
u300 <- c(SRS_DataS300$result$Upper_Mean, STR_Seragam300$result$Upper_Mean, STRHT_Seragam300$result$Upper_Mean,
STR_Proporsional300$result$Upper_Mean, STRHT_Proporsional300$result$Upper_Mean)
u600 <- c(SRS_DataS600$result$Upper_Mean, STR_Seragam600$result$Upper_Mean, STRHT_Seragam600$result$Upper_Mean,
STR_Proporsional600$result$Upper_Mean, STRHT_Proporsional600$result$Upper_Mean)
upper <- c(u30, u120, u300, u600)
names(x) <- names
cols <- rep(c('blue', 'coral', 'green', 'purple', 'black'), times = 4)
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(x, lower = lower, upper = upper, lines=Populasi$Mean, CIvert = T, linescol='grey', CIcol = cols, lineslwd = 2, CIlwd = 4, main = "Perbandingan Selang Penduga Rata-rata", ylab='Dugaan Rata-rata')
names2 <- c('SRS 30', 'STRS 30', 'STRS-HT 30', 'STRP 30', 'STRP-HT 30',
'SRS 120', 'STRS 120', 'STRS-HT 120', 'STRP 120', 'STRP-HT 120',
'SRS 300', 'STRS 300', 'STRS-HT 300', 'STRP 300', 'STRP-HT 300',
'SRS 600', 'STRS 600', 'STRS-HT 600', 'STRP 600', 'STRP-HT 60')
p30 <- c(SRS_DataS30$result$Prop, STR_Seragam30$result$Prop, STRHT_Seragam30$result$Prop,
STR_Proporsional30$result$Prop, STRHT_Proporsional30$result$Prop)
p120 <- c(SRS_DataS120$result$Prop, STR_Seragam120$result$Prop, STRHT_Seragam120$result$Prop,
STR_Proporsional120$result$Prop, STRHT_Proporsional120$result$Prop)
p300 <- c(SRS_DataS300$result$Prop, STR_Seragam300$result$Prop, STRHT_Seragam300$result$Prop,
STR_Proporsional300$result$Prop, STRHT_Proporsional300$result$Prop)
p600 <- c(SRS_DataS600$result$Prop, STR_Seragam600$result$Prop, STRHT_Seragam600$result$Prop,
STR_Proporsional600$result$Prop, STRHT_Proporsional600$result$Prop)
p <- c(p30, p120, p300, p600)
lp30 <- c(SRS_DataS30$result$Lower_Prop, STR_Seragam30$result$Lower_Prop, STRHT_Seragam30$result$Lower_Prop,
STR_Proporsional30$result$Lower_Prop, STRHT_Proporsional30$result$Lower_Prop)
lp120 <- c(SRS_DataS120$result$Lower_Prop, STR_Seragam120$result$Lower_Prop, STRHT_Seragam120$result$Lower_Prop,
STR_Proporsional120$result$Lower_Prop, STRHT_Proporsional120$result$Lower_Prop)
lp300 <- c(SRS_DataS300$result$Lower_Prop, STR_Seragam300$result$Lower_Prop, STRHT_Seragam300$result$Lower_Prop,
STR_Proporsional300$result$Lower_Prop, STRHT_Proporsional300$result$Lower_Prop)
lp600 <- c(SRS_DataS600$result$Lower_Prop, STR_Seragam600$result$Lower_Prop, STRHT_Seragam600$result$Lower_Prop,
STR_Proporsional600$result$Lower_Prop, STRHT_Proporsional600$result$Lower_Prop)
lowerp <- c(lp30, lp120, lp300, lp600)
up30 <- c(SRS_DataS30$result$Upper_Prop, STR_Seragam30$result$Upper_Prop, STRHT_Seragam30$result$Upper_Prop,
STR_Proporsional30$result$Upper_Prop, STRHT_Proporsional30$result$Upper_Prop)
up120 <- c(SRS_DataS120$result$Upper_Prop, STR_Seragam120$result$Upper_Prop, STRHT_Seragam120$result$Upper_Prop,
STR_Proporsional120$result$Upper_Prop, STRHT_Proporsional120$result$Upper_Prop)
up300 <- c(SRS_DataS300$result$Upper_Prop, STR_Seragam300$result$Upper_Prop, STRHT_Seragam300$result$Upper_Prop,
STR_Proporsional300$result$Upper_Prop, STRHT_Proporsional300$result$Upper_Prop)
up600 <- c(SRS_DataS600$result$Upper_Prop, STR_Seragam600$result$Upper_Prop, STRHT_Seragam600$result$Upper_Prop,
STR_Proporsional600$result$Upper_Prop, STRHT_Proporsional600$result$Upper_Prop)
upperp <- c(up30, up120, up300, up600)
names(p) <- names2
cols <- rep(c('blue', 'coral', 'green', 'purple', 'black'), times = 4)
#x<-binomORci(x=x, n=n, names=c("0","120","240","480","600","720"))
plotCII(p, lower = lowerp, upper = upperp, lines=Populasi$Prop, CIvert = T, linescol='grey', CIcol = cols, lineslwd = 2, CIlwd = 4, main = "Perbandingan Selang Penduga Proporsi", ylab='Dugaan Proporsi')