Dataset ini menggambarkan penjualan berdasarkan kategori usia konsumen dan brand HP yang mereka beli. Usia mengacu pada kelompok usia konsumen, yang dibagi menjadi 10-19 tahun, 20-39 tahun, 40-50 tahun, dan lebih dari 50 tahun. Brand menunjukkan berbagai merek HP, seperti Apple, Samsung, Xiaomi, Oppo, dan Realme. Penjualan mencatatkan jumlah unit yang terjual oleh masing-masing brand dalam kategori usia tertentu. Dataset ini bisa digunakan untuk menganalisis preferensi pembelian berdasarkan usia terhadap berbagai merek ponsel, serta untuk memahami perbedaan penjualan di setiap segmen usia.
library(readxl)
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(FactoMineR)
library(gplots)
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
datahp <- read_excel("C:/Users/user/Documents/Semester 5/Teknik Peubah Ganda/Data Survey Brand HP.xlsx")
datahp
datahp$Usia <- factor(datahp$Usia, levels=c("> 50 th", "40-50 th",
"20-39 th", "10-19 th"))
datahp$Stasiun.TV <- factor(datahp$Brand,
levels=c("Apple", "Samsung",
"Xiaomi","Oppo","Realme"))
table_count <- xtabs(Penjualan ~ Usia + Brand, data = datahp)
table_count
## Brand
## Usia Apple Oppo Realme Samsung Xiaomi
## > 50 th 1200 350 200 650 450
## 40-50 th 950 500 350 780 620
## 20-39 th 800 900 550 1050 1250
## 10-19 th 450 250 180 380 300
balloonplot(table_count, main ="Tabel Kontingensi Brand HP x Usia", xlab ="", ylab="", label = FALSE, show.margins = FALSE)
Di mana semakin besar lingkaran menunjukkan semakin besar pula nilai yang direpresentasikan.
chisq <- chisq.test(table_count)
chisq
##
## Pearson's Chi-squared test
##
## data: table_count
## X-squared = 622.6, df = 12, p-value < 2.2e-16
Diperoleh dari hasil uji Khi-kuadrat, bahwa kedua peubah (stasiun TV dan rentang usia) secara signifikan saling terkait.
model_hp <- CA(table_count, graph = F)
model_hp
## **Results of the Correspondence Analysis (CA)**
## The row variable has 4 categories; the column variable has 5 categories
## The chi square of independence between the two variables is equal to 622.5994 (p-value = 1.577513e-125 ).
## *The results are available in the following objects:
##
## name description
## 1 "$eig" "eigenvalues"
## 2 "$col" "results for the columns"
## 3 "$col$coord" "coord. for the columns"
## 4 "$col$cos2" "cos2 for the columns"
## 5 "$col$contrib" "contributions of the columns"
## 6 "$row" "results for the rows"
## 7 "$row$coord" "coord. for the rows"
## 8 "$row$cos2" "cos2 for the rows"
## 9 "$row$contrib" "contributions of the rows"
## 10 "$call" "summary called parameters"
## 11 "$call$marge.col" "weights of the columns"
## 12 "$call$marge.row" "weights of the rows"
eig.val <- get_eigenvalue(model_hp)
eig.val
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 4.982241e-02 97.30822684 97.30823
## Dim.2 1.371219e-03 2.67813093 99.98636
## Dim.3 6.984902e-06 0.01364222 100.00000
fviz_screeplot(model_hp, addlabels = TRUE)
Dapat dilihat bahwa untuk mereduksi menjadi 2 dimensi saja, kita sudah mendapatkan 99.9% keragaman dalam data.
row <- get_ca_row(model_hp)
row
## Correspondence Analysis - Results for rows
## ===================================================
## Name Description
## 1 "$coord" "Coordinates for the rows"
## 2 "$cos2" "Cos2 for the rows"
## 3 "$contrib" "contributions of the rows"
## 4 "$inertia" "Inertia of the rows"
row$coord
## Dim 1 Dim 2 Dim 3
## > 50 th -0.32853364 -0.03832468 0.0004511189
## 40-50 th -0.05029422 0.03995641 -0.0033272449
## 20-39 th 0.25185633 -0.02332025 0.0001390206
## 10-19 th -0.03120763 0.05607179 0.0055954816
Untuk memetakan menjadi dua dimensi, maka hanya perlu melihat Dim 1 dan Dim 2 nya saja.
row$contrib
## Dim 1 Dim 2 Dim 3
## > 50 th 50.7745725 25.10507 0.6828620
## 40-50 th 1.3360659 30.63954 41.7086008
## 20-39 th 47.6385845 14.84012 0.1035322
## 10-19 th 0.2507771 29.41527 57.5050049
Profil baris yang berkontribusi paling banyak kepada Dim 1 dan Dim 2 adalah baris yang paling penting dalam menjelaskan keragaman data. Dalam hal ini, responden berusia >50 tahun dan 20-39 tahun dianggap sebagai responden yang menyumbang keragaman paling besar.
fviz_ca_row(model_hp, col.row="steelblue", shape.row = 15)
Baris dengan profil serupa dikelompokkan bersama.
Baris yang berkorelasi negatif diposisikan pada sisi yang saling berlawanan (kuadran berlawanan).
col <- get_ca_col(model_hp)
col
## Correspondence Analysis - Results for columns
## ===================================================
## Name Description
## 1 "$coord" "Coordinates for the columns"
## 2 "$cos2" "Cos2 for the columns"
## 3 "$contrib" "contributions of the columns"
## 4 "$inertia" "Inertia of the columns"
col$coord
## Dim 1 Dim 2 Dim 3
## Apple -0.3354517256 -0.01155603 0.001073151
## Oppo 0.1763700925 -0.00547821 0.003454178
## Realme 0.1735825035 0.07566902 0.002759774
## Samsung -0.0002915437 0.02904440 -0.003938404
## Xiaomi 0.2161999590 -0.04949481 -0.001078529
Untuk memetakan menjadi dua dimensi, maka hanya perlu melihat Dim 1 dan Dim 2 nya saja.
col$contrib
## Dim 1 Dim 2 Dim 3
## Apple 6.315107e+01 2.7230511 4.610061
## Oppo 1.026885e+01 0.3599704 28.094767
## Realme 6.365955e+00 43.9547353 11.477918
## Samsung 4.012501e-05 14.4693919 52.229102
## Xiaomi 2.021409e+01 38.4928513 3.588152
Profil kolom yang berkontribusi paling banyak kepada Dim 1 dan Dim 2 adalah baris yang paling penting dalam menjelaskan keragaman data. Dalam hal ini, brand HP Realme dan Xiaomi dianggap sebagai brand HP yang menyumbang keragaman paling besar.
fviz_ca_col(model_hp, col.col="steelblue", shape.col = 15)
fviz_ca_biplot(model_hp, repel = TRUE)
Plot dalam gambar diatas, menunjukkan bagaimana korelasi antara brand HP dengan berbagai kategori usia.
Terlihat bahwa usia kategori 20-39 tahun berdekatan dengan brand HP Oppo dan Xiaomi, artinya jelas bahwa pembeli dengan rentang usia 20-39 tahun lebih sering menggunakan brand HP Oppo dan Xiaomi dibanding brand HP lainnya.
Kemudian pembeli dengan kategori usia > 50 tahun lebih sering menggunakan brand HP Apple
Terakhir, pembeli dengan kategori usia 40-50 tahun dan 10-19 tahun lebih sering menggunakan brand HP Samsung dibanding brand HP lainnya.