1 Import data & libraries

1.1 Load libraries

# Load libraries
library(dplyr)
## 
## 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(psych)
library(tidyr)
library(factoextra)
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(knitr)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
## 
##     group_rows

1.2 Import

data <- read.csv("genz_mental_wellness_synthetic_dataset.csv")
head(data)
##   Age Gender   Country Student_Working_Status Daily_Social_Media_Hours
## 1  24   Male    Canada                Working                     4.81
## 2  21   Male       USA                Student                     4.16
## 3  25   Male  Pakistan                Student                     3.07
## 4  22 Female  Pakistan                Student                     4.41
## 5  24   Male  Pakistan                Student                     2.97
## 6  20   Male Australia                   Both                     6.06
##   Screen_Time_Hours Night_Scrolling_Frequency Online_Gaming_Hours
## 1              6.93                      2.61                2.07
## 2              7.94                      1.85                3.58
## 3              7.45                      2.96                2.85
## 4              7.34                      4.51                3.37
## 5              5.76                      2.36                1.77
## 6              8.75                      4.60                0.61
##   Content_Type_Preference Exercise_Frequency_per_Week Daily_Sleep_Hours
## 1                    News                        5.41              6.84
## 2                  Gaming                        3.41              7.88
## 3           Entertainment                        3.40              6.39
## 4             Educational                        2.19              7.92
## 5             Educational                        4.93              5.97
## 6                  Gaming                        5.51              6.70
##   Caffeine_Intake_Cups Study_Work_Hours_per_Day Overthinking_Score
## 1                 1.52                    11.42               4.95
## 2                 2.23                     6.98               5.91
## 3                 0.53                     7.79               4.06
## 4                 0.58                     6.61               6.10
## 5                 1.64                     4.81               5.22
## 6                 0.00                     6.44               6.19
##   Anxiety_Score Mood_Stability_Score Social_Comparison_Index
## 1          4.13                 5.74                    4.67
## 2          3.63                 5.75                    5.38
## 3          5.67                 6.03                    2.41
## 4          4.78                 4.85                    5.86
## 5          4.23                 5.05                    5.54
## 6          4.29                 3.21                    5.99
##   Sleep_Quality_Score Motivation_Level Emotional_Fatigue_Score Wellbeing_Index
## 1                6.27             6.13                    6.45            4.28
## 2                7.37             6.27                    3.74            5.23
## 3                6.48             4.82                    6.69            3.72
## 4                7.27             5.17                    5.96            3.97
## 5                6.34             5.72                    2.22            4.63
## 6                7.55             4.88                    6.35            3.44
##   Burnout_Risk
## 1       Medium
## 2       Medium
## 3         High
## 4         High
## 5       Medium
## 6         High

1.3 Cek karakteristik data

