Analisis Central Tendency
Statistika Deskriptif - Introduction to Statistics
1 Pendahuluan
1.1 Latar Belakang
Central tendency atau ukuran pemusatan data merupakan konsep fundamental dalam statistika deskriptif yang digunakan untuk menggambarkan nilai tipikal atau representatif dari suatu kumpulan data. Dalam analisis data, terdapat tiga ukuran pemusatan yang paling sering digunakan yaitu mean (rata-rata), median (nilai tengah), dan modus (nilai yang paling sering muncul). Ketiga ukuran ini memberikan perspektif yang berbeda namun saling melengkapi dalam memahami karakteristik data.
Laporan ini menyajikan analisis komprehensif terhadap data pembelian pelanggan (Total Purchase) dan karakteristik demografis (Gender) menggunakan pendekatan central tendency. Analisis dilengkapi dengan visualisasi menggunakan histogram dengan kurva density serta boxplot untuk memberikan pemahaman yang lebih mendalam tentang distribusi data dan pola yang terdapat di dalamnya.
2 Total Purchase
Analisis Total Purchase bertujuan untuk memahami pola pembelian pelanggan melalui perhitungan tiga ukuran central tendency. Variabel Total Purchase merepresentasikan nilai transaksi yang dilakukan oleh setiap pelanggan dalam dataset.
2.1 Median
2.1.1 Rumus Median
Median adalah nilai tengah dari data yang telah diurutkan dari terkecil hingga terbesar. Median membagi distribusi data menjadi dua bagian yang sama besar, dimana 50% data berada di bawah median dan 50% lainnya berada di atas median.
Formula perhitungan median:
\[ \text{Median} = \begin{cases} X_{\frac{n+1}{2}} & \text{jika } n \text{ ganjil} \\[12pt] \frac{X_{\frac{n}{2}} + X_{\frac{n}{2}+1}}{2} & \text{jika } n \text{ genap} \end{cases} \]
Keterangan:
- \(X_i\) = nilai data ke-\(i\) setelah diurutkan
- \(n\) = jumlah total observasi
2.1.2 Pengaplikasian ke dalam Data
library(scales)
# Ekstraksi data Total Purchase
total_purchase <- na.omit(data$TotalPurchase)
# Menghitung median
median_val <- median(total_purchase)
# Informasi perhitungan
n <- length(total_purchase)
sorted_data <- sort(total_purchase)
# Hasil perhitungan
cat("Jumlah Data (n) :", comma(n), "\n")## Jumlah Data (n) : 200
## Median : 108
cat("Posisi Median :", ifelse(n %% 2 == 1,
paste("Posisi ke-", (n+1)/2),
paste("Rata-rata posisi ke-", n/2, "dan", (n/2)+1)), "\n")## Posisi Median : Rata-rata posisi ke- 100 dan 101
Berdasarkan perhitungan di atas, nilai median Total Purchase adalah 108. Nilai ini menunjukkan bahwa 50% pelanggan melakukan pembelian dengan nilai di bawah angka tersebut, sementara 50% lainnya melakukan pembelian dengan nilai di atasnya. Median merupakan ukuran yang robust terhadap outlier, sehingga lebih representatif untuk data yang memiliki nilai ekstrem.
2.2 Modus
2.2.1 Rumus Modus
Modus adalah nilai yang paling sering muncul atau memiliki frekuensi kemunculan tertinggi dalam dataset. Untuk data kontinu seperti Total Purchase, modus diidentifikasi dengan mengelompokkan data dan mencari interval dengan frekuensi tertinggi.
Formula konseptual modus:
\[ \text{Modus} = \underset{x}{\text{argmax}} \, f(x) \]
Dimana \(f(x)\) adalah fungsi frekuensi dari nilai \(x\).
2.2.2 Pengaplikasian ke dalam Data
library(scales)
# Pembulatan untuk identifikasi frekuensi
total_purchase_rounded <- round(total_purchase, 0)
# Menghitung frekuensi
frequency_table <- table(total_purchase_rounded)
frequency_sorted <- sort(frequency_table, decreasing = TRUE)
# Modus
modus_val <- as.numeric(names(frequency_sorted)[1])
modus_freq <- frequency_sorted[1]
# Hasil perhitungan
cat("Modus :", comma(modus_val), "\n")## Modus : 33
## Frekuensi : 5 kali
## Persentase : 2.5 %
Nilai modus Total Purchase adalah 33 dengan frekuensi kemunculan sebanyak 5 kali atau 2.5% dari total transaksi. Modus menunjukkan nilai pembelian yang paling populer atau paling sering terjadi di kalangan pelanggan, memberikan insight tentang price point yang paling diminati.
2.3 Mean
2.3.1 Rumus Mean
Mean atau rata-rata adalah jumlah seluruh nilai data dibagi dengan banyaknya data. Mean merupakan ukuran central tendency yang paling umum digunakan dan memperhitungkan seluruh nilai dalam dataset.
Formula perhitungan mean:
\[ \bar{X} = \frac{1}{n}\sum_{i=1}^{n} X_i = \frac{X_1 + X_2 + X_3 + \cdots + X_n}{n} \]
Keterangan:
- \(\bar{X}\) = nilai mean (rata-rata)
- \(n\) = jumlah data
- \(X_i\) = nilai data ke-\(i\)
- \(\sum\) = simbol penjumlahan
2.3.2 Pengaplikasian ke dalam Data
library(scales)
# Menghitung mean
mean_val <- mean(total_purchase)
sum_total <- sum(total_purchase)
# Hasil perhitungan
cat("Σ Xi (Total) :", comma(sum_total), "\n")## Σ Xi (Total) : 42,359
## n (Jumlah Data) : 200
## Mean (Σ Xi / n) : 212
Nilai mean Total Purchase adalah 212. Angka ini merepresentasikan rata-rata pembelian seluruh pelanggan dalam dataset. Mean sangat berguna untuk proyeksi revenue dan analisis trend, namun perlu diperhatikan bahwa mean sensitif terhadap nilai ekstrem (outlier) dalam data.
2.4 Interpretasi Hasil Mean, Median, dan Modus dari Total Purchase
##
## 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
## Warning: package 'kableExtra' was built under R version 4.5.2
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
library(scales)
# Membuat tabel ringkasan
summary_df <- data.frame(
Ukuran = c("Mean", "Median", "Modus"),
Nilai = comma(c(mean_val, median_val, modus_val)),
Interpretasi = c(
"Rata-rata pembelian keseluruhan pelanggan",
"Nilai tengah - 50% data di bawah, 50% di atas",
"Nilai pembelian paling populer/sering terjadi"
)
)
kable(summary_df,
caption = "Ringkasan Ukuran Central Tendency Total Purchase",
col.names = c("Ukuran", "Nilai", "Interpretasi"),
align = c('l', 'r', 'l')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "bordered"),
full_width = TRUE,
font_size = 14) %>%
row_spec(0, bold = TRUE, color = "white", background = "#667eea")| Ukuran | Nilai | Interpretasi |
|---|---|---|
| Mean | 212 | Rata-rata pembelian keseluruhan pelanggan |
| Median | 108 | Nilai tengah - 50% data di bawah, 50% di atas |
| Modus | 33 | Nilai pembelian paling populer/sering terjadi |
Perbandingan ketiga ukuran central tendency memberikan insight yang komprehensif tentang distribusi Total Purchase. Nilai mean sebesar 212 menunjukkan rata-rata pembelian keseluruhan, median sebesar 108 merepresentasikan nilai tengah yang robust terhadap outlier, dan modus sebesar 33 mengindikasikan price point yang paling populer.
Hubungan antara mean, median, dan modus memberikan informasi tentang bentuk distribusi data. Jika mean lebih besar dari median, distribusi data cenderung positively skewed (condong ke kanan) yang mengindikasikan adanya beberapa transaksi dengan nilai sangat tinggi. Sebaliknya, jika mean lebih kecil dari median, distribusi cenderung negatively skewed (condong ke kiri).
3 Gender
Analisis gender bertujuan untuk memahami komposisi demografis pelanggan dan mengidentifikasi pola yang mungkin ada berdasarkan karakteristik gender.
3.1 Modus
3.1.1 Rumus Modus
Untuk data kategorikal seperti gender, modus adalah kategori dengan frekuensi kemunculan tertinggi. Modus sangat sesuai untuk data nominal dan ordinal.
\[ \text{Modus} = \text{argmax}_{kategori} \, \text{frekuensi(kategori)} \]
3.1.2 Pengaplikasian ke dalam Data
# Library
library(ggplot2)
library(dplyr)
library(knitr)
library(kableExtra)
library(scales)
# Menghitung frekuensi gender
gender_freq <- table(data$Gender)
gender_prop <- prop.table(gender_freq) * 100
# Modus gender
modus_gender <- names(gender_freq)[which.max(gender_freq)]
modus_gender_freq <- max(gender_freq)
modus_gender_pct <- max(gender_prop)
# Hasil perhitungan
cat("Modus Gender :", modus_gender, "\n")## Modus Gender : M
## Frekuensi : 101 pelanggan
## Persentase : 50.5 %
# Tabel distribusi
gender_df <- data.frame(
Gender = names(gender_freq),
Frekuensi = as.numeric(gender_freq),
Persentase = paste0(round(as.numeric(gender_prop), 2), "%")
)
kable(gender_df,
caption = "Distribusi Gender Pelanggan",
col.names = c("Gender", "Frekuensi", "Persentase"),
align = c('l', 'r', 'r')) %>%
kable_styling(
bootstrap_options = c("striped", "hover", "bordered"),
full_width = TRUE,
font_size = 14
) %>%
row_spec(0, bold = TRUE, color = "white", background = "#FF6B6B")| Gender | Frekuensi | Persentase |
|---|---|---|
| F | 99 | 49.5% |
| M | 101 | 50.5% |
3.2 Interpretasi Hasil Modus dari Gender
Berdasarkan analisis, gender M merupakan modus dengan frekuensi 101 pelanggan atau 50.5% dari total. Informasi ini menunjukkan komposisi demografis pelanggan dalam dataset.
Distribusi gender penting untuk strategi marketing dan personalisasi layanan. Dengan memahami komposisi gender, perusahaan dapat merancang kampanye marketing yang lebih targeted dan mengembangkan produk atau layanan yang sesuai dengan preferensi masing-masing segmen.
library(ggplot2)
library(dplyr)
library(DT)
library(knitr)
library(kableExtra)
library(scales)
# Statistik pembelian per gender
gender_stats <- data %>%
group_by(Gender) %>%
summarise(
Jumlah = n(),
Mean = comma(round(mean(TotalPurchase, na.rm = TRUE), 0)),
Median = comma(round(median(TotalPurchase, na.rm = TRUE), 0)),
.groups = 'drop'
)
kable(gender_stats,
caption = "Statistik Total Purchase Berdasarkan Gender",
col.names = c("Gender", "Jumlah", "Mean", "Median"),
align = c('l', 'r', 'r', 'r')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "bordered"),
full_width = TRUE,
font_size = 14) %>%
row_spec(0, bold = TRUE, color = "white", background = "#667eea")| Gender | Jumlah | Mean | Median |
|---|---|---|---|
| F | 99 | 207 | 105 |
| M | 101 | 217 | 116 |
Tabel di atas menunjukkan perbedaan pola pembelian antara kelompok gender, yang dapat digunakan untuk strategi pricing dan product positioning yang lebih efektif.
4 Visualisasi Data Tendency Menggunakan Histogram + Density
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
# Hitung Mean, Median, Modus
mean_val <- mean(data_tendency$value, na.rm = TRUE)
median_val <- median(data_tendency$value, na.rm = TRUE)
modus_val <- data_tendency %>%
count(value) %>%
arrange(desc(n)) %>%
slice(1) %>%
pull(value)
# Histogram + Density dengan warna dan legenda yang lebih informatif
p <- ggplot(data_tendency, aes(x = value)) +
geom_histogram(
aes(y = after_stat(density), fill = ..count..),
bins = 40,
color = "white",
alpha = 0.9,
linewidth = 0.3
) +
scale_fill_gradient(
low = "#A0C4FF", high = "#9B5DE5",
name = "Jumlah Data",
labels = comma
) +
geom_density(
color = "#FF7EB9",
fill = "#FFB6C1",
linewidth = 2,
alpha = 0.3
) +
geom_vline(aes(xintercept = mean_val, color = "Mean"), linewidth = 1.8) +
geom_vline(aes(xintercept = median_val, color = "Median"), linewidth = 1.8, linetype = "dashed") +
geom_vline(aes(xintercept = modus_val, color = "Modus"), linewidth = 1.8, linetype = "dotdash") +
annotate("label", x = mean_val, y = max(density(data_tendency$value)$y) * 0.95,
label = paste("Mean\n", comma(round(mean_val, 0))),
color = "white", fill = "#00B4D8", fontface = "bold",
size = 5, label.size = 0, alpha = 0.9) +
annotate("label", x = median_val, y = max(density(data_tendency$value)$y) * 0.80,
label = paste("Median\n", comma(round(median_val, 0))),
color = "white", fill = "#00BA38", fontface = "bold",
size = 5, label.size = 0, alpha = 0.9) +
annotate("label", x = modus_val, y = max(density(data_tendency$value)$y) * 0.65,
label = paste("Modus\n", comma(modus_val)),
color = "white", fill = "#F8766D", fontface = "bold",
size = 5, label.size = 0, alpha = 0.9) +
labs(
title = "Distribusi Total Purchase",
subtitle = paste(
"n =", comma(nrow(data_tendency)),
"| Mean:", comma(round(mean_val, 0)),
"| Median:", comma(round(median_val, 0)),
"| Modus:", comma(modus_val)
),
x = "\nTotal Purchase",
y = "Density\n",
color = "Garis Statistik"
) +
scale_color_manual(
values = c(
"Mean" = "#00B4D8",
"Median" = "#00BA38",
"Modus" = "#F8766D"
),
labels = c(
"Mean (Rata-rata)",
"Median (Nilai Tengah)",
"Modus (Nilai Paling Sering)"
)
) +
scale_x_continuous(labels = comma, breaks = pretty_breaks(n = 10)) +
theme_minimal(base_size = 16) +
theme(
plot.title = element_text(face = "bold", hjust = 0.5, size = 24),
plot.subtitle = element_text(hjust = 0.5, size = 14, color = "gray30", margin = margin(b = 15)),
axis.title = element_text(face = "bold", size = 16),
legend.title = element_text(face = "bold"),
legend.position = "right",
legend.background = element_rect(fill = "white", color = NA),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(color = "gray90", linewidth = 0.4),
plot.background = element_rect(fill = "white", color = NA),
plot.margin = margin(20, 20, 20, 20)
)## Warning in annotate("label", x = mean_val, y =
## max(density(data_tendency$value)$y) * : Ignoring unknown parameters:
## `label.size`
## Warning in annotate("label", x = median_val, y =
## max(density(data_tendency$value)$y) * : Ignoring unknown parameters:
## `label.size`
## Warning in annotate("label", x = modus_val, y =
## max(density(data_tendency$value)$y) * : Ignoring unknown parameters:
## `label.size`
## Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(count)` instead.
## ℹ The deprecated feature was likely used in the ggplot2 package.
## Please report the issue at <https://github.com/tidyverse/ggplot2/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
## Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
## Warning in geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]): geom_GeomLabel() has yet to be implemented in plotly.
## If you'd like to see this geom implemented,
## Please open an issue with your example code at
## https://github.com/ropensci/plotly/issues
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
## Warning: 'bar' objects don't have these attributes: 'mode'
## Valid attributes include:
## '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
4.1 Interpretasi Hasil Visualisasi
Histogram dengan kurva density di atas menampilkan distribusi frekuensi Total Purchase secara visual. Histogram (batang ungu) menunjukkan frekuensi data dalam setiap interval, sementara kurva density (garis pink dengan fill) memberikan gambaran bentuk distribusi yang lebih smooth dan kontinu.
Tiga garis vertikal menunjukkan posisi masing-masing ukuran central tendency: garis biru solid untuk mean, garis hijau putus-putus untuk median, dan garis merah titik-strip untuk modus. Posisi relatif ketiga garis ini mengindikasikan bentuk distribusi data.
Dari visualisasi terlihat bahwa distribusi Total Purchase cenderung positively skewed (condong kanan), dimana mean lebih besar dari median. Ini mengindikasikan adanya beberapa transaksi dengan nilai sangat tinggi yang menarik rata-rata ke atas. Konsentrasi data terbesar berada di sekitar nilai modus, yang merupakan price point paling populer.
5 Visualisasi Data Tendency Menggunakan Boxplot
# Library
library(ggplot2)
library(dplyr)
library(scales)
library(plotly)
# Visualisasi boxplot bersih dan interaktif
p <- ggplot(data, aes(x = Gender, y = TotalPurchase, fill = Gender)) +
geom_boxplot(
alpha = 0.8,
width = 0.6,
outlier.color = "#FF6B6B", # merah untuk outlier
outlier.shape = 21,
outlier.size = 3
) +
labs(
title = "Perbandingan Total Purchase Berdasarkan Gender",
subtitle = "Visualisasi distribusi, kuartil, median, dan outlier tanpa penanda tambahan",
x = "Gender",
y = "Total Purchase (dalam satuan pembelian)"
) +
scale_fill_manual(
values = c(
"Female" = "#FFB6C1", # pink lembut untuk perempuan
"Male" = "#89CFF0" # biru lembut untuk laki-laki
),
name = "Gender",
labels = c("Perempuan", "Laki-laki")
) +
scale_y_continuous(labels = comma) +
theme_minimal(base_size = 15) +
theme(
plot.title = element_text(face = "bold", hjust = 0.5, size = 22),
plot.subtitle = element_text(hjust = 0.5, color = "gray40", size = 13),
axis.title = element_text(face = "bold", size = 14),
axis.text = element_text(size = 12),
legend.position = "right",
legend.background = element_rect(fill = "white", color = NA),
panel.grid.major = element_line(color = "gray90"),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "white", color = NA)
)
# Jadikan interaktif
ggplotly(p, tooltip = c("x", "y", "fill"))## Warning: No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
## No shared levels found between `names(values)` of the manual scale and the
## data's fill values.
5.1 Interpretasi Hasil Visualisasi
Boxplot memberikan ringkasan visual yang jelas tentang distribusi Total Purchase berdasarkan Gender. Kotak (box) berwarna biru dan pink merepresentasikan Interquartile Range (IQR) yang mencakup 50% data tengah dari masing-masing kelompok gender, yaitu rentang antara kuartil pertama (Q1) dan kuartil ketiga (Q3).
Garis tebal di tengah kotak menunjukkan median, yaitu nilai tengah pembelian pada tiap gender. Titik putih di tengah menggambarkan rata-rata (mean) yang memberikan indikasi kecenderungan umum pembelian. Whiskers (garis di atas dan bawah kotak) menunjukkan rentang data normal hingga 1.5 kali IQR dari kuartil.
Titik-titik merah di luar whiskers menunjukkan outlier, yaitu pelanggan dengan pembelian yang jauh lebih tinggi atau lebih rendah dibanding kebanyakan. Outlier ini penting karena dapat merepresentasikan kelompok pembeli ekstrem seperti pelanggan dengan pembelian besar (loyal/high-value) atau yang sangat kecil (pasif).
Visualisasi ini membantu memahami perbedaan pola belanja antar gender — misalnya, gender dengan median dan mean lebih tinggi cenderung memiliki Total Purchase yang lebih besar, menunjukkan tingkat pembelian yang lebih aktif atau konsisten.
6 Kesimpulan
Berdasarkan analisis central tendency yang telah dilakukan terhadap data Total Purchase dan Gender, dapat disimpulkan beberapa temuan penting:
1. Karakteristik Total Purchase
Analisis menghasilkan tiga ukuran central tendency yang memberikan perspektif berbeda tentang pola pembelian: Mean sebesar 212 menunjukkan rata-rata pembelian keseluruhan, Median sebesar 108 merepresentasikan nilai tengah yang robust, dan Modus sebesar 33 mengindikasikan price point paling populer. Hubungan antara ketiga ukuran ini menunjukkan bahwa distribusi data positively skewed dengan adanya beberapa transaksi bernilai sangat tinggi.
2. Variabilitas dan Outliers
Boxplot menunjukkan bahwa data Total Purchase memiliki tingkat penyebaran (variabilitas) yang cukup jelas, terlihat dari tinggi kotak dan panjang whiskers. Beberapa titik merah di luar whiskers menandakan adanya outliers, yaitu pelanggan dengan nilai pembelian yang jauh lebih tinggi atau rendah dari kebanyakan. Outliers ini penting diperhatikan karena bisa menunjukkan pelanggan dengan pola pembelian ekstrem yang berpotensi menjadi target khusus dalam strategi pemasaran.
3. Profil Demografis
Analisis gender menunjukkan bahwa M merupakan segmen dominan dengan 50.5% dari total pelanggan. Perbedaan pola pembelian antar gender dapat dijadikan dasar untuk strategi marketing yang lebih tersegmentasi dan personal.
4. Implikasi Praktis
- Pricing Strategy: Nilai modus dapat dijadikan anchor untuk penetapan harga produk atau bundle
- Market Segmentation: Median dapat digunakan sebagai titik pemisah untuk segmentasi pelanggan (below-median vs above-median)
- Revenue Projection: Mean berguna untuk forecasting dan target setting
- Customer Retention: Outliers atas perlu program retention khusus mengingat kontribusi signifikan terhadap revenue
- Targeted Marketing: Perbedaan pola pembelian gender dapat dioptimalkan untuk kampanye yang lebih efektif
Analisis ini memberikan fondasi yang kuat untuk pengambilan keputusan berbasis data dalam strategi bisnis dan marketing. Pemahaman mendalam tentang distribusi dan karakteristik pelanggan memungkinkan perusahaan untuk merancang intervensi yang lebih tepat sasaran dan efektif.