Professional Documents
Culture Documents
NIM : 16221002
1. Boostrap
# Buat dataframe dengan data yang diberikan
data_custom <- data.frame(
Y_custom = c(115, 72, 44, 49, 46, 11, 1, 5, 1, 0, 28, 14, 8, 4, 152, 47, 2, 2,
45, 25, 2, 100, 2, 1, 16, 61, 14, 9, 49, 70, 70, 124, 121, 115, 91, 87, 51, 35,
30, 20, 0, 4, 2, 2, 0, 83, 78, 14, 8, 2, 1, 1, 1, 0, 0, 73, 53, 1, 1, 1, 0, 1),
X1_custom = c(2, 7, 2.5, 6, 3, 4.5, 1, 3, 1.5, 3, 3, 2.5, 4, 3.5, 7.5, 8, 2, 2.5,
8, 6.5, 2.5, 5, 1, 0.5, 8, 3, 3, 5.5, 2, 5, 2, 2, 3, 7.5, 4.5, 7, 5, 4, 2.5, 7.5, 3, 4.5,
1, 3, 3, 7, 6, 4.5, 8, 5, 2, 3, 1, 6.5, 3, 5, 2, 1, 1, 2, 1, 1),
X2_custom = c(5, 11, 12, 11, 14, 14, 5, 9, 3, 1, 7, 9, 8, 9, 16, 16, 0, 3, 6, 12,
6, 12, 0, 2, 4, 8, 8, 5, 7, 0, 7, 17, 11, 20, 18, 20, 35, 35, 8, 24, 9, 0, 3, 2, 5, 13,
11, 14, 8, 5, 3, 2, 1, 12, 0, 11, 6, 3, 5, 2, 0, 0),
X3_custom = c(343, 11, 15, 9, 22, 20, 5, 19, 13, 0, 4, 8, 58, 4, 36, 21, 0, 3,
16, 32, 0, 41, 0, 1, 3, 19, 72, 46, 58, 0, 4, 117, 31, 138, 27, 245, 34, 26, 31,
151, 9, 0, 3, 3, 20, 31, 93, 22, 28, 10, 0, 4, 0, 17, 0, 13, 6, 1, 1, 0, 45, 1)
)
# Lakukan bootstrap
set.seed(123) # untuk hasil yang reprodusibel
for (i in 1:R_custom) {
# Ambil sampel dengan penggantian
indeks_sampel_custom <- sample(1:nrow(data_custom), replace = TRUE)
data_bootstrap_custom <- data_custom[indeks_sampel_custom, ]
# Hitung rata-rata, standar deviasi (st), dan standard error (error) dari
koefisien bootstrap
rata_bootstrap_custom <- mean(hasil_bootstrap_custom)
st_bootstrap_custom <- sd(hasil_bootstrap_custom)
error_bootstrap_custom <- st_bootstrap_custom /
sqrt(length(hasil_bootstrap_custom))
Runing
2. Jacknife
# Buat dataframe dengan data yang diberikan
data_custom <- data.frame(
Y_custom = c(115, 72, 44, 49, 46, 11, 1, 5, 1, 0, 28, 14, 8, 4, 152, 47, 2, 2,
45, 25, 2, 100, 2, 1, 16, 61, 14, 9, 49, 70, 70, 124, 121, 115, 91, 87, 51, 35,
30, 20, 0, 4, 2, 2, 0, 83, 78, 14, 8, 2, 1, 1, 1, 0, 0, 73, 53, 1, 1, 1, 0, 1),
X1_custom = c(2, 7, 2.5, 6, 3, 4.5, 1, 3, 1.5, 3, 3, 2.5, 4, 3.5, 7.5, 8, 2, 2.5,
8, 6.5, 2.5, 5, 1, 0.5, 8, 3, 3, 5.5, 2, 5, 2, 2, 3, 7.5, 4.5, 7, 5, 4, 2.5, 7.5, 3, 4.5,
1, 3, 3, 7, 6, 4.5, 8, 5, 2, 3, 1, 6.5, 3, 5, 2, 1, 1, 2, 1, 1),
X2_custom = c(5, 11, 12, 11, 14, 14, 5, 9, 3, 1, 7, 9, 8, 9, 16, 16, 0, 3, 6, 12,
6, 12, 0, 2, 4, 8, 8, 5, 7, 0, 7, 17, 11, 20, 18, 20, 35, 35, 8, 24, 9, 0, 3, 2, 5, 13,
11, 14, 8, 5, 3, 2, 1, 12, 0, 11, 6, 3, 5, 2, 0, 0),
X3_custom = c(343, 11, 15, 9, 22, 20, 5, 19, 13, 0, 4, 8, 58, 4, 36, 21, 0, 3,
16, 32, 0, 41, 0, 1, 3, 19, 72, 46, 58, 0, 4, 117, 31, 138, 27, 245, 34, 26, 31,
151, 9, 0, 3, 3, 20, 31, 93, 22, 28, 10, 0, 4, 0, 17, 0, 13, 6, 1, 1, 0, 45, 1)
)
# Lakukan jackknife
for (iterasi in 1:jumlah_obs_custom) {
# Hapus satu observasi
data_jackknife_custom <- data_custom[-iterasi, ]
# Hitung rata-rata, standar deviasi (st), dan standar error (error) dari
koefisien jackknife
rata_jack_custom <- mean(hasil_jack_custom)
st_jack_custom <- sd(hasil_jack_custom)
error_jack_custom <- st_jack_custom / sqrt(jumlah_obs_custom)
# Tampilkan hasilnya
cat("Intercept (beta): Rata-rata =", rata_jack_custom, ", St =",
st_jack_custom, ", Error =", error_jack_custom, "\n")
cat("X1 (beta1): Rata-rata =", rata_jack_1_custom, ", St =",
st_jack_1_custom, ", Error =", error_jack_1_custom, "\n")
cat("X2 (beta2): Rata-rata =", rata_jack_2_custom, ", St =",
st_jack_2_custom, ", Error =", error_jack_2_custom, "\n")
cat("X3 (beta3): Rata-rata =", rata_jack_3_custom, ", St =",
st_jack_3_custom, ", Error =", error_jack_3_custom, "\n")
Hasil