str(data)
## 'data.frame':    10000 obs. of  22 variables:
##  $ Age                        : int  24 21 25 22 24 20 24 25 22 21 ...
##  $ Gender                     : chr  "Male" "Male" "Male" "Female" ...
##  $ Country                    : chr  "Canada" "USA" "Pakistan" "Pakistan" ...
##  $ Student_Working_Status     : chr  "Working" "Student" "Student" "Student" ...
##  $ Daily_Social_Media_Hours   : num  4.81 4.16 3.07 4.41 2.97 6.06 3.68 4.64 6.5 3.73 ...
##  $ Screen_Time_Hours          : num  6.93 7.94 7.45 7.34 5.76 8.75 6.15 6.7 9.61 5.97 ...
##  $ Night_Scrolling_Frequency  : num  2.61 1.85 2.96 4.51 2.36 4.6 1.68 4.24 4.33 4.26 ...
##  $ Online_Gaming_Hours        : num  2.07 3.58 2.85 3.37 1.77 0.61 1.65 1.66 0 0.98 ...
##  $ Content_Type_Preference    : chr  "News" "Gaming" "Entertainment" "Educational" ...
##  $ Exercise_Frequency_per_Week: num  5.41 3.41 3.4 2.19 4.93 5.51 3.61 2.21 1.41 1.94 ...
##  $ Daily_Sleep_Hours          : num  6.84 7.88 6.39 7.92 5.97 6.7 5.18 6.27 6.78 4.65 ...
##  $ Caffeine_Intake_Cups       : num  1.52 2.23 0.53 0.58 1.64 0 1.5 2.46 1.89 2.9 ...
##  $ Study_Work_Hours_per_Day   : num  11.42 6.98 7.79 6.61 4.81 ...
##  $ Overthinking_Score         : num  4.95 5.91 4.06 6.1 5.22 6.19 5.31 4.07 5.32 4.46 ...
##  $ Anxiety_Score              : num  4.13 3.63 5.67 4.78 4.23 4.29 5.29 4.36 5.26 4.67 ...
##  $ Mood_Stability_Score       : num  5.74 5.75 6.03 4.85 5.05 3.21 6.23 3.68 3.54 5.91 ...
##  $ Social_Comparison_Index    : num  4.67 5.38 2.41 5.86 5.54 5.99 3.07 4.16 5.15 4.63 ...
##  $ Sleep_Quality_Score        : num  6.27 7.37 6.48 7.27 6.34 7.55 4.79 7.18 7.17 4.61 ...
##  $ Motivation_Level           : num  6.13 6.27 4.82 5.17 5.72 4.88 5.51 2.8 4.51 6.06 ...
##  $ Emotional_Fatigue_Score    : num  6.45 3.74 6.69 5.96 2.22 6.35 5.87 6.03 5.59 5.38 ...
##  $ Wellbeing_Index            : num  4.28 5.23 3.72 3.97 4.63 3.44 3.65 2.82 3.27 3.85 ...
##  $ Burnout_Risk               : chr  "Medium" "Medium" "High" "High" ...
dim(data)
## [1] 10000    22
summary(data)
##       Age           Gender            Country          Student_Working_Status
##  Min.   :18.00   Length:10000       Length:10000       Length:10000          
##  1st Qu.:20.00   Class :character   Class :character   Class :character      
##  Median :22.00   Mode  :character   Mode  :character   Mode  :character      
##  Mean   :21.99                                                               
##  3rd Qu.:24.00                                                               
##  Max.   :26.00                                                               
##  Daily_Social_Media_Hours Screen_Time_Hours Night_Scrolling_Frequency
##  Min.   : 0.500           Min.   : 2.000    Min.   :0.000            
##  1st Qu.: 3.010           1st Qu.: 5.810    1st Qu.:2.188            
##  Median : 3.990           Median : 7.000    Median :2.980            
##  Mean   : 4.006           Mean   : 7.017    Mean   :2.986            
##  3rd Qu.: 4.982           3rd Qu.: 8.210    3rd Qu.:3.790            
##  Max.   :10.000           Max.   :14.000    Max.   :7.000            
##  Online_Gaming_Hours Content_Type_Preference Exercise_Frequency_per_Week
##  Min.   :0.000       Length:10000            Min.   :0.000              
##  1st Qu.:0.470       Class :character        1st Qu.:1.960              
##  Median :1.460       Mode  :character        Median :3.010              
##  Mean   :1.607                               Mean   :2.995              
##  3rd Qu.:2.500                               3rd Qu.:4.000              
##  Max.   :6.000                               Max.   :7.000              
##  Daily_Sleep_Hours Caffeine_Intake_Cups Study_Work_Hours_per_Day
##  Min.   : 3.000    Min.   :0.000        Min.   : 1.000          
##  1st Qu.: 5.710    1st Qu.:0.800        1st Qu.: 4.700          
##  Median : 6.520    Median :1.480        Median : 6.030          
##  Mean   : 6.512    Mean   :1.506        Mean   : 6.031          
##  3rd Qu.: 7.320    3rd Qu.:2.150        3rd Qu.: 7.340          
##  Max.   :10.000    Max.   :6.000        Max.   :13.050          
##  Overthinking_Score Anxiety_Score   Mood_Stability_Score
##  Min.   :1.000      Min.   :1.000   Min.   : 1.000      
##  1st Qu.:4.240      1st Qu.:3.840   1st Qu.: 4.310      
##  Median :5.000      Median :4.740   Median : 5.170      
##  Mean   :5.002      Mean   :4.748   Mean   : 5.161      
##  3rd Qu.:5.760      3rd Qu.:5.630   3rd Qu.: 6.000      
##  Max.   :9.510      Max.   :9.690   Max.   :10.000      
##  Social_Comparison_Index Sleep_Quality_Score Motivation_Level
##  Min.   :1.000           Min.   : 1.020      Min.   : 1.000  
##  1st Qu.:3.470           1st Qu.: 5.550      1st Qu.: 4.200  
##  Median :4.400           Median : 6.530      Median : 5.080  
##  Mean   :4.404           Mean   : 6.514      Mean   : 5.086  
##  3rd Qu.:5.320           3rd Qu.: 7.490      3rd Qu.: 5.950  
##  Max.   :9.420           Max.   :10.000      Max.   :10.000  
##  Emotional_Fatigue_Score Wellbeing_Index Burnout_Risk      
##  Min.   : 1.000          Min.   :1.00    Length:10000      
##  1st Qu.: 4.620          1st Qu.:3.02    Class :character  
##  Median : 5.580          Median :3.87    Mode  :character  
##  Mean   : 5.582          Mean   :3.87                      
##  3rd Qu.: 6.540          3rd Qu.:4.70                      
##  Max.   :10.000          Max.   :8.86
colnames(data)
##  [1] "Age"                         "Gender"                     
##  [3] "Country"                     "Student_Working_Status"     
##  [5] "Daily_Social_Media_Hours"    "Screen_Time_Hours"          
##  [7] "Night_Scrolling_Frequency"   "Online_Gaming_Hours"        
##  [9] "Content_Type_Preference"     "Exercise_Frequency_per_Week"
## [11] "Daily_Sleep_Hours"           "Caffeine_Intake_Cups"       
## [13] "Study_Work_Hours_per_Day"    "Overthinking_Score"         
## [15] "Anxiety_Score"               "Mood_Stability_Score"       
## [17] "Social_Comparison_Index"     "Sleep_Quality_Score"        
## [19] "Motivation_Level"            "Emotional_Fatigue_Score"    
## [21] "Wellbeing_Index"             "Burnout_Risk"

