Dalam dunia investasi modern, khususnya saham teknologi yang bersifat volatil, investor sering kali menggunakan data historis return saham untuk memperkirakan rata-rata keuntungan di masa mendatang. Namun, estimasi yang diperoleh dari sampel tersebut mengandung ketidakpastian estimasi (estimation uncertainty). Oleh karena itu, diperlukan suatu interval untuk mengukur seberapa akurat estimasi tersebut. Interval Kepercayaan (Confidence Interval) 95% merupakan salah satu alat statistika yang paling umum digunakan untuk mengukur tingkat ketidakpastian estimasi parameter populasi. Lebar interval kepercayaan ini dipengaruhi oleh tiga faktor utama, yaitu:
Praktikum ini dilakukan dengan menggunakan simulasi Monte Carlo untuk mempelajari secara empiris bagaimana ketiga faktor tersebut memengaruhi lebar Interval Kepercayaan 95% pada estimasi return investasi saham teknologi.
Praktikum ini bertujuan untuk:
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.6.1
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.6.1
##
## 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(tidyr)
## Warning: package 'tidyr' was built under R version 4.6.1
library(viridis)
## Warning: package 'viridis' was built under R version 4.6.1
## Loading required package: viridisLite
## Warning: package 'viridisLite' was built under R version 4.6.1
library(patchwork)
## Warning: package 'patchwork' was built under R version 4.6.1
library(scales)
## Warning: package 'scales' was built under R version 4.6.1
##
## Attaching package: 'scales'
## The following object is masked from 'package:viridis':
##
## viridis_pal
library(knitr)
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.6.1
set.seed(2025)
ALPHA <- 0.05 # CI 95%
N_SIM <- 10000 # Jumlah simulasi Monte Carlo
MU_POP <- 0.8 # Rata-rata return harian saham teknologi (%)
ukuran_sampel <- c(5, 30, 100)
sd_populasi <- c(10, 50, 90)
pengetahuan <- c("Diketahui (z)", "Tidak Diketahui (t)")
# Fungsi Lebar CI Analitik
lebar_ci_analitik <- function(n, sigma, diketahui) {
if (diketahui) {
z <- qnorm(1 - ALPHA/2)
2 * z * sigma / sqrt(n)
} else {
t <- qt(1 - ALPHA/2, df = n-1)
2 * t * sigma / sqrt(n)
}
}
# Fungsi Simulasi Monte Carlo
simulasi_lebar <- function(n, sigma, diketahui, n_sim = N_SIM) {
lebars <- numeric(n_sim)
for(i in 1:n_sim) {
sampel <- rnorm(n, mean = MU_POP, sd = sigma)
if(diketahui) {
se <- sigma / sqrt(n)
z <- qnorm(1 - ALPHA/2)
lebars[i] <- 2 * z * se
} else {
s <- sd(sampel)
se <- s / sqrt(n)
t <- qt(1 - ALPHA/2, df = n-1)
lebars[i] <- 2 * t * se
}
}
data.frame(mean_lebar = mean(lebars), sd_lebar = sd(lebars))
}
grid <- expand.grid(n = ukuran_sampel,
sigma = sd_populasi,
pengetahuan = pengetahuan,
stringsAsFactors = FALSE)
hasil <- grid %>%
rowwise() %>%
mutate(
diketahui = pengetahuan == "Diketahui (z)",
lebar_analitik = lebar_ci_analitik(n, sigma, diketahui),
sim = list(simulasi_lebar(n, sigma, diketahui)),
lebar_sim = sim$mean_lebar,
sd_sim = sim$sd_lebar
) %>%
ungroup() %>%
select(-sim, -diketahui)
# Tampilkan preview tabel hasil
print("Preview Tabel Hasil Simulasi:")
## [1] "Preview Tabel Hasil Simulasi:"
head(hasil) %>% knitr::kable(digits = 3)
| n | sigma | pengetahuan | lebar_analitik | lebar_sim | sd_sim |
|---|---|---|---|---|---|
| 5 | 10 | Diketahui (z) | 17.530 | 17.530 | 0 |
| 30 | 10 | Diketahui (z) | 7.157 | 7.157 | 0 |
| 100 | 10 | Diketahui (z) | 3.920 | 3.920 | 0 |
| 5 | 50 | Diketahui (z) | 87.652 | 87.652 | 0 |
| 30 | 50 | Diketahui (z) | 35.784 | 35.784 | 0 |
| 100 | 50 | Diketahui (z) | 19.600 | 19.600 | 0 |
hasil %>%
arrange(sigma, n, pengetahuan) %>%
mutate(
lebar_analitik = round(lebar_analitik, 3),
lebar_sim = round(lebar_sim, 3),
sd_sim = round(sd_sim, 3)
) %>%
kable(align = "c", caption = "Ringkasan Lebar Interval Kepercayaan 95% (10.000 Simulasi)")
| n | sigma | pengetahuan | lebar_analitik | lebar_sim | sd_sim |
|---|---|---|---|---|---|
| 5 | 10 | Diketahui (z) | 17.530 | 17.530 | 0.000 |
| 5 | 10 | Tidak Diketahui (t) | 24.833 | 23.375 | 8.407 |
| 30 | 10 | Diketahui (z) | 7.157 | 7.157 | 0.000 |
| 30 | 10 | Tidak Diketahui (t) | 7.468 | 7.406 | 0.971 |
| 100 | 10 | Diketahui (z) | 3.920 | 3.920 | 0.000 |
| 100 | 10 | Tidak Diketahui (t) | 3.968 | 3.957 | 0.280 |
| 5 | 50 | Diketahui (z) | 87.652 | 87.652 | 0.000 |
| 5 | 50 | Tidak Diketahui (t) | 124.166 | 116.653 | 42.133 |
| 30 | 50 | Diketahui (z) | 35.784 | 35.784 | 0.000 |
| 30 | 50 | Tidak Diketahui (t) | 37.341 | 37.090 | 4.907 |
| 100 | 50 | Diketahui (z) | 19.600 | 19.600 | 0.000 |
| 100 | 50 | Tidak Diketahui (t) | 19.842 | 19.781 | 1.405 |
| 5 | 90 | Diketahui (z) | 157.774 | 157.774 | 0.000 |
| 5 | 90 | Tidak Diketahui (t) | 223.500 | 210.544 | 76.902 |
| 30 | 90 | Diketahui (z) | 64.411 | 64.411 | 0.000 |
| 30 | 90 | Tidak Diketahui (t) | 67.213 | 66.547 | 8.828 |
| 100 | 90 | Diketahui (z) | 35.279 | 35.279 | 0.000 |
| 100 | 90 | Tidak Diketahui (t) | 35.716 | 35.602 | 2.520 |
p1 <- ggplot(hasil, aes(x = factor(n), y = factor(sigma), fill = lebar_sim)) +
geom_tile(color = "white", linewidth = 0.8) +
geom_text(aes(label = round(lebar_sim, 1)), color = "white", fontface = "bold") +
scale_fill_viridis_c(option = "magma", direction = -1) +
facet_wrap(~pengetahuan) +
labs(title = "Heatmap Lebar Interval Kepercayaan 95%",
subtitle = "Return Saham Teknologi",
x = "Ukuran Sampel (n hari)",
y = "Volatilitas Return (σ)") +
theme_minimal(base_size = 13)
p1
p2 <- ggplot(hasil, aes(x = n, y = lebar_sim, color = factor(sigma),
linetype = pengetahuan, group = interaction(sigma, pengetahuan))) +
geom_line(linewidth = 1.2) + geom_point(size = 3) +
scale_color_viridis_d() +
labs(title = "Pengaruh Ukuran Sampel terhadap Lebar IK",
x = "Ukuran Sampel (n hari)",
y = "Rata-rata Lebar IK") +
theme_minimal()
p2
p3 <- ggplot(hasil, aes(x = factor(sigma), y = lebar_sim,
fill = factor(n), alpha = pengetahuan)) +
geom_col(position = "dodge", color = "black") +
scale_fill_viridis_d() +
scale_alpha_manual(values = c(1, 0.65)) +
labs(title = "Pengaruh Variabilitas Data terhadap Lebar IK",
x = "Volatilitas Return (σ)",
y = "Rata-rata Lebar IK") +
theme_minimal()
p3
p4 <- ggplot(hasil, aes(x = lebar_analitik, y = lebar_sim, color = factor(n))) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "gray50") +
geom_point(size = 3.5) +
facet_wrap(~pengetahuan) +
labs(title = "Validasi Simulasi vs Formula Analitik") +
theme_minimal()
p4
selisih <- hasil %>%
select(n, sigma, pengetahuan, lebar_sim) %>%
pivot_wider(names_from = pengetahuan,
values_from = lebar_sim) %>%
mutate(
selisih_pct = (`Tidak Diketahui (t)` - `Diketahui (z)`) /
`Diketahui (z)` * 100
)
p5 <- ggplot(selisih, aes(x = factor(sigma), y = selisih_pct, fill = factor(n))) +
geom_col(position = position_dodge(width = 0.85),
color = "black", width = 0.8) +
geom_text(aes(label = sprintf("%.1f%%", selisih_pct)),
position = position_dodge(width = 0.85),
vjust = -0.4, # diubah agar tidak terlalu atas
size = 4.2,
fontface = "bold") +
scale_fill_viridis_d(option = "plasma", name = "Ukuran Sampel (n)") +
labs(title = "Selisih Lebar Interval Kepercayaan (t vs z)",
subtitle = "Pengaruh Ketidaktahuan terhadap Standar Deviasi Populasi",
x = "Volatilitas Return (σ)",
y = "Selisih Persentase (%)") +
theme_minimal(base_size = 14) +
theme(
plot.margin = margin(t = 25, r = 20, b = 10, l = 10), # tambah ruang atas
legend.position = "bottom"
) +
ylim(0, max(selisih$selisih_pct) * 1.12) # beri ruang ekstra di atas
p5
# 12. Plot 6: Distribusi Lebar IK (n=5, σ=50)
set.seed(123)
n_ex <- 5; sigma_ex <- 50
dist_z <- replicate(N_SIM, 2 * qnorm(1 - ALPHA/2) * sigma_ex / sqrt(n_ex))
dist_t <- replicate(N_SIM, {
sampel <- rnorm(n_ex, MU_POP, sigma_ex)
2 * qt(1 - ALPHA/2, n_ex-1) * sd(sampel) / sqrt(n_ex)
})
df_dist <- data.frame(lebar = c(dist_z, dist_t),
metode = rep(c("σ Diketahui (z)", "σ Tidak Diketahui (t)"), each = N_SIM))
p6 <- ggplot(df_dist, aes(x = lebar, fill = metode)) +
geom_histogram(aes(y = after_stat(density)), bins = 60, alpha = 0.7,
position = "identity", color = "white") +
geom_density(aes(color = metode), linewidth = 1.1) +
labs(title = "Distribusi Lebar IK (n=5, σ=50)",
subtitle = "Perbandingan Distribusi z dan t",
x = "Lebar Interval Kepercayaan",
y = "Densitas") +
theme_minimal(base_size = 13)
p6
(p1 | p6) /
(p2 | p3) /
(p5 | p4) +
plot_annotation(
title = "Simulasi Monte Carlo Ketidakpastian Estimasi Return Investasi Saham Teknologi",
subtitle = "Interval Kepercayaan 95%",
caption = "Praktikum Week 5 - PSS"
)
Lebar Interval Kepercayaan berbanding terbalik dengan akar dari ukuran sampel. Hasil simulasi menunjukkan bahwa semakin besar ukuran sampel, semakin sempit lebar interval kepercayaan yang dihasilkan. Pada n = 5, interval sangat lebar sehingga estimasi return saham menjadi kurang presisi. Sebaliknya, pada n = 100, lebar interval mengecil secara signifikan, menghasilkan estimasi yang jauh lebih akurat dan dapat diandalkan.
Lebar Interval Kepercayaan berbanding lurus dengan standar deviasi (sigma). Semakin tinggi volatilitas return saham, semakin lebar interval kepercayaan yang terbentuk. Pada tingkat volatilitas tinggi (sigma = 90), ketidakpastian estimasi meningkat secara drastis. Hal ini sesuai dengan karakteristik saham teknologi yang cenderung memiliki fluktuasi harga yang besar, sehingga memerlukan sampel yang lebih besar untuk menghasilkan estimasi yang stabil.
Penggunaan distribusi t (ketika sigma tidak diketahui) menghasilkan Interval Kepercayaan yang lebih lebar dibandingkan distribusi z (ketika sigma diketahui). Perbedaan ini sangat signifikan pada ukuran sampel kecil (n = 5), namun semakin mengecil seiring bertambahnya ukuran sampel. Hal ini menunjukkan bahwa ketidaktahuan terhadap parameter volatilitas populasi memberikan penalti ketidakpastian yang lebih besar pada sampel berukuran kecil.
Berdasarkan hasil simulasi Monte Carlo yang dilakukan, dapat disimpulkan beberapa hal sebagai berikut: