Load Library

library(readxl)
library(dplyr)

Input Data

Data_Kopi <- read_excel("C:/Users/Lenovo/Downloads/1. Tugas SIM 2025B - Coffee Chain Datasets.xlsx")

# Lihat data
head(Data_Kopi)
## # A tibble: 6 × 20
##   `Area Code` Date                Market  `Market Size` Product   `Product Line`
##         <dbl> <dttm>              <chr>   <chr>         <chr>     <chr>         
## 1         719 2012-01-01 00:00:00 Central Major Market  Amaretto  Beans         
## 2         970 2012-01-01 00:00:00 Central Major Market  Colombian Beans         
## 3         970 2012-01-01 00:00:00 Central Major Market  Decaf Ir… Beans         
## 4         303 2012-01-01 00:00:00 Central Major Market  Green Tea Leaves        
## 5         303 2012-01-01 00:00:00 Central Major Market  Caffe Mo… Beans         
## 6         720 2012-01-01 00:00:00 Central Major Market  Decaf Es… Beans         
## # ℹ 14 more variables: `Product Type` <chr>, State <chr>, Type <chr>,
## #   `Budget COGS` <dbl>, `Budget Margin` <dbl>, `Budget Profit` <dbl>,
## #   `Budget Sales` <dbl>, COGS <dbl>, Inventory <dbl>, Margin <dbl>,
## #   Marketing <dbl>, Profit <dbl>, Sales <dbl>, `Total Expenses` <dbl>
str(Data_Kopi)
## tibble [4,248 × 20] (S3: tbl_df/tbl/data.frame)
##  $ Area Code     : num [1:4248] 719 970 970 303 303 720 970 719 970 719 ...
##  $ Date          : POSIXct[1:4248], format: "2012-01-01" "2012-01-01" ...
##  $ Market        : chr [1:4248] "Central" "Central" "Central" "Central" ...
##  $ Market Size   : chr [1:4248] "Major Market" "Major Market" "Major Market" "Major Market" ...
##  $ Product       : chr [1:4248] "Amaretto" "Colombian" "Decaf Irish Cream" "Green Tea" ...
##  $ Product Line  : chr [1:4248] "Beans" "Beans" "Beans" "Leaves" ...
##  $ Product Type  : chr [1:4248] "Coffee" "Coffee" "Coffee" "Tea" ...
##  $ State         : chr [1:4248] "Colorado" "Colorado" "Colorado" "Colorado" ...
##  $ Type          : chr [1:4248] "Regular" "Regular" "Decaf" "Regular" ...
##  $ Budget COGS   : num [1:4248] 90 80 100 30 60 80 140 50 50 40 ...
##  $ Budget Margin : num [1:4248] 130 110 140 50 90 130 160 80 70 70 ...
##  $ Budget Profit : num [1:4248] 100 80 110 30 70 80 110 20 40 20 ...
##  $ Budget Sales  : num [1:4248] 220 190 240 80 150 210 300 130 120 110 ...
##  $ COGS          : num [1:4248] 89 83 95 44 54 72 170 63 60 58 ...
##  $ Inventory     : num [1:4248] 777 623 821 623 456 ...
##  $ Margin        : num [1:4248] 130 107 139 56 80 108 171 87 80 72 ...
##  $ Marketing     : num [1:4248] 24 27 26 14 15 23 47 57 19 22 ...
##  $ Profit        : num [1:4248] 94 68 101 30 54 53 99 0 33 17 ...
##  $ Sales         : num [1:4248] 219 190 234 100 134 180 341 150 140 130 ...
##  $ Total Expenses: num [1:4248] 36 39 38 26 26 55 72 87 47 55 ...

Seleksi Variabel

Data_Kopi1 <- Data_Kopi[, c("Area Code", "Product", "Product Type",
                           "Budget COGS", "Budget Margin",
                           "Budget Profit", "Budget Sales")]

head(Data_Kopi1)
## # A tibble: 6 × 7
##   `Area Code` Product           `Product Type` `Budget COGS` `Budget Margin`
##         <dbl> <chr>             <chr>                  <dbl>           <dbl>
## 1         719 Amaretto          Coffee                    90             130
## 2         970 Colombian         Coffee                    80             110
## 3         970 Decaf Irish Cream Coffee                   100             140
## 4         303 Green Tea         Tea                       30              50
## 5         303 Caffe Mocha       Espresso                  60              90
## 6         720 Decaf Espresso    Espresso                  80             130
## # ℹ 2 more variables: `Budget Profit` <dbl>, `Budget Sales` <dbl>

Eksplorasi Data

summary(Data_Kopi1)
##    Area Code       Product          Product Type        Budget COGS    
##  Min.   :203.0   Length:4248        Length:4248        Min.   :  0.00  
##  1st Qu.:417.0   Class :character   Class :character   1st Qu.: 30.00  
##  Median :573.0   Mode  :character   Mode  :character   Median : 50.00  
##  Mean   :582.3                                         Mean   : 74.83  
##  3rd Qu.:772.0                                         3rd Qu.: 90.00  
##  Max.   :985.0                                         Max.   :450.00  
##  Budget Margin    Budget Profit      Budget Sales   
##  Min.   :-210.0   Min.   :-320.00   Min.   :   0.0  
##  1st Qu.:  50.0   1st Qu.:  20.00   1st Qu.:  80.0  
##  Median :  70.0   Median :  40.00   Median : 130.0  
##  Mean   : 100.8   Mean   :  60.91   Mean   : 175.6  
##  3rd Qu.: 130.0   3rd Qu.:  80.00   3rd Qu.: 210.0  
##  Max.   : 690.0   Max.   : 560.00   Max.   :1140.0
tail(Data_Kopi1)
## # A tibble: 6 × 7
##   `Area Code` Product           `Product Type` `Budget COGS` `Budget Margin`
##         <dbl> <chr>             <chr>                  <dbl>           <dbl>
## 1         425 Lemon             Herbal Tea                40              70
## 2         206 Caffe Latte       Espresso                  20              30
## 3         509 Caffe Mocha       Espresso                  60              80
## 4         360 Decaf Espresso    Espresso                  70             100
## 5         360 Colombian         Coffee                    80             120
## 6         206 Decaf Irish Cream Coffee                   120             170
## # ℹ 2 more variables: `Budget Profit` <dbl>, `Budget Sales` <dbl>
names(Data_Kopi1)
## [1] "Area Code"     "Product"       "Product Type"  "Budget COGS"  
## [5] "Budget Margin" "Budget Profit" "Budget Sales"
dim(Data_Kopi1)
## [1] 4248    7