1.4 Cek type variabel

struktur_data <- data.frame(
  Nama_Variabel = names(data),
  Tipe_Data = sapply(data, class)
)

kable(struktur_data, caption = "Struktur Variabel Dataset") %>%
  kable_styling(bootstrap_options = c("striped","hover","condensed"))
Struktur Variabel Dataset
Nama_Variabel Tipe_Data
Age Age integer
Gender Gender character
Country Country character
Student_Working_Status Student_Working_Status character
Daily_Social_Media_Hours Daily_Social_Media_Hours numeric
Screen_Time_Hours Screen_Time_Hours numeric
Night_Scrolling_Frequency Night_Scrolling_Frequency numeric
Online_Gaming_Hours Online_Gaming_Hours numeric
Content_Type_Preference Content_Type_Preference character
Exercise_Frequency_per_Week Exercise_Frequency_per_Week numeric
Daily_Sleep_Hours Daily_Sleep_Hours numeric
Caffeine_Intake_Cups Caffeine_Intake_Cups numeric
Study_Work_Hours_per_Day Study_Work_Hours_per_Day numeric
Overthinking_Score Overthinking_Score numeric
Anxiety_Score Anxiety_Score numeric
Mood_Stability_Score Mood_Stability_Score numeric
Social_Comparison_Index Social_Comparison_Index numeric
Sleep_Quality_Score Sleep_Quality_Score numeric
Motivation_Level Motivation_Level numeric
Emotional_Fatigue_Score Emotional_Fatigue_Score numeric
Wellbeing_Index Wellbeing_Index numeric
Burnout_Risk Burnout_Risk character

1.5 Pilah variabel

hanya memakai variabel numeric

data_pca <- data[, sapply(data, is.numeric)]
head(data_pca)
##   Age Daily_Social_Media_Hours Screen_Time_Hours Night_Scrolling_Frequency
## 1  24                     4.81              6.93                      2.61
## 2  21                     4.16              7.94                      1.85
## 3  25                     3.07              7.45                      2.96
## 4  22                     4.41              7.34                      4.51
## 5  24                     2.97              5.76                      2.36
## 6  20                     6.06              8.75                      4.60
##   Online_Gaming_Hours Exercise_Frequency_per_Week Daily_Sleep_Hours
## 1                2.07                        5.41              6.84
## 2                3.58                        3.41              7.88
## 3                2.85                        3.40              6.39
## 4                3.37                        2.19              7.92
## 5                1.77                        4.93              5.97
## 6                0.61                        5.51              6.70
##   Caffeine_Intake_Cups Study_Work_Hours_per_Day Overthinking_Score
## 1                 1.52                    11.42               4.95
## 2                 2.23                     6.98               5.91
## 3                 0.53                     7.79               4.06
## 4                 0.58                     6.61               6.10
## 5                 1.64                     4.81               5.22
## 6                 0.00                     6.44               6.19
##   Anxiety_Score Mood_Stability_Score Social_Comparison_Index
## 1          4.13                 5.74                    4.67
## 2          3.63                 5.75                    5.38
## 3          5.67                 6.03                    2.41
## 4          4.78                 4.85                    5.86
## 5          4.23                 5.05                    5.54
## 6          4.29                 3.21                    5.99
##   Sleep_Quality_Score Motivation_Level Emotional_Fatigue_Score Wellbeing_Index
## 1                6.27             6.13                    6.45            4.28
## 2                7.37             6.27                    3.74            5.23
## 3                6.48             4.82                    6.69            3.72
## 4                7.27             5.17                    5.96            3.97
## 5                6.34             5.72                    2.22            4.63
## 6                7.55             4.88                    6.35            3.44

1.6 Statistik deskriptif

