#Load Dataset

library(readr)
df<-read_csv("ResearchInformation3.csv")
## Rows: 493 Columns: 16
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (10): Department, Gender, Income, Hometown, Preparation, Gaming, Attenda...
## dbl  (6): HSC, SSC, Computer, English, Last, Overall
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df
## # A tibble: 493 × 16
##    Department     Gender   HSC   SSC Income Hometown Computer Preparation Gaming
##    <chr>          <chr>  <dbl> <dbl> <chr>  <chr>       <dbl> <chr>       <chr> 
##  1 Business Admi… Male    4.17  4.84 Low (… Village         3 More than … 0-1 H…
##  2 Business Admi… Female  4.92  5    Upper… City            3 0-1 Hour    0-1 H…
##  3 Business Admi… Male    5     4.83 Lower… Village         3 0-1 Hour    More …
##  4 Business Admi… Male    4     4.5  High … City            5 More than … More …
##  5 Business Admi… Female  2.19  3.17 Lower… Village         3 0-1 Hour    2-3 H…
##  6 Computer Scie… Male    4.75  4.05 Lower… Village         3 0-1 Hour    More …
##  7 Computer Scie… Male    4.42  5    High … Village         4 0-1 Hour    More …
##  8 Computer Scie… Male    4.5   4.81 Upper… City            3 2-3 Hours   More …
##  9 Computer Scie… Male    3.32  4.5  Low (… City            4 0-1 Hour    More …
## 10 Computer Scie… Female  3.33  4.95 Lower… City            3 0-1 Hour    More …
## # ℹ 483 more rows
## # ℹ 7 more variables: Attendance <chr>, Job <chr>, English <dbl>, Extra <chr>,
## #   Semester <chr>, Last <dbl>, Overall <dbl>

#Variabel dependen, independen, covariat

df <- df[, c( "HSC","Gender","Income", "Hometown","Job","Gaming","Extra","Last","Overall")]
df
## # A tibble: 493 × 9
##      HSC Gender Income                 Hometown Job   Gaming Extra  Last Overall
##    <dbl> <chr>  <chr>                  <chr>    <chr> <chr>  <chr> <dbl>   <dbl>
##  1  4.17 Male   Low (Below 15,000)     Village  No    0-1 H… Yes    3.22    3.35
##  2  4.92 Female Upper middle (30,000-… City     No    0-1 H… Yes    3.47    3.47
##  3  5    Male   Lower middle (15,000-… Village  No    More … Yes    4       3.72
##  4  4    Male   High (Above 50,000)    City     No    More … Yes    3.8     3.75
##  5  2.19 Female Lower middle (15,000-… Village  No    2-3 H… Yes    3.94    3.94
##  6  4.75 Male   Lower middle (15,000-… Village  No    More … No     1       1   
##  7  4.42 Male   High (Above 50,000)    Village  No    More … No     1.06    1.06
##  8  4.5  Male   Upper middle (30,000-… City     No    More … Yes    2.95    1.25
##  9  3.32 Male   Low (Below 15,000)     City     No    More … Yes    1.42    1.44
## 10  3.33 Female Lower middle (15,000-… City     No    More … No     1.5     1.5 
## # ℹ 483 more rows

EXPLORATORY DATA ANALYSIS

library(ggplot2)
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
yz <- c("Last", "Overall", "HSC")

