library(lavaan)
## Warning: package 'lavaan' was built under R version 4.5.3
## This is lavaan 0.6-21
## lavaan is FREE software! Please report any bugs.
library(semPlot)
## Warning: package 'semPlot' was built under R version 4.5.3
library(psych)
## Warning: package 'psych' was built under R version 4.5.3
##
## Attaching package: 'psych'
## The following object is masked from 'package:lavaan':
##
## cor2cov
library(car)
## Warning: package 'car' was built under R version 4.5.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.5.3
## Registered S3 method overwritten by 'car':
## method from
## na.action.merMod lme4
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
data <- read.csv2("C:/Users/HP/OneDrive/Semester 4/Analisis Multivariat/student+performance/student/student-por.csv", sep = ";", header = TRUE)
cat("Jumlah siswa (baris) :", nrow(data), "\n")
## Jumlah siswa (baris) : 649
cat("Jumlah variabel (kolom):", ncol(data), "\n")
## Jumlah variabel (kolom): 33
head(data, 10)
## school sex age address famsize Pstatus Medu Fedu Mjob Fjob
## 1 GP F 18 U GT3 A 4 4 at_home teacher
## 2 GP F 17 U GT3 T 1 1 at_home other
## 3 GP F 15 U LE3 T 1 1 at_home other
## 4 GP F 15 U GT3 T 4 2 health services
## 5 GP F 16 U GT3 T 3 3 other other
## 6 GP M 16 U LE3 T 4 3 services other
## 7 GP M 16 U LE3 T 2 2 other other
## 8 GP F 17 U GT3 A 4 4 other teacher
## 9 GP M 15 U LE3 A 3 2 services other
## 10 GP M 15 U GT3 T 3 4 other other
## reason guardian traveltime studytime failures schoolsup famsup paid
## 1 course mother 2 2 0 yes no no
## 2 course father 1 2 0 no yes no
## 3 other mother 1 2 0 yes no no
## 4 home mother 1 3 0 no yes no
## 5 home father 1 2 0 no yes no
## 6 reputation mother 1 2 0 no yes no
## 7 home mother 1 2 0 no no no
## 8 home mother 2 2 0 yes yes no
## 9 home mother 1 2 0 no yes no
## 10 home mother 1 2 0 no yes no
## activities nursery higher internet romantic famrel freetime goout Dalc Walc
## 1 no yes yes no no 4 3 4 1 1
## 2 no no yes yes no 5 3 3 1 1
## 3 no yes yes yes no 4 3 2 2 3
## 4 yes yes yes yes yes 3 2 2 1 1
## 5 no yes yes no no 4 3 2 1 2
## 6 yes yes yes yes no 5 4 2 1 2
## 7 no yes yes yes no 4 4 4 1 1
## 8 no yes yes no no 4 1 4 1 1
## 9 no yes yes yes no 4 2 2 1 1
## 10 yes yes yes yes no 5 5 1 1 1
## health absences G1 G2 G3
## 1 3 4 0 11 11
## 2 3 2 9 11 11
## 3 3 6 12 13 12
## 4 5 0 14 14 14
## 5 5 0 11 13 13
## 6 5 6 12 12 13
## 7 3 0 13 12 13
## 8 1 2 10 13 13
## 9 1 0 15 16 17
## 10 5 0 12 12 13
options(repr.plot.width = 16, repr.plot.height = 4)
par(mfrow = c(1, min(4, ncol(data))), mar = c(4, 4, 2, 1))
for (col in colnames(data)) {
if (is.numeric(data[[col]])) {
hist(data[[col]], main = paste("Histogram:", col),
xlab = col, col = "lightblue", border = "white")
} else {
counts <- table(data[[col]])
barplot(counts, main = paste("Barplot:", col),
xlab = col, col = "lightgreen", border = "white", las = 2)}}
par(mfrow = c(1, 1))
# missing value
cat("Total missing value:", sum(is.na(data)), "\n")
## Total missing value: 0
cat("Jumlah duplikat :", nrow(data[duplicated(data), ]), "\n")
## Jumlah duplikat : 0
# Persentase missing per kolom (hanya tampil yang > 0)
missing_pct <- colMeans(is.na(data)) * 100
print(round(missing_pct[missing_pct > 0], 2))
## named numeric(0)
data_pilih <- data[, c("Medu", "Fedu", "Mjob", "Fjob", "paid", "internet",
"studytime", "freetime", "goout", "activities", "absences",
"G1", "G2", "G3")]
data_numeric <- data_pilih
# Konversi binary yes/no → 1/0
data_numeric$paid <- ifelse(data_numeric$paid == "yes", 1, 0)
data_numeric$internet <- ifelse(data_numeric$internet == "yes", 1, 0)
data_numeric$activities <- ifelse(data_numeric$activities == "yes", 1, 0)
# Konversi kategori nominal → angka
data_numeric$Mjob <- as.numeric(as.factor(data_numeric$Mjob))
data_numeric$Fjob <- as.numeric(as.factor(data_numeric$Fjob))
# Pastikan semua kolom numerik
sapply(data_numeric, class)
## Medu Fedu Mjob Fjob paid internet studytime
## "integer" "integer" "numeric" "numeric" "numeric" "numeric" "integer"
## freetime goout activities absences G1 G2 G3
## "integer" "integer" "numeric" "integer" "integer" "integer" "integer"
data_z <- as.data.frame(lapply(data_numeric, function(x) {
(x - mean(x, na.rm = TRUE)) / sd(x, na.rm = TRUE)
}))
# Verifikasi: mean tiap kolom harus mendekati 0
round(colMeans(data_z), 4)
## Medu Fedu Mjob Fjob paid internet studytime
## 0 0 0 0 0 0 0
## freetime goout activities absences G1 G2 G3
## 0 0 0 0 0 0 0
library(psych)
describe(data_numeric)
## vars n mean sd median trimmed mad min max range skew kurtosis
## Medu 1 649 2.51 1.13 2 2.53 1.48 0 4 4 -0.03 -1.27
## Fedu 2 649 2.31 1.10 2 2.27 1.48 0 4 4 0.21 -1.12
## Mjob 3 649 2.94 1.25 3 2.93 1.48 1 5 4 -0.19 -0.83
## Fjob 4 649 3.22 0.86 3 3.29 0.00 1 5 4 -0.53 1.17
## paid 5 649 0.06 0.24 0 0.00 0.00 0 1 1 3.69 11.66
## internet 6 649 0.77 0.42 1 0.83 0.00 0 1 1 -1.26 -0.41
## studytime 7 649 1.93 0.83 2 1.85 1.48 1 4 3 0.70 0.02
## freetime 8 649 3.18 1.05 3 3.19 1.48 1 5 4 -0.18 -0.41
## goout 9 649 3.18 1.18 3 3.20 1.48 1 5 4 -0.01 -0.87
## activities 10 649 0.49 0.50 0 0.48 0.00 0 1 1 0.06 -2.00
## absences 11 649 3.66 4.64 2 2.80 2.97 0 32 32 2.01 5.70
## G1 12 649 11.40 2.75 11 11.38 2.97 0 19 19 0.00 0.02
## G2 13 649 11.57 2.91 11 11.56 2.97 0 19 19 -0.36 1.63
## G3 14 649 11.91 3.23 12 12.04 2.97 0 19 19 -0.91 2.66
## se
## Medu 0.04
## Fedu 0.04
## Mjob 0.05
## Fjob 0.03
## paid 0.01
## internet 0.02
## studytime 0.03
## freetime 0.04
## goout 0.05
## activities 0.02
## absences 0.18
## G1 0.11
## G2 0.11
## G3 0.13
library(psych)
mardia(data_z)
## Call: mardia(x = data_z)
##
## Mardia tests of multivariate skew and kurtosis
## Use describe(x) the to get univariate tests
## n.obs = 649 num.vars = 14
## b1p = 41.93 skew = 4534.95 with probability <= 0
## small sample skew = 4558.71 with probability <= 0
## b2p = 270.39 kurtosis = 27.92 with probability <= 0
library(car)
data_clean <- na.omit(data_z)
model_vif <- lm(G3 ~ Medu + Fedu + Mjob + Fjob + paid + internet +
studytime + freetime + goout + activities + absences + G1 + G2,
data = data_clean)
cat("Nilai VIF =")
## Nilai VIF =
vif(model_vif)
## Medu Fedu Mjob Fjob paid internet studytime
## 2.098904 1.787472 1.352158 1.088891 1.039036 1.134082 1.094915
## freetime goout activities absences G1 G2
## 1.189652 1.162034 1.056358 1.059132 4.122214 4.038222
# VIF < 5 → aman
library(psych)
r <- cor(data_z, use = "complete.obs")
KMO(r)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = r)
## Overall MSA = 0.74
## MSA for each item =
## Medu Fedu Mjob Fjob paid internet studytime
## 0.66 0.67 0.74 0.66 0.54 0.84 0.89
## freetime goout activities absences G1 G2 G3
## 0.56 0.58 0.73 0.60 0.87 0.71 0.76
library(lavaan)
library(semPlot)
model_cfa_x1 <- 'SosialEkonomi =~ Medu + Fedu + Mjob + Fjob + paid + internet'
fit_x1 <- cfa(model_cfa_x1, data = data_z, std.lv = TRUE)
summary(fit_x1, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-21 ended normally after 15 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 12
##
## Number of observations 649
##
## Model Test User Model:
##
## Test statistic 44.787
## Degrees of freedom 9
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 628.856
## Degrees of freedom 15
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.942
## Tucker-Lewis Index (TLI) 0.903
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -5230.310
## Loglikelihood unrestricted model (H1) -5207.916
##
## Akaike (AIC) 10484.620
## Bayesian (BIC) 10538.325
## Sample-size adjusted Bayesian (SABIC) 10500.225
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.078
## 90 Percent confidence interval - lower 0.056
## 90 Percent confidence interval - upper 0.102
## P-value H_0: RMSEA <= 0.050 0.018
## P-value H_0: RMSEA >= 0.080 0.480
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.043
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SosialEkonomi =~
## Medu 0.922 0.042 22.164 0.000 0.922 0.923
## Fedu 0.697 0.041 17.095 0.000 0.697 0.697
## Mjob 0.494 0.041 12.185 0.000 0.494 0.494
## Fjob 0.196 0.042 4.703 0.000 0.196 0.196
## paid 0.119 0.042 2.849 0.004 0.119 0.119
## internet 0.297 0.041 7.176 0.000 0.297 0.297
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Medu 0.148 0.054 2.728 0.006 0.148 0.148
## .Fedu 0.513 0.042 12.188 0.000 0.513 0.514
## .Mjob 0.755 0.045 16.708 0.000 0.755 0.756
## .Fjob 0.960 0.054 17.906 0.000 0.960 0.962
## .paid 0.984 0.055 17.977 0.000 0.984 0.986
## .internet 0.911 0.051 17.727 0.000 0.911 0.912
## SosialEkonomi 1.000 1.000 1.000
semPaths(fit_x1, what = "path", whatLabels = "std",
style = "ram", layout = "tree", rotation = 2,
sizeMan = 6, sizeLat = 7, edge.label.cex = 1.2, label.cex = 1.3,
color = list(lat = "lightblue", man = "lightgreen"))
title("CFA: Status Sosial-Ekonomi (X1)")
## Aktivitas Non-Akademik (X2)
model_cfa_x2 <- 'AktivitasNonAkademik =~ freetime + goout + activities + absences'
fit_x2 <- cfa(model_cfa_x2, data = data_z, std.lv = TRUE)
summary(fit_x2, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-21 ended normally after 21 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 8
##
## Number of observations 649
##
## Model Test User Model:
##
## Test statistic 6.633
## Degrees of freedom 2
## P-value (Chi-square) 0.036
##
## Model Test Baseline Model:
##
## Test statistic 105.432
## Degrees of freedom 6
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.953
## Tucker-Lewis Index (TLI) 0.860
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -3632.163
## Loglikelihood unrestricted model (H1) -3628.847
##
## Akaike (AIC) 7280.326
## Bayesian (BIC) 7316.130
## Sample-size adjusted Bayesian (SABIC) 7290.730
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.060
## 90 Percent confidence interval - lower 0.013
## 90 Percent confidence interval - upper 0.113
## P-value H_0: RMSEA <= 0.050 0.297
## P-value H_0: RMSEA >= 0.080 0.310
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.027
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## AktivitasNonAkademik =~
## freetime 0.748 0.158 4.733 0.000 0.748 0.749
## goout 0.462 0.102 4.513 0.000 0.462 0.462
## activities 0.199 0.057 3.517 0.000 0.199 0.199
## absences 0.010 0.050 0.190 0.849 0.010 0.010
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .freetime 0.438 0.233 1.884 0.060 0.438 0.439
## .goout 0.785 0.098 7.978 0.000 0.785 0.786
## .activities 0.959 0.056 17.221 0.000 0.959 0.960
## .absences 0.998 0.055 18.013 0.000 0.998 1.000
## AktivtsNnAkdmk 1.000 1.000 1.000
semPaths(fit_x2, what = "path", whatLabels = "std",
style = "ram", layout = "tree", rotation = 2,
sizeMan = 6, sizeLat = 7, edge.label.cex = 1.2, label.cex = 1.3,
color = list(lat = "lightcoral", man = "lightyellow"))
title("CFA: Aktivitas Non-Akademik (X2)")
## Prestasi Akademik (Y)
model_cfa_y <- 'PrestasiAkademik =~ G1 + G2 + G3'
fit_y <- cfa(model_cfa_y, data = data_z, std.lv = TRUE)
summary(fit_y, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-21 ended normally after 18 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 6
##
## Number of observations 649
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Model Test Baseline Model:
##
## Test statistic 2116.649
## Degrees of freedom 3
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1702.848
## Loglikelihood unrestricted model (H1) -1702.848
##
## Akaike (AIC) 3417.695
## Bayesian (BIC) 3444.548
## Sample-size adjusted Bayesian (SABIC) 3425.498
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent confidence interval - lower 0.000
## 90 Percent confidence interval - upper 0.000
## P-value H_0: RMSEA <= 0.050 NA
## P-value H_0: RMSEA >= 0.080 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PrestasiAkademik =~
## G1 0.881 0.031 28.496 0.000 0.881 0.882
## G2 0.980 0.029 34.218 0.000 0.980 0.981
## G3 0.936 0.030 31.508 0.000 0.936 0.937
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .G1 0.221 0.014 15.507 0.000 0.221 0.222
## .G2 0.038 0.009 4.170 0.000 0.038 0.039
## .G3 0.122 0.011 11.488 0.000 0.122 0.122
## PrestasiAkadmk 1.000 1.000 1.000
semPaths(fit_y, what = "path", whatLabels = "std",
style = "ram", layout = "tree", rotation = 2,
sizeMan = 6, sizeLat = 7, edge.label.cex = 1.2, label.cex = 1.3,
color = list(lat = "lightpink", man = "lightcyan"))
title("CFA: Prestasi Akademik (Y)")
# Tabel Fit Indeks
cfa_fits <- data.frame(
Konstruk = c("SosialEkonomi", "AktivitasNonAkademik", "PrestasiAkademik"),
CFI = round(c(fitMeasures(fit_x1,"cfi"), fitMeasures(fit_x2,"cfi"), fitMeasures(fit_y,"cfi")), 4),
TLI = round(c(fitMeasures(fit_x1,"tli"), fitMeasures(fit_x2,"tli"), fitMeasures(fit_y,"tli")), 4),
RMSEA = round(c(fitMeasures(fit_x1,"rmsea"), fitMeasures(fit_x2,"rmsea"), fitMeasures(fit_y,"rmsea")), 4),
SRMR = round(c(fitMeasures(fit_x1,"srmr"), fitMeasures(fit_x2,"srmr"), fitMeasures(fit_y,"srmr")), 4))
cat("Fit Indeks CFA\n")
## Fit Indeks CFA
print(cfa_fits)
## Konstruk CFI TLI RMSEA SRMR
## 1 SosialEkonomi 0.9417 0.9028 0.0783 0.0433
## 2 AktivitasNonAkademik 0.9534 0.8602 0.0597 0.0274
## 3 PrestasiAkademik 1.0000 1.0000 0.0000 0.0000
# Composite Reliability (CR)
hitung_CR <- function(fit){
std <- standardizedSolution(fit)
lambda <- std$est[std$op == "=~"]
theta <- 1 - lambda^2
sum(lambda)^2 / (sum(lambda)^2 + sum(theta))}
cr_df <- data.frame(
Konstruk = c("SosialEkonomi", "AktivitasNonAkademik", "PrestasiAkademik"),
CR = round(c(hitung_CR(fit_x1), hitung_CR(fit_x2), hitung_CR(fit_y)), 4),
Keterangan = ifelse(c(hitung_CR(fit_x1), hitung_CR(fit_x2), hitung_CR(fit_y)) > 0.70,
"Reliabel", "Perlu Evaluasi"))
cat("\n Composite Reliability (CR > 0.70 = reliabel)\n")
##
## Composite Reliability (CR > 0.70 = reliabel)
print(cr_df)
## Konstruk CR Keterangan
## 1 SosialEkonomi 0.6347 Perlu Evaluasi
## 2 AktivitasNonAkademik 0.3876 Perlu Evaluasi
## 3 PrestasiAkademik 0.9534 Reliabel
model_sem <- '
# Measurement model
SosialEkonomi =~ Medu + Fedu + Mjob + Fjob + paid + internet
AktivitasNonAkademik =~ studytime + freetime + goout + activities + absences
PrestasiAkademik =~ G1 + G2 + G3
# Structural model
PrestasiAkademik ~ SosialEkonomi + AktivitasNonAkademik'
fit_sem <- sem(model_sem, data = data_z, std.lv = TRUE)
summary(fit_sem, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-21 ended normally after 32 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 31
##
## Number of observations 649
##
## Model Test User Model:
##
## Test statistic 198.141
## Degrees of freedom 74
## P-value (Chi-square) 0.000
##
## Model Test Baseline Model:
##
## Test statistic 3067.036
## Degrees of freedom 91
## P-value 0.000
##
## User Model versus Baseline Model:
##
## Comparative Fit Index (CFI) 0.958
## Tucker-Lewis Index (TLI) 0.949
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -11451.023
## Loglikelihood unrestricted model (H1) -11351.952
##
## Akaike (AIC) 22964.045
## Bayesian (BIC) 23102.784
## Sample-size adjusted Bayesian (SABIC) 23004.359
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.051
## 90 Percent confidence interval - lower 0.042
## 90 Percent confidence interval - upper 0.059
## P-value H_0: RMSEA <= 0.050 0.421
## P-value H_0: RMSEA >= 0.080 0.000
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.063
##
## Parameter Estimates:
##
## Standard errors Standard
## Information Expected
## Information saturated (h1) model Structured
##
## Latent Variables:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SosialEkonomi =~
## Medu 0.905 0.039 22.960 0.000 0.905 0.905
## Fedu 0.707 0.040 17.874 0.000 0.707 0.708
## Mjob 0.500 0.040 12.413 0.000 0.500 0.500
## Fjob 0.205 0.042 4.900 0.000 0.205 0.206
## paid 0.115 0.042 2.720 0.007 0.115 0.115
## internet 0.306 0.041 7.371 0.000 0.306 0.306
## AktivitasNonAkademik =~
## studytime 0.154 0.054 2.861 0.004 0.154 0.154
## freetime -0.609 0.083 -7.324 0.000 -0.609 -0.609
## goout -0.559 0.078 -7.160 0.000 -0.559 -0.560
## activities -0.178 0.054 -3.319 0.001 -0.178 -0.178
## absences -0.083 0.054 -1.542 0.123 -0.083 -0.083
## PrestasiAkademik =~
## G1 0.821 0.030 27.358 0.000 0.882 0.883
## G2 0.912 0.028 32.160 0.000 0.979 0.980
## G3 0.872 0.029 29.983 0.000 0.936 0.937
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## PrestasiAkademik ~
## SosialEkonomi 0.333 0.047 7.062 0.000 0.310 0.310
## AktivtsNnAkdmk 0.214 0.058 3.691 0.000 0.199 0.199
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## SosialEkonomi ~~
## AktivtsNnAkdmk -0.016 0.058 -0.269 0.788 -0.016 -0.016
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .Medu 0.180 0.047 3.824 0.000 0.180 0.180
## .Fedu 0.498 0.040 12.479 0.000 0.498 0.499
## .Mjob 0.749 0.045 16.731 0.000 0.749 0.750
## .Fjob 0.956 0.053 17.879 0.000 0.956 0.958
## .paid 0.985 0.055 17.974 0.000 0.985 0.987
## .internet 0.905 0.051 17.683 0.000 0.905 0.906
## .studytime 0.975 0.055 17.632 0.000 0.975 0.976
## .freetime 0.628 0.098 6.403 0.000 0.628 0.629
## .goout 0.686 0.086 7.945 0.000 0.686 0.687
## .activities 0.967 0.055 17.492 0.000 0.967 0.968
## .absences 0.992 0.055 17.906 0.000 0.992 0.993
## .G1 0.221 0.014 15.522 0.000 0.221 0.221
## .G2 0.039 0.009 4.347 0.000 0.039 0.040
## .G3 0.122 0.011 11.563 0.000 0.122 0.122
## SosialEkonomi 1.000 1.000 1.000
## AktivtsNnAkdmk 1.000 1.000 1.000
## .PrestasiAkadmk 1.000 0.866 0.866
semPaths(fit_sem, what = "path", whatLabels = "std",
style = "ram", layout = "tree", rotation = 2,
sizeMan = 7, sizeLat = 8, color = "lightgray",
edge.label.cex = 1.1, label.cex = 1.2)
title("Model SEM: Pengaruh SES & Aktivitas Non-Akademik\nterhadap Prestasi Akademik Siswa")
param <- parameterEstimates(fit_sem, standardized = TRUE)
jalur <- param[param$op == "~", ]
beta_x1 <- jalur[jalur$rhs == "SosialEkonomi", "std.all"]
beta_x2 <- jalur[jalur$rhs == "AktivitasNonAkademik", "std.all"]
pval_x1 <- jalur[jalur$rhs == "SosialEkonomi", "pvalue"]
pval_x2 <- jalur[jalur$rhs == "AktivitasNonAkademik", "pvalue"]
cat("HASIL UJI HIPOTESIS SEM\n")
## HASIL UJI HIPOTESIS SEM
cat("H1: SES → Prestasi Akademik\n")
## H1: SES → Prestasi Akademik
cat(sprintf(" β = %.4f | p = %.4f | %s\n\n", beta_x1, pval_x1,
ifelse(pval_x1 < 0.05, "SIGNIFIKAN ✓ (H1 Diterima)", "TIDAK SIGNIFIKAN ✗ (H1 Ditolak)")))
## β = 0.3096 | p = 0.0000 | SIGNIFIKAN ✓ (H1 Diterima)
cat("H2: Aktivitas Non-Akademik → Prestasi Akademik\n")
## H2: Aktivitas Non-Akademik → Prestasi Akademik
cat(sprintf(" β = %.4f | p = %.4f | %s\n\n", beta_x2, pval_x2,
ifelse(pval_x2 < 0.05, "SIGNIFIKAN ✓ (H2 Diterima)", "TIDAK SIGNIFIKAN ✗ (H2 Ditolak)")))
## β = 0.1992 | p = 0.0002 | SIGNIFIKAN ✓ (H2 Diterima)
cat("Fit Model SEM:")
## Fit Model SEM:
cat(sprintf(" CFI = %.4f (> 0.90)\n", fitMeasures(fit_sem, "cfi")))
## CFI = 0.9583 (> 0.90)
cat(sprintf(" TLI = %.4f (> 0.90)\n", fitMeasures(fit_sem, "tli")))
## TLI = 0.9487 (> 0.90)
cat(sprintf(" RMSEA = %.4f (< 0.08)\n", fitMeasures(fit_sem, "rmsea")))
## RMSEA = 0.0508 (< 0.08)
cat(sprintf(" SRMR = %.4f (< 0.08)\n", fitMeasures(fit_sem, "srmr")))
## SRMR = 0.0627 (< 0.08)