data.frame(
  Variabel = colnames(data_pca),
  Minimum = apply(data_pca, 2, min),
  Maksimum = apply(data_pca, 2, max),
  Mean = apply(data_pca, 2, mean),
  SD = apply(data_pca, 2, sd)
)
##                                                Variabel Minimum Maksimum
## Age                                                 Age   18.00    26.00
## Daily_Social_Media_Hours       Daily_Social_Media_Hours    0.50    10.00
## Screen_Time_Hours                     Screen_Time_Hours    2.00    14.00
## Night_Scrolling_Frequency     Night_Scrolling_Frequency    0.00     7.00
## Online_Gaming_Hours                 Online_Gaming_Hours    0.00     6.00
## Exercise_Frequency_per_Week Exercise_Frequency_per_Week    0.00     7.00
## Daily_Sleep_Hours                     Daily_Sleep_Hours    3.00    10.00
## Caffeine_Intake_Cups               Caffeine_Intake_Cups    0.00     6.00
## Study_Work_Hours_per_Day       Study_Work_Hours_per_Day    1.00    13.05
## Overthinking_Score                   Overthinking_Score    1.00     9.51
## Anxiety_Score                             Anxiety_Score    1.00     9.69
## Mood_Stability_Score               Mood_Stability_Score    1.00    10.00
## Social_Comparison_Index         Social_Comparison_Index    1.00     9.42
## Sleep_Quality_Score                 Sleep_Quality_Score    1.02    10.00
## Motivation_Level                       Motivation_Level    1.00    10.00
## Emotional_Fatigue_Score         Emotional_Fatigue_Score    1.00    10.00
## Wellbeing_Index                         Wellbeing_Index    1.00     8.86
##                                  Mean        SD
## Age                         21.992900 2.5893088
## Daily_Social_Media_Hours     4.005883 1.4805089
## Screen_Time_Hours            7.016991 1.7925289
## Night_Scrolling_Frequency    2.986009 1.1970353
## Online_Gaming_Hours          1.607241 1.3000446
## Exercise_Frequency_per_Week  2.994855 1.4782478
## Daily_Sleep_Hours            6.512031 1.1941936
## Caffeine_Intake_Cups         1.505871 0.9340687
## Study_Work_Hours_per_Day     6.030983 1.9753370
## Overthinking_Score           5.001868 1.1431790
## Anxiety_Score                4.747556 1.3055925
## Mood_Stability_Score         5.161021 1.2570548
## Social_Comparison_Index      4.403556 1.3364786
## Sleep_Quality_Score          6.514447 1.4278061
## Motivation_Level             5.086132 1.3083508
## Emotional_Fatigue_Score      5.582222 1.4165579
## Wellbeing_Index              3.870213 1.2389397
data_pca <- as.data.frame(data_pca)

data_long <- tidyr::pivot_longer(data_pca,
                                 cols = everything(),
                                 names_to = "variable",
                                 values_to = "value")

ggplot(data_long, aes(variable, value)) +
  geom_boxplot(fill = "lightblue") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Boxplot 17 Variabel Numerik (EDA)")

1.7 Cek missing value

missing_jumlah <- colSums(is.na(data_pca))

tabel_missing <- data.frame(
  Nama_Variabel = names(missing_jumlah),
  Jumlah_Missing = missing_jumlah
)

tabel_missing
##                                           Nama_Variabel Jumlah_Missing
## Age                                                 Age              0
## Daily_Social_Media_Hours       Daily_Social_Media_Hours              0
## Screen_Time_Hours                     Screen_Time_Hours              0
## Night_Scrolling_Frequency     Night_Scrolling_Frequency              0
## Online_Gaming_Hours                 Online_Gaming_Hours              0
## Exercise_Frequency_per_Week Exercise_Frequency_per_Week              0
## Daily_Sleep_Hours                     Daily_Sleep_Hours              0
## Caffeine_Intake_Cups               Caffeine_Intake_Cups              0
## Study_Work_Hours_per_Day       Study_Work_Hours_per_Day              0
## Overthinking_Score                   Overthinking_Score              0
## Anxiety_Score                             Anxiety_Score              0
## Mood_Stability_Score               Mood_Stability_Score              0
## Social_Comparison_Index         Social_Comparison_Index              0
## Sleep_Quality_Score                 Sleep_Quality_Score              0
## Motivation_Level                       Motivation_Level              0
## Emotional_Fatigue_Score         Emotional_Fatigue_Score              0
## Wellbeing_Index                         Wellbeing_Index              0

1.8 Standarisasi

## Standarisasi
data_scaled <- scale(data_pca)

data_scaled_df <- as.data.frame(data_scaled)

head(data_scaled_df) %>%
  kable(caption = "Data Setelah Standarisasi (6 Observasi Pertama)") %>%
  kable_styling(
    bootstrap_options = c("striped","hover","condensed"),
    full_width = FALSE
  )