for (var in yz) {
  meanval <- mean(df[[var]], na.rm = TRUE)
  sdval <- sd(df[[var]], na.rm = TRUE)

  ggplot(df, aes_string(x = var)) +
    geom_histogram(aes(y = ..density..),
                   fill = "skyblue", bins = 20, color = "black") +
    stat_function(fun = dnorm, 
                  args = list(mean = meanval, sd = sdval),
                  color = "red", size = 1) +
    ggtitle(paste("Distribusi", var)) +
    theme_minimal() -> p
  print(p)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

library(ggplot2)

X <- c("Gender", "Hometown", "Job", "Gaming", "Extra", "Income")

for (var in X) {
  ggplot(df, aes_string(x = var)) +
    geom_bar(fill = "orange", color = "black") +
    geom_text(stat = "count", aes(label = ..count..), vjust = -0.5) +
    ggtitle(paste("Frekuensi:", var)) +
    theme_minimal() -> p
  print(p)
}

# PRE-PROCESSING

#Cek Miss Value

colSums(is.na(df))
##      HSC   Gender   Income Hometown      Job   Gaming    Extra     Last 
##        0        0        0        0        0        0        0        0 
##  Overall 
##        0

#Del Data Duplikat

sum(duplicated(df))
## [1] 2
df <- df[!duplicated(df), ]
sum(duplicated(df))
## [1] 0

#Informasi Data

summary(df)
##       HSC           Gender             Income            Hometown        
##  Min.   :2.170   Length:491         Length:491         Length:491        
##  1st Qu.:3.830   Class :character   Class :character   Class :character  
##  Median :4.170   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :4.156                                                           
##  3rd Qu.:4.500                                                           
##  Max.   :5.000                                                           
##      Job               Gaming             Extra                Last      
##  Length:491         Length:491         Length:491         Min.   :1.000  
##  Class :character   Class :character   Class :character   1st Qu.:2.810  
##  Mode  :character   Mode  :character   Mode  :character   Median :3.250  
##                                                           Mean   :3.161  
##                                                           3rd Qu.:3.670  
##                                                           Max.   :4.000  
##     Overall     
##  Min.   :1.000  
##  1st Qu.:2.880  
##  Median :3.270  
##  Mean   :3.186  
##  3rd Qu.:3.670  
##  Max.   :4.000
str(df)
## tibble [491 × 9] (S3: tbl_df/tbl/data.frame)
##  $ HSC     : num [1:491] 4.17 4.92 5 4 2.19 4.75 4.42 4.5 3.32 3.33 ...
##  $ Gender  : chr [1:491] "Male" "Female" "Male" "Male" ...
##  $ Income  : chr [1:491] "Low (Below 15,000)" "Upper middle (30,000-50,000)" "Lower middle (15,000-30,000)" "High (Above 50,000)" ...
##  $ Hometown: chr [1:491] "Village" "City" "Village" "City" ...
##  $ Job     : chr [1:491] "No" "No" "No" "No" ...
##  $ Gaming  : chr [1:491] "0-1 Hour" "0-1 Hour" "More than 3 Hours" "More than 3 Hours" ...
##  $ Extra   : chr [1:491] "Yes" "Yes" "Yes" "Yes" ...
##  $ Last    : num [1:491] 3.22 3.47 4 3.8 3.94 ...
##  $ Overall : num [1:491] 3.35 3.47 3.72 3.75 3.94 ...

#Variabel Kategori dijadikan Factor

df$Gaming <- factor(df$Gaming, 
                    levels = c("0-1 Hour", "2-3 Hours", "More than 3 Hours"), 
                    ordered = TRUE)

df$Income <- factor(df$Income, 
                    levels = c("Low (Below 15,000)", 
                               "Lower middle (15,000-30,000)", 
                               "Upper middle (30,000-50,000)", 
                               "High (Above 50,000)"), 
                    ordered = TRUE)

df$Job <- factor(df$Job)
df$Extra <- factor(df$Extra)
df$Gender <- factor(df$Gender)
df$Hometown <- factor(df$Hometown)

#Transform manly

library(e1071)

manly <- function(x, lambda) {
  if (lambda == 0) return(x)
  (exp(lambda * x) - 1) / lambda}

optlambdaoverall <- optimize(function(l) abs(skewness(manly(df$Overall, l), na.rm = TRUE)),interval = c(-1, 1))
optlambdalast <- optimize(function(l) abs(skewness(manly(df$Last, l), na.rm = TRUE)),interval = c(-1, 1))
lambda_overall <- optlambdaoverall$minimum
lambda_last <- optlambdalast$minimum

df$Overall_mn <- manly(df$Overall, lambda_overall)
df$Last_mn <- manly(df$Last, lambda_last)

lambda_overall
## [1] 0.7977598
lambda_last
## [1] 0.7027244
library(ggplot2)

mean_last <- mean(df$Last_mn, na.rm = TRUE)
sd_last <- sd(df$Last_mn, na.rm = TRUE)
ggplot(df, aes(x = Last_mn)) +
  geom_histogram(aes(y = ..density..), fill = "skyblue", color = "black", bins = 20) +
  stat_function(fun = dnorm, args = list(mean = mean_last, sd = sd_last),
                color = "red", size = 1) +
  labs(title = "Distribusi Last Manly Transform") +
  theme_minimal()

mean_overall <- mean(df$Overall_mn, na.rm = TRUE)
sd_overall <- sd(df$Overall_mn, na.rm = TRUE)
ggplot(df, aes(x = Overall_mn)) +
  geom_histogram(aes(y = ..density..), fill = "skyblue", color = "black", bins = 20) +
  stat_function(fun = dnorm, args = list(mean = mean_overall, sd = sd_overall),
                color = "red", size = 1) +
  labs(title = "Distribusi Overall Manly Transform") +
  theme_minimal()

UJI ASUMSI

1. Uji Normalitas y (Shapiro-Wilk)

cat("================================================\n")
## ================================================
cat("Shapiro Wilk Manly Transform \n")
## Shapiro Wilk Manly Transform
shapiro.test(df$Last_mn)
## 
##  Shapiro-Wilk normality test
## 
## data:  df$Last_mn
## W = 0.97183, p-value = 4.114e-08
shapiro.test(df$Overall_mn)
## 
##  Shapiro-Wilk normality test
## 
## data:  df$Overall_mn
## W = 0.97652, p-value = 4.229e-07

#2. Uji Dependensi antar Y (Barlett)

#install.packages("psych") 
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
cortest.bartlett(df[, c("Overall_mn", "Last_mn")])
## R was not square, finding R from data
## $chisq
## [1] 969.4672
## 
## $p.value
## [1] 7.782109e-213
## 
## $df
## [1] 1

#3. Uji Homogenitas Varians-Kovarians (Box’s M Test)

library(heplots)
## Loading required package: broom
## Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
## Warning: 'rgl.init' failed, will use the null device.
## See '?rgl.useNULL' for ways to avoid this warning.
cat("============================Box's M Test Gender==============")
## ============================Box's M Test Gender==============
boxM(df[, c("Overall_mn", "Last_mn")], df$Gender)
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  df[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 2.0133, df = 3, p-value = 0.5696
cat("============================Box's M Test Income==============")
## ============================Box's M Test Income==============
boxM(df[, c("Overall_mn", "Last_mn")], df$Income)
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  df[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 16.242, df = 9, p-value = 0.062
cat("============================Box's M Test Gaming==============")
## ============================Box's M Test Gaming==============
boxM(df[, c("Overall_mn", "Last_mn")], df$Gaming)
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  df[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 37.106, df = 6, p-value = 1.679e-06
cat("============================Box's M Test Job==============")
## ============================Box's M Test Job==============
boxM(df[, c("Overall_mn", "Last_mn")], df$Job)
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  df[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 55.371, df = 3, p-value = 5.722e-12
cat("============================Box's M Test Hometown==============")
## ============================Box's M Test Hometown==============
boxM(df[, c("Overall_mn", "Last_mn")], df$Hometown)
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  df[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 11.648, df = 3, p-value = 0.008692
cat("============================Box's M Test Extra==============")
## ============================Box's M Test Extra==============
boxM(df[, c("Overall_mn", "Last_mn")], df$Extra)
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  df[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 38.528, df = 3, p-value = 2.185e-08
zx <- na.omit(df[, c("Overall_mn", "Last_mn", "Gender", "Hometown", "Job", "Gaming", "Extra", "Income")])
factors <- c("Gender", "Hometown", "Job", "Gaming", "Extra", "Income")

for (i in 1:(length(factors) - 1)) {
  for (j in (i + 1):length(factors)) {
    f1 <- factors[i]
    f2 <- factors[j]

    cat("\n============================Box's M Test", f1, "*", f2,"============================\n")
    group <- interaction(zx[[f1]], zx[[f2]])
    group_counts <- table(group)
    if (all(group_counts >= 2)) {result <- boxM(zx[, c("Overall_mn", "Last_mn")], group)
    print(result)} 
    else {cat("ada grup < 2 observasi\n")}}}
## 
## ============================Box's M Test Gender * Hometown ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 29.99, df = 9, p-value = 0.0004404
## 
## 
## ============================Box's M Test Gender * Job ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 56.387, df = 9, p-value = 6.62e-09
## 
## 
## ============================Box's M Test Gender * Gaming ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 104.54, df = 15, p-value = 1.79e-15
## 
## 
## ============================Box's M Test Gender * Extra ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 54.984, df = 9, p-value = 1.226e-08
## 
## 
## ============================Box's M Test Gender * Income ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 48.814, df = 21, p-value = 0.0005322
## 
## 
## ============================Box's M Test Hometown * Job ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 68.766, df = 9, p-value = 2.656e-11
## 
## 
## ============================Box's M Test Hometown * Gaming ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 62.859, df = 15, p-value = 8.08e-08
## 
## 
## ============================Box's M Test Hometown * Extra ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 79.363, df = 9, p-value = 2.162e-13
## 
## 
## ============================Box's M Test Hometown * Income ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 45.624, df = 21, p-value = 0.001433
## 
## 
## ============================Box's M Test Job * Gaming ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 122.23, df = 15, p-value < 2.2e-16
## 
## 
## ============================Box's M Test Job * Extra ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 90.823, df = 9, p-value = 1.113e-15
## 
## 
## ============================Box's M Test Job * Income ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 79.058, df = 21, p-value = 1.16e-08
## 
## 
## ============================Box's M Test Gaming * Extra ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 128.99, df = 15, p-value < 2.2e-16
## 
## 
## ============================Box's M Test Gaming * Income ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 87.366, df = 33, p-value = 8.339e-07
## 
## 
## ============================Box's M Test Extra * Income ============================
## 
##  Box's M-test for Homogeneity of Covariance Matrices
## 
## data:  zx[, c("Overall_mn", "Last_mn")]
## Chi-Sq (approx.) = 65.844, df = 21, p-value = 1.604e-06

MODELING

#MANOVA one way

varx <- c("Gender", "Hometown", "Job", "Gaming", "Extra", "Income")

for (var in varx) {
  cat("\n======================One-Way MANOVA", var,"==========================\n")
  
  subset_df <- df[, c("Last_mn", "Overall_mn", var)]
  names(subset_df)[3] <- "X"

  model <- manova(cbind(Last_mn, Overall_mn) ~ X, data = subset_df)
  print(summary(model, test = "Pillai"))
}
## 
## ======================One-Way MANOVA Gender ==========================
##            Df   Pillai approx F num Df den Df   Pr(>F)   
## X           1 0.022464   5.6073      2    488 0.003912 **
## Residuals 489                                            
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ======================One-Way MANOVA Hometown ==========================
##            Df    Pillai approx F num Df den Df Pr(>F)
## X           1 0.0028314  0.69281      2    488 0.5007
## Residuals 489                                        
## 
## ======================One-Way MANOVA Job ==========================
##            Df    Pillai approx F num Df den Df Pr(>F)
## X           1 0.0024587  0.60139      2    488 0.5485
## Residuals 489                                        
## 
## ======================One-Way MANOVA Gaming ==========================
##            Df  Pillai approx F num Df den Df    Pr(>F)    
## X           2 0.20743   28.235      4    976 < 2.2e-16 ***
## Residuals 488                                             
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ======================One-Way MANOVA Extra ==========================
##            Df  Pillai approx F num Df den Df   Pr(>F)    
## X           1 0.13566   38.295      2    488 3.56e-16 ***
## Residuals 489                                            
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ======================One-Way MANOVA Income ==========================
##            Df    Pillai approx F num Df den Df Pr(>F)
## X           3 0.0030842  0.25072      6    974 0.9591
## Residuals 487

#MANOVA two way

varx <- c("Gender", "Hometown", "Job", "Gaming", "Extra", "Income")
combinasi <- combn(varx, 2, simplify = FALSE)

for (combo in combinasi) {
  var1 <- combo[1]
  var2 <- combo[2]
  cat("\n=========================Two-Way MANOVA", var1, "and", var2,"=======================\n")

  subdf <- df[, c("Last_mn", "Overall_mn", var1, var2)]
  names(subdf)[3:4] <- c("X1", "X2")

  model <- manova(cbind(Last_mn, Overall_mn) ~ X1 * X2, data = subdf)
  print(summary(model, test = "Pillai"))}
## 
## =========================Two-Way MANOVA Gender and Hometown =======================
##            Df    Pillai approx F num Df den Df   Pr(>F)   
## X1          1 0.0224955   5.5922      2    486 0.003971 **
## X2          1 0.0015838   0.3855      2    486 0.680333   
## X1:X2       1 0.0017764   0.4324      2    486 0.649173   
## Residuals 487                                             
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Gender and Job =======================
##            Df    Pillai approx F num Df den Df   Pr(>F)   
## X1          1 0.0224826   5.5889      2    486 0.003983 **
## X2          1 0.0021180   0.5158      2    486 0.597366   
## X1:X2       1 0.0032101   0.7826      2    486 0.457804   
## Residuals 487                                             
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Gender and Gaming =======================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.026890   6.6871      2    484  0.001365 ** 
## X2          2 0.209020  28.3015      4    970 < 2.2e-16 ***
## X1:X2       2 0.006198   0.7538      4    970  0.555516    
## Residuals 485                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Gender and Extra =======================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.025929    6.469      2    486  0.001688 ** 
## X2          1 0.137491   38.736      2    486 2.458e-16 ***
## X1:X2       1 0.002330    0.568      2    486  0.567252    
## Residuals 487                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Gender and Income =======================
##            Df    Pillai approx F num Df den Df   Pr(>F)   
## X1          1 0.0227155   5.6017      2    482 0.003936 **
## X2          3 0.0042569   0.3434      6    966 0.913859   
## X1:X2       3 0.0187549   1.5241      6    966 0.166931   
## Residuals 483                                             
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Hometown and Job =======================
##            Df     Pillai approx F num Df den Df Pr(>F)
## X1          1 0.00283885  0.69181      2    486 0.5012
## X2          1 0.00307238  0.74889      2    486 0.4734
## X1:X2       1 0.00037088  0.09016      2    486 0.9138
## Residuals 487                                         
## 
## =========================Two-Way MANOVA Hometown and Gaming =======================
##            Df   Pillai approx F num Df den Df Pr(>F)    
## X1          1 0.003540   0.8598      2    484 0.4239    
## X2          2 0.208193  28.1765      4    970 <2e-16 ***
## X1:X2       2 0.011986   1.4621      4    970 0.2117    
## Residuals 485                                           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Hometown and Extra =======================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.003272    0.798      2    486    0.4509    
## X2          1 0.135976   38.242      2    486 3.765e-16 ***
## X1:X2       1 0.003810    0.929      2    486    0.3955    
## Residuals 487                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Hometown and Income =======================
##            Df    Pillai approx F num Df den Df Pr(>F)
## X1          1 0.0028809  0.69631      2    482 0.4989
## X2          3 0.0039175  0.31597      6    966 0.9288
## X1:X2       3 0.0212718  1.73078      6    966 0.1106
## Residuals 483                                        
## 
## =========================Two-Way MANOVA Job and Gaming =======================
##            Df   Pillai approx F num Df den Df Pr(>F)    
## X1          1 0.003024   0.7341      2    484 0.4805    
## X2          2 0.211536  28.6824      4    970 <2e-16 ***
## X1:X2       2 0.000935   0.1134      4    970 0.9778    
## Residuals 485                                           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Job and Extra =======================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.002756    0.671      2    486 0.5114420    
## X2          1 0.136330   38.357      2    486 3.408e-16 ***
## X1:X2       1 0.031467    7.895      2    486 0.0004225 ***
## Residuals 487                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Job and Income =======================
##            Df    Pillai approx F num Df den Df Pr(>F)
## X1          1 0.0024822  0.59970      2    482 0.5494
## X2          3 0.0031514  0.25409      6    966 0.9577
## X1:X2       3 0.0108921  0.88162      6    966 0.5077
## Residuals 483                                        
## 
## =========================Two-Way MANOVA Gaming and Extra =======================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          2 0.239696   33.021      4    970 < 2.2e-16 ***
## X2          1 0.137578   38.605      2    484 2.781e-16 ***
## X1:X2       2 0.062531    7.827      4    970 3.295e-06 ***
## Residuals 485                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Gaming and Income =======================
##            Df   Pillai approx F num Df den Df Pr(>F)    
## X1          2 0.209695  28.0522      4    958 <2e-16 ***
## X2          3 0.002236   0.1787      6    958 0.9827    
## X1:X2       6 0.024428   0.9872     12    958 0.4591    
## Residuals 479                                           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANOVA Extra and Income =======================
##            Df   Pillai approx F num Df den Df Pr(>F)    
## X1          1 0.139463   39.058      2    482 <2e-16 ***
## X2          3 0.002936    0.237      6    966 0.9645    
## X1:X2       3 0.032805    2.685      6    966 0.0137 *  
## Residuals 483                                           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#MANCOVA one way

varx <- c("Gender", "Hometown", "Job", "Gaming", "Extra", "Income")
for (var in varx) {
  cat("\n====================One-Way MANCOVA", var, "dngan covariat HSC====================\n")

  subsetdf <- df[, c("Last_mn", "Overall_mn", var, "HSC")]
  names(subsetdf)[3] <- "X"

  model <- manova(cbind(Last_mn, Overall_mn) ~ X + HSC, data = subsetdf)

  print(summary(model, test = "Pillai"))}
## 
## ====================One-Way MANCOVA Gender dngan covariat HSC====================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X           1 0.024400     6.09      2    487  0.002442 ** 
## HSC         1 0.086271    22.99      2    487 2.878e-10 ***
## Residuals 488                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ====================One-Way MANCOVA Hometown dngan covariat HSC====================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X           1 0.003101   0.7574      2    487    0.4694    
## HSC         1 0.087129  23.2408      2    487 2.289e-10 ***
## Residuals 488                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ====================One-Way MANCOVA Job dngan covariat HSC====================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X           1 0.002627   0.6413      2    487     0.527    
## HSC         1 0.088845  23.7434      2    487 1.448e-10 ***
## Residuals 488                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ====================One-Way MANCOVA Gaming dngan covariat HSC====================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X           2 0.217051   29.643      4    974 < 2.2e-16 ***
## HSC         1 0.060768   15.722      2    486  2.42e-07 ***
## Residuals 487                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ====================One-Way MANCOVA Extra dngan covariat HSC====================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X           1 0.145099   41.328      2    487 < 2.2e-16 ***
## HSC         1 0.076241   20.097      2    487 4.107e-09 ***
## Residuals 488                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ====================One-Way MANCOVA Income dngan covariat HSC====================
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X           3 0.003168    0.257      6    972    0.9565    
## HSC         1 0.090203   24.043      2    485 1.107e-10 ***
## Residuals 486                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#MANCOVA two way

varx <- c("Gender", "Hometown", "Job", "Gaming", "Extra", "Income")
combinasi <- combn(varx, 2, simplify = FALSE)

for (combo in combinasi) {
  var1 <- combo[1]
  var2 <- combo[2]
  cat("\n=========================Two-Way MANCOVA", var1, "&", var2, "dengan covariat HSC =====\n")

  subdf <- df[, c("Last_mn", "Overall_mn", var1, var2, "HSC")]
  names(subdf)[3:4] <- c("X1", "X2")

  model <- manova(cbind(Last_mn, Overall_mn) ~ X1 * X2 + HSC, data = subdf)
  print(summary(model, test = "Pillai"))
}
## 
## =========================Two-Way MANCOVA Gender & Hometown dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.024408   6.0671      2    485  0.002497 ** 
## X2          1 0.001730   0.4203      2    485  0.657105    
## HSC         1 0.085211  22.5886      2    485 4.171e-10 ***
## X1:X2       1 0.001769   0.4296      2    485  0.650999    
## Residuals 486                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Gender & Job dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.024424   6.0710      2    485  0.002488 ** 
## X2          1 0.002243   0.5450      2    485  0.580179    
## HSC         1 0.086425  22.9408      2    485 3.023e-10 ***
## X1:X2       1 0.003330   0.8103      2    485  0.445325    
## Residuals 486                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Gender & Gaming dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.028468   7.0766      2    483 0.0009351 ***
## X2          2 0.218420  29.6689      4    968 < 2.2e-16 ***
## HSC         1 0.058565  15.0234      2    483 4.681e-07 ***
## X1:X2       2 0.006498   0.7889      4    968 0.5324686    
## Residuals 484                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Gender & Extra dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.027828    6.941      2    485  0.001066 ** 
## X2          1 0.146790   41.721      2    485 < 2.2e-16 ***
## HSC         1 0.074028   19.387      2    485 7.944e-09 ***
## X1:X2       1 0.002960    0.720      2    485  0.487338    
## Residuals 486                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Gender & Income dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.024828   6.1233      2    481  0.002366 ** 
## X2          3 0.004467   0.3597      6    964  0.904395    
## HSC         1 0.088748  23.4227      2    481 1.963e-10 ***
## X1:X2       3 0.022662   1.8414      6    964  0.088117 .  
## Residuals 482                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Hometown & Job dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df   Pr(>F)    
## X1          1 0.003110   0.7566      2    485   0.4698    
## X2          1 0.003296   0.8019      2    485   0.4491    
## HSC         1 0.087096  23.1358      2    485 2.53e-10 ***
## X1:X2       1 0.000982   0.2382      2    485   0.7881    
## Residuals 486                                             
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Hometown & Gaming dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.003781   0.9167      2    483   0.40055    
## X2          2 0.218451  29.6736      4    968 < 2.2e-16 ***
## HSC         1 0.060726  15.6135      2    483 2.687e-07 ***
## X1:X2       2 0.016340   1.9934      4    968   0.09345 .  
## Residuals 484                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Hometown & Extra dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.003536    0.861      2    485    0.4235    
## X2          1 0.145277   41.218      2    485 < 2.2e-16 ***
## HSC         1 0.074670   19.569      2    485 6.714e-09 ***
## X1:X2       1 0.004183    1.019      2    485    0.3619    
## Residuals 486                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Hometown & Income dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.003166   0.7638      2    481   0.46645    
## X2          3 0.004085   0.3288      6    964   0.92199    
## HSC         1 0.089780  23.7218      2    481 1.495e-10 ***
## X1:X2       3 0.023422   1.9039      6    964   0.07733 .  
## Residuals 482                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Job & Gaming dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.003162   0.7661      2    483    0.4654    
## X2          2 0.221284  30.1064      4    968 < 2.2e-16 ***
## HSC         1 0.060629  15.5869      2    483 2.755e-07 ***
## X1:X2       2 0.000900   0.1090      4    968    0.9794    
## Residuals 484                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Job & Extra dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.002912    0.708      2    485 0.4930039    
## X2          1 0.145608   41.328      2    485 < 2.2e-16 ***
## HSC         1 0.076715   20.149      2    485 3.926e-09 ***
## X1:X2       1 0.029255    7.308      2    485 0.0007465 ***
## Residuals 486                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Job & Income dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df   Pr(>F)    
## X1          1 0.002664   0.6423      2    481   0.5265    
## X2          3 0.003239   0.2606      6    964   0.9550    
## HSC         1 0.090644  23.9728      2    481 1.19e-10 ***
## X1:X2       3 0.013704   1.1085      6    964   0.3552    
## Residuals 482                                             
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Gaming & Extra dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          2 0.248140   34.278      4    968 < 2.2e-16 ***
## X2          1 0.143609   40.497      2    483 < 2.2e-16 ***
## HSC         1 0.056566   14.480      2    483 7.813e-07 ***
## X1:X2       2 0.056875    7.083      4    968 1.274e-05 ***
## Residuals 484                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Gaming & Income dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          2 0.219917  29.5268      4    956 < 2.2e-16 ***
## X2          3 0.002293   0.1829      6    956    0.9816    
## HSC         1 0.061213  15.5514      2    477 2.865e-07 ***
## X1:X2       6 0.026647   1.0758     12    956    0.3771    
## Residuals 478                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## =========================Two-Way MANCOVA Extra & Income dengan covariat HSC =====
##            Df   Pillai approx F num Df den Df    Pr(>F)    
## X1          1 0.148629   41.986      2    481 < 2.2e-16 ***
## X2          3 0.002991    0.241      6    964   0.96302    
## HSC         1 0.079927   20.892      2    481 1.992e-09 ***
## X1:X2       3 0.027186    2.214      6    964   0.03966 *  
## Residuals 482                                              
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1