Produk Yang Paling Laku

produk_count <- sort(table(Data_Kopi1$`Product Type`), decreasing = TRUE)

barplot(produk_count,
        main = "Produk Paling Laku",
        xlab = "Product Type",
        ylab = "Frekuensi",
        col = "cyan",
        border = "white")

# Total Sales & Profit per Product Type

Data_Kopi_Urut <- Data_Kopi %>%
  group_by(`Product Type`) %>%
  summarise(
    total_sales = sum(Sales, na.rm = TRUE),
    total_profit = sum(Profit, na.rm = TRUE)
  ) %>%
  arrange(desc(total_sales))

Data_Kopi_Urut
## # A tibble: 4 × 3
##   `Product Type` total_sales total_profit
##   <chr>                <dbl>        <dbl>
## 1 Espresso            222996        68620
## 2 Coffee              216828        74683
## 3 Herbal Tea          207214        63254
## 4 Tea                 172773        52986

Visualisasi Total Sales

barplot(Data_Kopi_Urut$total_sales,
        names.arg = Data_Kopi_Urut$`Product Type`,
        main = "Total Sales per Product Type",
        xlab = "Product Type",
        ylab = "Total Sales",
        col = "cyan",
        border = "white",
        las = 2)

# Visualisasi Total Profit

Kopi_profit <- Data_Kopi_Urut %>%
  arrange(desc(total_profit))

barplot(Kopi_profit$total_profit,
        names.arg = Kopi_profit$`Product Type`,
        main = "Total Profit per Product Type",
        xlab = "Product Type",
        ylab = "Total Profit",
        col = "cyan",
        border = "white",
        las = 2)

# Ranking Produk

Data_Kopi_Urut_rank <- Data_Kopi_Urut %>%
  mutate(
    rank_sales = rank(-total_sales),
    rank_profit = rank(-total_profit)
  )

Data_Kopi_Urut_rank
## # A tibble: 4 × 5
##   `Product Type` total_sales total_profit rank_sales rank_profit
##   <chr>                <dbl>        <dbl>      <dbl>       <dbl>
## 1 Espresso            222996        68620          1           2
## 2 Coffee              216828        74683          2           1
## 3 Herbal Tea          207214        63254          3           3
## 4 Tea                 172773        52986          4           4

Uji Hipotesis

Korelasi Pearson

Korelasi <- cor.test(Data_Kopi_Urut$total_sales,
                     Data_Kopi_Urut$total_profit)

cat("Nilai Korelasi:", Korelasi$estimate, "\n")
## Nilai Korelasi: 0.9095054
cat("p-value:", Korelasi$p.value, "\n\n")
## p-value: 0.09049455
if (Korelasi$p.value < 0.05) {
  cat("Keputusan: TOLAK H0\n")
  cat("Artinya: Ada hubungan signifikan antara total sales dan total profit\n")
} else {
  cat("Keputusan: GAGAL TOLAK H0\n")
  cat("Artinya: Tidak ada hubungan signifikan antara total sales dan total profit\n")
}
## Keputusan: GAGAL TOLAK H0
## Artinya: Tidak ada hubungan signifikan antara total sales dan total profit

Hasil Uji KOrelasi

## Berdasarkan hasil uji korelasi Pearson, diperoleh nilai koefisien korelasi sebesar 0.9095 dengan p-value sebesar 0.0905. 
##   Hal ini menunjukkan bahwa hubungan antara total sales dan total profit bersifat positif. 
##   Karena p-value ≥ 0,05, maka keputusan yang diambil adalah gagal menolak H0. 
##   Dengan demikian, dapat disimpulkan bahwa tidak terdapat hubungan yang signifikan antara total sales dan total profit.

Interpretasi

Berdasarkan hasil uji korelasi Pearson, diperoleh nilai koefisien korelasi sebesar 0,9095 yang menunjukkan adanya hubungan positif sangat kuat antara total sales dan total profit. Hal ini mengindikasikan bahwa secara pola, peningkatan penjualan cenderung diikuti oleh peningkatan keuntungan.

Namun, nilai p-value sebesar 0,0905 lebih besar dari 0,05, sehingga keputusan yang diambil adalah gagal menolak H0. Dengan demikian, secara statistik hubungan tersebut tidak signifikan pada taraf signifikansi 5%.

Kondisi ini menunjukkan bahwa meskipun secara numerik hubungan terlihat sangat kuat, data yang digunakan belum cukup mendukung untuk menyimpulkan adanya hubungan yang signifikan. Hal ini dapat disebabkan oleh jumlah data yang terbatas atau variasi data yang kurang.

Secara praktis, hasil ini mengindikasikan bahwa peningkatan sales belum tentu secara konsisten diikuti oleh peningkatan profit, sehingga diperlukan analisis lebih lanjut terhadap faktor lain seperti biaya (COGS), margin, dan efisiensi operasional.