Data Setelah Standarisasi (6 Observasi Pertama)
Age Daily_Social_Media_Hours Screen_Time_Hours Night_Scrolling_Frequency Online_Gaming_Hours Exercise_Frequency_per_Week Daily_Sleep_Hours Caffeine_Intake_Cups Study_Work_Hours_per_Day Overthinking_Score Anxiety_Score Mood_Stability_Score Social_Comparison_Index Sleep_Quality_Score Motivation_Level Emotional_Fatigue_Score Wellbeing_Index
0.7751490 0.5431355 -0.0485298 -0.3141169 0.3559563 1.6337890 0.2746364 0.0151263 2.7281506 -0.0453717 -0.4730082 0.4605837 0.1993627 -0.1712046 0.7978502 0.6125962 0.3307562
-0.3834614 0.1040973 0.5149200 -0.9490188 1.5174549 0.2808359 1.1455169 0.7752417 0.4804330 0.7943918 -0.8559761 0.4685388 0.7306095 0.5992081 0.9048552 -1.3004919 1.0975409
1.1613524 -0.6321360 0.2415632 -0.0217278 0.9559357 0.2740711 -0.1021869 -1.0447529 0.8904896 -0.8239025 0.7065328 0.6912817 -1.4916483 -0.0241258 -0.2034103 0.7820210 -0.1212432
0.0027420 0.2729582 0.1801974 1.2731379 1.3559220 -0.5444655 1.1790123 -0.9912237 0.2931231 0.9605950 0.0248500 -0.2474204 1.0897623 0.5291706 0.0641021 0.2666873 0.0805423
0.7751490 -0.6996803 -0.7012389 -0.5229662 0.1251949 1.3090802 -0.4538887 0.1435965 -0.6181138 0.1908118 -0.3964146 -0.0883183 0.8503271 -0.1221784 0.4844786 -2.3735154 0.6132558
-0.7696649 1.3874398 0.9667956 1.3483237 -0.7670822 1.7014366 0.1574024 -1.6121630 0.2070619 1.0393228 -0.3504585 -1.5520572 1.1870328 0.7252756 -0.1575510 0.5420026 -0.3472429

1.9 Cek korelasi

cor_matrix <- cor(data_scaled)
round(cor_matrix, 2)
##                               Age Daily_Social_Media_Hours Screen_Time_Hours
## Age                          1.00                     0.00              0.00
## Daily_Social_Media_Hours     0.00                     1.00              0.83
## Screen_Time_Hours            0.00                     0.83              1.00
## Night_Scrolling_Frequency    0.00                    -0.01             -0.01
## Online_Gaming_Hours          0.00                     0.00             -0.01
## Exercise_Frequency_per_Week -0.01                     0.00              0.00
## Daily_Sleep_Hours            0.02                    -0.01             -0.01
## Caffeine_Intake_Cups         0.00                     0.00              0.00
## Study_Work_Hours_per_Day     0.01                     0.01              0.00
## Overthinking_Score           0.00                     0.26              0.21
## Anxiety_Score               -0.01                     0.11              0.10
## Mood_Stability_Score         0.00                    -0.08             -0.07
## Social_Comparison_Index      0.00                     0.66              0.56
## Sleep_Quality_Score          0.02                    -0.01             -0.02
## Motivation_Level             0.01                    -0.04             -0.03
## Emotional_Fatigue_Score      0.02                     0.38              0.44
## Wellbeing_Index              0.01                    -0.13             -0.14
##                             Night_Scrolling_Frequency Online_Gaming_Hours
## Age                                              0.00                0.00
## Daily_Social_Media_Hours                        -0.01                0.00
## Screen_Time_Hours                               -0.01               -0.01
## Night_Scrolling_Frequency                        1.00                0.01
## Online_Gaming_Hours                              0.01                1.00
## Exercise_Frequency_per_Week                     -0.01                0.00
## Daily_Sleep_Hours                                0.00               -0.01
## Caffeine_Intake_Cups                             0.00               -0.01
## Study_Work_Hours_per_Day                         0.01                0.01
## Overthinking_Score                               0.42               -0.02
## Anxiety_Score                                    0.20                0.00
## Mood_Stability_Score                            -0.12                0.01
## Social_Comparison_Index                         -0.01               -0.01
## Sleep_Quality_Score                              0.00                0.00
## Motivation_Level                                -0.07               -0.01
## Emotional_Fatigue_Score                          0.10                0.00
## Wellbeing_Index                                 -0.12                0.00
##                             Exercise_Frequency_per_Week Daily_Sleep_Hours
## Age                                               -0.01              0.02
## Daily_Social_Media_Hours                           0.00             -0.01
## Screen_Time_Hours                                  0.00             -0.01
## Night_Scrolling_Frequency                         -0.01              0.00
## Online_Gaming_Hours                                0.00             -0.01
## Exercise_Frequency_per_Week                        1.00              0.00
## Daily_Sleep_Hours                                  0.00              1.00
## Caffeine_Intake_Cups                               0.00             -0.01
## Study_Work_Hours_per_Day                           0.00             -0.01
## Overthinking_Score                                -0.01              0.00
## Anxiety_Score                                      0.00             -0.45
## Mood_Stability_Score                               0.01              0.28
## Social_Comparison_Index                           -0.02             -0.01
## Sleep_Quality_Score                                0.00              0.83
## Motivation_Level                                   0.34              0.50
## Emotional_Fatigue_Score                           -0.31             -0.22
## Wellbeing_Index                                    0.18              0.70
##                             Caffeine_Intake_Cups Study_Work_Hours_per_Day
## Age                                         0.00                     0.01
## Daily_Social_Media_Hours                    0.00                     0.01
## Screen_Time_Hours                           0.00                     0.00
## Night_Scrolling_Frequency                   0.00                     0.01
## Online_Gaming_Hours                        -0.01                     0.01
## Exercise_Frequency_per_Week                 0.00                     0.00
## Daily_Sleep_Hours                          -0.01                    -0.01
## Caffeine_Intake_Cups                        1.00                    -0.01
## Study_Work_Hours_per_Day                   -0.01                     1.00
## Overthinking_Score                         -0.01                     0.01
## Anxiety_Score                               0.00                     0.02
## Mood_Stability_Score                       -0.01                    -0.01
## Social_Comparison_Index                    -0.01                     0.00
## Sleep_Quality_Score                        -0.01                    -0.02
## Motivation_Level                            0.00                    -0.01
## Emotional_Fatigue_Score                     0.01                     0.01
## Wellbeing_Index                            -0.01                    -0.02
##                             Overthinking_Score Anxiety_Score
## Age                                       0.00         -0.01
## Daily_Social_Media_Hours                  0.26          0.11
## Screen_Time_Hours                         0.21          0.10
## Night_Scrolling_Frequency                 0.42          0.20
## Online_Gaming_Hours                      -0.02          0.00
## Exercise_Frequency_per_Week              -0.01          0.00
## Daily_Sleep_Hours                         0.00         -0.45
## Caffeine_Intake_Cups                     -0.01          0.00
## Study_Work_Hours_per_Day                  0.01          0.02
## Overthinking_Score                        1.00          0.44
## Anxiety_Score                             0.44          1.00
## Mood_Stability_Score                     -0.27         -0.62
## Social_Comparison_Index                   0.16          0.08
## Sleep_Quality_Score                       0.00         -0.37
## Motivation_Level                         -0.15         -0.46
## Emotional_Fatigue_Score                   0.29          0.50
## Wellbeing_Index                          -0.28         -0.78
##                             Mood_Stability_Score Social_Comparison_Index
## Age                                         0.00                    0.00
## Daily_Social_Media_Hours                   -0.08                    0.66
## Screen_Time_Hours                          -0.07                    0.56
## Night_Scrolling_Frequency                  -0.12                   -0.01
## Online_Gaming_Hours                         0.01                   -0.01
## Exercise_Frequency_per_Week                 0.01                   -0.02
## Daily_Sleep_Hours                           0.28                   -0.01
## Caffeine_Intake_Cups                       -0.01                   -0.01
## Study_Work_Hours_per_Day                   -0.01                    0.00
## Overthinking_Score                         -0.27                    0.16
## Anxiety_Score                              -0.62                    0.08
## Mood_Stability_Score                        1.00                   -0.06
## Social_Comparison_Index                    -0.06                    1.00
## Sleep_Quality_Score                         0.23                   -0.02
## Motivation_Level                            0.29                   -0.03
## Emotional_Fatigue_Score                    -0.31                    0.26
## Wellbeing_Index                             0.69                   -0.10
##                             Sleep_Quality_Score Motivation_Level
## Age                                        0.02             0.01
## Daily_Social_Media_Hours                  -0.01            -0.04
## Screen_Time_Hours                         -0.02            -0.03
## Night_Scrolling_Frequency                  0.00            -0.07
## Online_Gaming_Hours                        0.00            -0.01
## Exercise_Frequency_per_Week                0.00             0.34
## Daily_Sleep_Hours                          0.83             0.50
## Caffeine_Intake_Cups                      -0.01             0.00
## Study_Work_Hours_per_Day                  -0.02            -0.01
## Overthinking_Score                         0.00            -0.15
## Anxiety_Score                             -0.37            -0.46
## Mood_Stability_Score                       0.23             0.29
## Social_Comparison_Index                   -0.02            -0.03
## Sleep_Quality_Score                        1.00             0.40
## Motivation_Level                           0.40             1.00
## Emotional_Fatigue_Score                   -0.19            -0.34
## Wellbeing_Index                            0.70             0.74
##                             Emotional_Fatigue_Score Wellbeing_Index
## Age                                            0.02            0.01
## Daily_Social_Media_Hours                       0.38           -0.13
## Screen_Time_Hours                              0.44           -0.14
## Night_Scrolling_Frequency                      0.10           -0.12
## Online_Gaming_Hours                            0.00            0.00
## Exercise_Frequency_per_Week                   -0.31            0.18
## Daily_Sleep_Hours                             -0.22            0.70
## Caffeine_Intake_Cups                           0.01           -0.01
## Study_Work_Hours_per_Day                       0.01           -0.02
## Overthinking_Score                             0.29           -0.28
## Anxiety_Score                                  0.50           -0.78
## Mood_Stability_Score                          -0.31            0.69
## Social_Comparison_Index                        0.26           -0.10
## Sleep_Quality_Score                           -0.19            0.70
## Motivation_Level                              -0.34            0.74
## Emotional_Fatigue_Score                        1.00           -0.57
## Wellbeing_Index                               -0.57            1.00
library(corrplot)
## corrplot 0.95 loaded
corrplot(cor_matrix, method = "color", type = "upper")

# Uji kelayakan PCA

1.10 Uji KMO

kmo_result <- KMO(data_scaled)
kmo_per_var <- data.frame(
  Variabel = names(kmo_result$MSAi),
  MSA = round(kmo_result$MSAi, 4)
)

kable(kmo_per_var, caption = "Nilai MSA Setiap Variabel") %>%
  kable_styling(
    bootstrap_options = c("striped","hover","condensed"),
    full_width = FALSE
  )
Nilai MSA Setiap Variabel
Variabel MSA
Age Age 0.7771
Daily_Social_Media_Hours Daily_Social_Media_Hours 0.6649
Screen_Time_Hours Screen_Time_Hours 0.7141
Night_Scrolling_Frequency Night_Scrolling_Frequency 0.6272
Online_Gaming_Hours Online_Gaming_Hours 0.3616
Exercise_Frequency_per_Week Exercise_Frequency_per_Week 0.8097
Daily_Sleep_Hours Daily_Sleep_Hours 0.9635
Caffeine_Intake_Cups Caffeine_Intake_Cups 0.4511
Study_Work_Hours_per_Day Study_Work_Hours_per_Day 0.6613
Overthinking_Score Overthinking_Score 0.7841
Anxiety_Score Anxiety_Score 0.3570
Mood_Stability_Score Mood_Stability_Score 0.2268
Social_Comparison_Index Social_Comparison_Index 0.8204
Sleep_Quality_Score Sleep_Quality_Score 0.2612
Motivation_Level Motivation_Level 0.2567
Emotional_Fatigue_Score Emotional_Fatigue_Score 0.2658
Wellbeing_Index Wellbeing_Index 0.4049
# Ambil nama variabel dengan MSA >= 0.5
variabel_lolos <- names(kmo_result$MSAi[kmo_result$MSAi >= 0.5])

variabel_lolos
## [1] "Age"                         "Daily_Social_Media_Hours"   
## [3] "Screen_Time_Hours"           "Night_Scrolling_Frequency"  
## [5] "Exercise_Frequency_per_Week" "Daily_Sleep_Hours"          
## [7] "Study_Work_Hours_per_Day"    "Overthinking_Score"         
## [9] "Social_Comparison_Index"
data_reduced <- data_scaled[, variabel_lolos]

kmo_result2 <- KMO(data_reduced)
kmo_result2$MSA   # ini nilai KMO overall
## [1] 0.6511046

1.11 Uji Bartlett

cortest.bartlett(data_reduced)
## R was not square, finding R from data
## $chisq
## [1] 20178.46
## 
## $p.value
## [1] 0
## 
## $df
## [1] 36

2 Uji PCA

pca_awal <- principal(data_reduced, nfactors = ncol(data_reduced), rotate = "none")
pca_awal$values
## [1] 2.4693112 1.3638372 1.0232638 1.0108038 0.9946897 0.9713043 0.5508143
## [8] 0.4603357 0.1556401

2.1 Cek eigeen value

eigen_values <- pca_awal$values

tabel_eigen <- data.frame(
  Komponen = paste0("PC", 1:length(eigen_values)),
  Eigenvalue = round(eigen_values, 4),
  Keputusan = ifelse(eigen_values > 1, "Dipertahankan", "Tidak")
)

kable(tabel_eigen, caption = "Eigenvalue dan Keputusan Jumlah Komponen") %>%
  kable_styling(
    bootstrap_options = c("striped","hover","condensed"),
    full_width = FALSE
  )
Eigenvalue dan Keputusan Jumlah Komponen
Komponen Eigenvalue Keputusan
PC1 2.4693 Dipertahankan
PC2 1.3638 Dipertahankan
PC3 1.0233 Dipertahankan
PC4 1.0108 Dipertahankan
PC5 0.9947 Tidak
PC6 0.9713 Tidak
PC7 0.5508 Tidak
PC8 0.4603 Tidak
PC9 0.1556 Tidak

2.2 Cek scree plot

library(factoextra)

pca_model <- prcomp(data_reduced, scale. = TRUE)

fviz_eig(
  pca_model,
  addlabels = TRUE,
  ylim = c(0, 30),
  barfill = "steelblue",
  barcolor = "black",
  linecolor = "red"
) +
  theme_minimal() +
  labs(
    title = "Scree Plot PCA",
    x = "Principal Component",
    y = "Percentage of Variance"
  )
## Warning in geom_bar(stat = "identity", fill = barfill, color = barcolor, :
## Ignoring empty aesthetic: `width`.

2.3 Cumulative variance

eig_val <- get_eigenvalue(pca_model)

kable(round(eig_val, 3),
      caption = "Eigenvalue dan Proporsi Variansi PCA") %>%
  kable_styling(
    bootstrap_options = c("striped","hover","condensed"),
    full_width = FALSE
  )
Eigenvalue dan Proporsi Variansi PCA
eigenvalue variance.percent cumulative.variance.percent
Dim.1 2.469 27.437 27.437
Dim.2 1.364 15.154 42.591
Dim.3 1.023 11.370 53.960
Dim.4 1.011 11.231 65.191
Dim.5 0.995 11.052 76.243
Dim.6 0.971 10.792 87.036
Dim.7 0.551 6.120 93.156
Dim.8 0.460 5.115 98.271
Dim.9 0.156 1.729 100.000
loading <- pca_model$rotation[,1:4]
loading
##                                       PC1          PC2           PC3
## Age                          0.0003516554 -0.002559084 -0.7198557484
## Daily_Social_Media_Hours     0.5928556718  0.114126095  0.0001264989
## Screen_Time_Hours            0.5642778660  0.125276370  0.0086941392
## Night_Scrolling_Frequency    0.0639021037 -0.739363548  0.0065503297
## Exercise_Frequency_per_Week -0.0072737169  0.016179127  0.4843262920
## Daily_Sleep_Hours           -0.0138699487  0.004154051 -0.4526934299
## Study_Work_Hours_per_Day     0.0082282156 -0.015008150 -0.2046220840
## Overthinking_Score           0.2570161068 -0.635494524  0.0076237693
## Social_Comparison_Index      0.5095672427  0.142332379 -0.0160490767
##                                       PC4
## Age                          0.0852073844
## Daily_Social_Media_Hours    -0.0059975704
## Screen_Time_Hours           -0.0119615490
## Night_Scrolling_Frequency   -0.0076557108
## Exercise_Frequency_per_Week -0.1345373910
## Daily_Sleep_Hours           -0.6252621428
## Study_Work_Hours_per_Day     0.7635662380
## Overthinking_Score          -0.0203854508
## Social_Comparison_Index      0.0001378507

2.4 Score PCA

pca_scores <- as.data.frame(pca_model$x[,1:4])

head(pca_scores)
##          PC1        PC2        PC3        PC4
## 1  0.3714989  0.3300081 -0.4552307  1.7583269
## 2  0.8539818  0.3802883 -0.2122179 -0.4354741
## 3 -1.2045371  0.2731325 -0.8196846  0.8235825
## 4  1.1370782 -1.3512476 -0.8596091 -0.4728595
## 5 -0.3696210  0.2453183  0.3861757 -0.2854278
## 6  2.3131235 -1.1819287  1.2707594 -0.2860318

3 Factor Analysis (FA)

fa.parallel(data_reduced, fa = "fa")

## Parallel analysis suggests that the number of factors =  2  and the number of components =  NA
fa_model <- fa(data_reduced,
               nfactors = 2,
               rotate = "varimax")

print(fa_model$loadings, cutoff = 0.3)
## 
## Loadings:
##                             MR1    MR2   
## Age                                      
## Daily_Social_Media_Hours     0.987       
## Screen_Time_Hours            0.829       
## Night_Scrolling_Frequency           0.533
## Exercise_Frequency_per_Week              
## Daily_Sleep_Hours                        
## Study_Work_Hours_per_Day                 
## Overthinking_Score                  0.806
## Social_Comparison_Index      0.665       
## 
##                  MR1   MR2
## SS loadings    2.135 0.959
## Proportion Var 0.237 0.107
## Cumulative Var 0.237 0.344
fa_model <- fa(data_reduced,
               nfactors = 2,
               rotate = "varimax",
               scores = "regression")

factor_scores <- as.data.frame(fa_model$scores)
head(factor_scores)
##           MR1         MR2
## 1  0.52007986 -0.13458932
## 2  0.08223927  0.34668203
## 3 -0.56168220 -0.55596760
## 4  0.17138731  0.96503814
## 5 -0.69278318  0.05565477
## 6  1.26567748  0.96352466