library(readxl)    
## Warning: package 'readxl' was built under R version 4.5.2
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(tidyr)     
library(psych) 
library(writexl)
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
library(e1071)
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
## The following object is masked from 'package:dplyr':
## 
##     recode
Life_Expectancy_Data <- read_excel("Life Expectancy Data.xlsx")
str(Life_Expectancy_Data)
## tibble [2,938 × 22] (S3: tbl_df/tbl/data.frame)
##  $ Country                        : chr [1:2938] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
##  $ Year                           : num [1:2938] 2015 2014 2013 2012 2011 ...
##  $ Status                         : chr [1:2938] "Developing" "Developing" "Developing" "Developing" ...
##  $ Life expectancy                : num [1:2938] 65 59.9 59.9 59.5 59.2 58.8 58.6 58.1 57.5 57.3 ...
##  $ Adult Mortality                : num [1:2938] 263 271 268 272 275 279 281 287 295 295 ...
##  $ infant deaths                  : num [1:2938] 62 64 66 69 71 74 77 80 82 84 ...
##  $ Alcohol                        : num [1:2938] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.03 0.02 0.03 ...
##  $ percentage expenditure         : num [1:2938] 71.3 73.5 73.2 78.2 7.1 ...
##  $ Hepatitis B                    : num [1:2938] 65 62 64 67 68 66 63 64 63 64 ...
##  $ Measles                        : num [1:2938] 1154 492 430 2787 3013 ...
##  $ BMI                            : num [1:2938] 19.1 18.6 18.1 17.6 17.2 16.7 16.2 15.7 15.2 14.7 ...
##  $ under-five deaths              : num [1:2938] 83 86 89 93 97 102 106 110 113 116 ...
##  $ Polio                          : num [1:2938] 6 58 62 67 68 66 63 64 63 58 ...
##  $ Total expenditure              : num [1:2938] 8.16 8.18 8.13 8.52 7.87 9.2 9.42 8.33 6.73 7.43 ...
##  $ Diphtheria                     : num [1:2938] 65 62 64 67 68 66 63 64 63 58 ...
##  $ HIV/AIDS                       : num [1:2938] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
##  $ GDP                            : num [1:2938] 584.3 612.7 631.7 670 63.5 ...
##  $ Population                     : num [1:2938] 33736494 327582 31731688 3696958 2978599 ...
##  $ thinness  1-19 years           : num [1:2938] 17.2 17.5 17.7 17.9 18.2 18.4 18.6 18.8 19 19.2 ...
##  $ thinness 5-9 years             : num [1:2938] 17.3 17.5 17.7 18 18.2 18.4 18.7 18.9 19.1 19.3 ...
##  $ Income composition of resources: num [1:2938] 0.479 0.476 0.47 0.463 0.454 0.448 0.434 0.433 0.415 0.405 ...
##  $ Schooling                      : num [1:2938] 10.1 10 9.9 9.8 9.5 9.2 8.9 8.7 8.4 8.1 ...
View(Life_Expectancy_Data)
describe(Life_Expectancy_Data)
##                                 vars    n        mean          sd     median
## Country*                           1 2938       96.10       56.24      94.00
## Year                               2 2938     2007.52        4.61    2008.00
## Status*                            3 2938        1.83        0.38       2.00
## Life expectancy                    4 2928       69.22        9.52      72.10
## Adult Mortality                    5 2928      164.80      124.29     144.00
## infant deaths                      6 2938       30.30      117.93       3.00
## Alcohol                            7 2744        4.60        4.05       3.76
## percentage expenditure             8 2938      738.25     1987.91      64.91
## Hepatitis B                        9 2385       80.94       25.07      92.00
## Measles                           10 2938     2419.59    11467.27      17.00
## BMI                               11 2904       38.32       20.04      43.50
## under-five deaths                 12 2938       42.04      160.45       4.00
## Polio                             13 2919       82.55       23.43      93.00
## Total expenditure                 14 2712        5.94        2.50       5.76
## Diphtheria                        15 2919       82.32       23.72      93.00
## HIV/AIDS                          16 2938        1.74        5.08       0.10
## GDP                               17 2490     7483.16    14270.17    1766.95
## Population                        18 2286 12753375.12 61012096.51 1386542.00
## thinness  1-19 years              19 2904        4.84        4.42       3.30
## thinness 5-9 years                20 2904        4.87        4.51       3.30
## Income composition of resources   21 2771        0.63        0.21       0.68
## Schooling                         22 2775       11.99        3.36      12.30
##                                    trimmed        mad     min          max
## Country*                             95.90      72.65    1.00 1.930000e+02
## Year                               2007.52       5.93 2000.00 2.015000e+03
## Status*                               1.91       0.00    1.00 2.000000e+00
## Life expectancy                      69.91       8.60   36.30 8.900000e+01
## Adult Mortality                     150.51     112.68    1.00 7.230000e+02
## infant deaths                        10.20       4.45    0.00 1.800000e+03
## Alcohol                               4.23       4.81    0.01 1.787000e+01
## percentage expenditure              230.74      96.24    0.00 1.947991e+04
## Hepatitis B                          86.89       8.90    1.00 9.900000e+01
## Measles                             286.08      25.20    0.00 2.121830e+05
## BMI                                  39.05      24.17    1.00 8.730000e+01
## under-five deaths                    14.15       5.93    0.00 2.500000e+03
## Polio                                88.05       8.90    3.00 9.900000e+01
## Total expenditure                     5.85       2.36    0.37 1.760000e+01
## Diphtheria                           87.99       8.90    2.00 9.900000e+01
## HIV/AIDS                              0.54       0.00    0.10 5.060000e+01
## GDP                                3751.73    2360.98    1.68 1.191727e+05
## Population                      3953693.58 2012347.06   34.00 1.293859e+09
## thinness  1-19 years                  4.14       3.41    0.10 2.770000e+01
## thinness 5-9 years                    4.15       3.41    0.10 2.860000e+01
## Income composition of resources       0.65       0.19    0.00 9.500000e-01
## Schooling                            12.17       3.11    0.00 2.070000e+01
##                                        range  skew kurtosis         se
## Country*                        1.920000e+02  0.03    -1.22       1.04
## Year                            1.500000e+01 -0.01    -1.21       0.09
## Status*                         1.000000e+00 -1.72     0.95       0.01
## Life expectancy                 5.270000e+01 -0.64    -0.24       0.18
## Adult Mortality                 7.220000e+02  1.17     1.74       2.30
## infant deaths                   1.800000e+03  9.78   115.76       2.18
## Alcohol                         1.786000e+01  0.59    -0.81       0.08
## percentage expenditure          1.947991e+04  4.65    26.51      36.68
## Hepatitis B                     9.800000e+01 -1.93     2.76       0.51
## Measles                         2.121830e+05  9.43   114.58     211.56
## BMI                             8.630000e+01 -0.22    -1.29       0.37
## under-five deaths               2.500000e+03  9.49   109.49       2.96
## Polio                           9.600000e+01 -2.10     3.76       0.43
## Total expenditure               1.723000e+01  0.62     1.15       0.05
## Diphtheria                      9.700000e+01 -2.07     3.55       0.44
## HIV/AIDS                        5.050000e+01  5.39    34.80       0.09
## GDP                             1.191711e+05  3.20    12.29     285.98
## Population                      1.293859e+09 15.90   297.09 1276079.80
## thinness  1-19 years            2.760000e+01  1.71     3.96       0.08
## thinness 5-9 years              2.850000e+01  1.78     4.34       0.08
## Income composition of resources 9.500000e-01 -1.14     1.38       0.00
## Schooling                       2.070000e+01 -0.60     0.88       0.06
missing_table <- data.frame(
  Variable = names(Life_Expectancy_Data),
  Missing = colSums(is.na(Life_Expectancy_Data))
)

print(missing_table)
##                                                        Variable Missing
## Country                                                 Country       0
## Year                                                       Year       0
## Status                                                   Status       0
## Life expectancy                                 Life expectancy      10
## Adult Mortality                                 Adult Mortality      10
## infant deaths                                     infant deaths       0
## Alcohol                                                 Alcohol     194
## percentage expenditure                   percentage expenditure       0
## Hepatitis B                                         Hepatitis B     553
## Measles                                                 Measles       0
## BMI                                                         BMI      34
## under-five deaths                             under-five deaths       0
## Polio                                                     Polio      19
## Total expenditure                             Total expenditure     226
## Diphtheria                                           Diphtheria      19
## HIV/AIDS                                               HIV/AIDS       0
## GDP                                                         GDP     448
## Population                                           Population     652
## thinness  1-19 years                       thinness  1-19 years      34
## thinness 5-9 years                           thinness 5-9 years      34
## Income composition of resources Income composition of resources     167
## Schooling                                             Schooling     163
num_vars <- names(Life_Expectancy_Data)[sapply(Life_Expectancy_Data, is.numeric)]
cat_vars <- names(Life_Expectancy_Data)[sapply(Life_Expectancy_Data, is.character)]

impute_numeric <- function(x) {
  if (all(is.na(x))) return(x)
  
  if (abs(skewness(x, na.rm = TRUE)) > 1) {
    x[is.na(x)] <- median(x, na.rm = TRUE)
  } else {
    x[is.na(x)] <- mean(x, na.rm = TRUE)
  }
  return(x)
}

impute_categorical <- function(x) {
  mode_value <- names(sort(table(x), decreasing = TRUE))[1]
  x[is.na(x)] <- mode_value
  return(x)
}

Life_Expectancy_Imputed <- Life_Expectancy_Data

# Imputasi numerik
for (col in num_vars) {
  Life_Expectancy_Imputed[[col]] <- impute_numeric(Life_Expectancy_Imputed[[col]])
}

# Imputasi kategorikal
for (col in cat_vars) {
  Life_Expectancy_Imputed[[col]] <- impute_categorical(Life_Expectancy_Imputed[[col]])
}

cat("Missing value sebelum imputasi:\n")
## Missing value sebelum imputasi:
print(colSums(is.na(Life_Expectancy_Data)))
##                         Country                            Year 
##                               0                               0 
##                          Status                 Life expectancy 
##                               0                              10 
##                 Adult Mortality                   infant deaths 
##                              10                               0 
##                         Alcohol          percentage expenditure 
##                             194                               0 
##                     Hepatitis B                         Measles 
##                             553                               0 
##                             BMI               under-five deaths 
##                              34                               0 
##                           Polio               Total expenditure 
##                              19                             226 
##                      Diphtheria                        HIV/AIDS 
##                              19                               0 
##                             GDP                      Population 
##                             448                             652 
##            thinness  1-19 years              thinness 5-9 years 
##                              34                              34 
## Income composition of resources                       Schooling 
##                             167                             163
cat("\nMissing value sesudah imputasi:\n")
## 
## Missing value sesudah imputasi:
print(colSums(is.na(Life_Expectancy_Imputed)))
##                         Country                            Year 
##                               0                               0 
##                          Status                 Life expectancy 
##                               0                               0 
##                 Adult Mortality                   infant deaths 
##                               0                               0 
##                         Alcohol          percentage expenditure 
##                               0                               0 
##                     Hepatitis B                         Measles 
##                               0                               0 
##                             BMI               under-five deaths 
##                               0                               0 
##                           Polio               Total expenditure 
##                               0                               0 
##                      Diphtheria                        HIV/AIDS 
##                               0                               0 
##                             GDP                      Population 
##                               0                               0 
##            thinness  1-19 years              thinness 5-9 years 
##                               0                               0 
## Income composition of resources                       Schooling 
##                               0                               0
cek_outlier <- function(x) {
  Q1 <- quantile(x, 0.25, na.rm = TRUE)
  Q3 <- quantile(x, 0.75, na.rm = TRUE)
  IQR_val <- Q3 - Q1
  lower <- Q1 - 1.5 * IQR_val
  upper <- Q3 + 1.5 * IQR_val
  sum(x < lower | x > upper, na.rm = TRUE)
}

num_vars <- names(Life_Expectancy_Imputed)[sapply(Life_Expectancy_Imputed, is.numeric)]

outlier_before <- data.frame(
  Variable = num_vars,
  Outlier_Before = sapply(Life_Expectancy_Imputed[num_vars], cek_outlier)
)

cat("=== OUTLIER SEBELUM PEMBERSIHAN ===\n")
## === OUTLIER SEBELUM PEMBERSIHAN ===
print(outlier_before)
##                                                        Variable Outlier_Before
## Year                                                       Year              0
## Life expectancy                                 Life expectancy             17
## Adult Mortality                                 Adult Mortality             86
## infant deaths                                     infant deaths            315
## Alcohol                                                 Alcohol              3
## percentage expenditure                   percentage expenditure            389
## Hepatitis B                                         Hepatitis B            322
## Measles                                                 Measles            542
## BMI                                                         BMI              0
## under-five deaths                             under-five deaths            394
## Polio                                                     Polio            279
## Total expenditure                             Total expenditure             51
## Diphtheria                                           Diphtheria            298
## HIV/AIDS                                               HIV/AIDS            542
## GDP                                                         GDP            445
## Population                                           Population            452
## thinness  1-19 years                       thinness  1-19 years            100
## thinness 5-9 years                           thinness 5-9 years             99
## Income composition of resources Income composition of resources            130
## Schooling                                             Schooling             77
df_before_long <- Life_Expectancy_Imputed %>%
  select(all_of(num_vars)) %>%
  tidyr::pivot_longer(cols = everything(), names_to = "Variable", values_to = "Value")

ggplot(df_before_long, aes(x = "", y = Value)) +
  geom_boxplot(
    fill = "lightgreen",
    color = "darkgreen",
    outlier.color = "red",
    outlier.size = 1
  ) +
  facet_wrap(~ Variable, scales = "free", ncol = 4) +
  theme_minimal(base_size = 11) +
  theme(
    strip.text = element_text(face = "bold"),
    axis.text.x = element_blank(),
    axis.ticks.x = element_blank()
  ) +
  labs(title = "Boxplot Outlier Sebelum Pembersihan", x = NULL, y = "Nilai")

handle_outlier <- function(x) {
  Q1 <- quantile(x, 0.25, na.rm = TRUE)
  Q3 <- quantile(x, 0.75, na.rm = TRUE)
  IQR_val <- Q3 - Q1
  lower <- Q1 - 1.5 * IQR_val
  upper <- Q3 + 1.5 * IQR_val
  
  x[x < lower] <- lower
  x[x > upper] <- upper
  return(x)
}

Life_Expectancy_Clean <- Life_Expectancy_Imputed
Life_Expectancy_Clean[num_vars] <- 
  lapply(Life_Expectancy_Imputed[num_vars], handle_outlier)

outlier_after <- data.frame(
  Variable = num_vars,
  Outlier_After = sapply(Life_Expectancy_Clean[num_vars], cek_outlier)
)

print(outlier_after)
##                                                        Variable Outlier_After
## Year                                                       Year             0
## Life expectancy                                 Life expectancy             0
## Adult Mortality                                 Adult Mortality             0
## infant deaths                                     infant deaths             0
## Alcohol                                                 Alcohol             0
## percentage expenditure                   percentage expenditure             0
## Hepatitis B                                         Hepatitis B             0
## Measles                                                 Measles             0
## BMI                                                         BMI             0
## under-five deaths                             under-five deaths             0
## Polio                                                     Polio             0
## Total expenditure                             Total expenditure             0
## Diphtheria                                           Diphtheria             0
## HIV/AIDS                                               HIV/AIDS             0
## GDP                                                         GDP             0
## Population                                           Population             0
## thinness  1-19 years                       thinness  1-19 years             0
## thinness 5-9 years                           thinness 5-9 years             0
## Income composition of resources Income composition of resources             0
## Schooling                                             Schooling             0
df_after_long <- Life_Expectancy_Clean %>%
  select(all_of(num_vars)) %>%
  pivot_longer(cols = everything(), names_to = "Variable", values_to = "Value")

ggplot(df_after_long, aes(x = "", y = Value)) +
  geom_boxplot(
    fill = "lightgreen",
    color = "darkgreen",
    outlier.color = "red",
    outlier.size = 1
  ) +
  facet_wrap(~ Variable, scales = "free", ncol = 4) +
  theme_minimal(base_size = 11) +
  theme(
    strip.text = element_text(face = "bold"),
    axis.text.x = element_blank(),
    axis.ticks.x = element_blank()
  ) +
  labs(title = "Boxplot Setelah Penanganan Outlier", x = NULL, y = "Nilai")

cat_cols <- sapply(Life_Expectancy_Clean, is.character)
cat_cols <- names(Life_Expectancy_Clean)[cat_cols]

cat("Kolom kategorikal yang ditemukan:\n")
## Kolom kategorikal yang ditemukan:
print(cat_cols)
## [1] "Country" "Status"
for (col in cat_cols) {
  unique_vals <- unique(Life_Expectancy_Clean[[col]])
  
  if (length(unique_vals) == 2) {
    Life_Expectancy_Clean[[col]] <- as.numeric(as.factor(Life_Expectancy_Clean[[col]])) - 1
    
  } else {
    cat(paste("Kolom", col, "memiliki lebih dari 2 kategori, perlu one-hot encoding.\n"))
  }
}
## Kolom Country memiliki lebih dari 2 kategori, perlu one-hot encoding.
str(Life_Expectancy_Clean)
## tibble [2,938 × 22] (S3: tbl_df/tbl/data.frame)
##  $ Country                        : chr [1:2938] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
##  $ Year                           : num [1:2938] 2015 2014 2013 2012 2011 ...
##  $ Status                         : num [1:2938] 1 1 1 1 1 1 1 1 1 1 ...
##  $ Life expectancy                : num [1:2938] 65 59.9 59.9 59.5 59.2 58.8 58.6 58.1 57.5 57.3 ...
##  $ Adult Mortality                : num [1:2938] 263 271 268 272 275 279 281 287 295 295 ...
##  $ infant deaths                  : num [1:2938] 55 55 55 55 55 55 55 55 55 55 ...
##  $ Alcohol                        : num [1:2938] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.03 0.02 0.03 ...
##  $ percentage expenditure         : num [1:2938] 71.3 73.5 73.2 78.2 7.1 ...
##  $ Hepatitis B                    : num [1:2938] 65 62 64 67 68 66 63 64 63 64 ...
##  $ Measles                        : num [1:2938] 901 492 430 901 901 ...
##  $ BMI                            : num [1:2938] 19.1 18.6 18.1 17.6 17.2 16.7 16.2 15.7 15.2 14.7 ...
##  $ under-five deaths              : num [1:2938] 70 70 70 70 70 70 70 70 70 70 ...
##  $ Polio                          : num [1:2938] 49.5 58 62 67 68 66 63 64 63 58 ...
##  $ Total expenditure              : num [1:2938] 8.16 8.18 8.13 8.52 7.87 9.2 9.42 8.33 6.73 7.43 ...
##  $ Diphtheria                     : num [1:2938] 65 62 64 67 68 66 63 64 63 58 ...
##  $ HIV/AIDS                       : num [1:2938] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
##  $ GDP                            : num [1:2938] 584.3 612.7 631.7 670 63.5 ...
##  $ Population                     : num [1:2938] 10832552 327582 10832552 3696958 2978599 ...
##  $ thinness  1-19 years           : num [1:2938] 15.3 15.3 15.3 15.3 15.3 ...
##  $ thinness 5-9 years             : num [1:2938] 15.6 15.6 15.6 15.6 15.6 15.6 15.6 15.6 15.6 15.6 ...
##  $ Income composition of resources: num [1:2938] 0.479 0.476 0.47 0.463 0.454 0.448 0.434 0.433 0.415 0.405 ...
##  $ Schooling                      : num [1:2938] 10.1 10 9.9 9.8 9.5 9.2 8.9 8.7 8.4 8.1 ...
View(Life_Expectancy_Clean)
set.seed(123)  

index_train <- sample(1:nrow(Life_Expectancy_Clean),
                      size = 0.8 * nrow(Life_Expectancy_Clean))

data_train <- Life_Expectancy_Clean[index_train, ]
data_test  <- Life_Expectancy_Clean[-index_train, ]

cat("Jumlah data training:", nrow(data_train), "\n")
## Jumlah data training: 2350
cat("Jumlah data testing :", nrow(data_test), "\n")
## Jumlah data testing : 588
str(data_train)
## tibble [2,350 × 22] (S3: tbl_df/tbl/data.frame)
##  $ Country                        : chr [1:2350] "Sudan" "Sweden" "Sao Tome and Principe" "Central African Republic" ...
##  $ Year                           : num [1:2350] 2010 2010 2006 2002 2013 ...
##  $ Status                         : num [1:2350] 1 0 1 1 1 0 1 0 1 1 ...
##  $ Life expectancy                : num [1:2350] 62.5 81.5 64.7 45.6 71 78.7 74.1 81 82.2 79.2 ...
##  $ Adult Mortality                : num [1:2350] 243 58 22 58 135 8 151 67 6 81 ...
##  $ infant deaths                  : num [1:2350] 55 0 0 17 55 1 4 0 1 0 ...
##  $ Alcohol                        : num [1:2350] 1.77 7.2 5.46 1.47 0.01 ...
##  $ percentage expenditure         : num [1:2350] 172 778.2 47.1 31.6 52.8 ...
##  $ Hepatitis B                    : num [1:2350] 75 92 75 92 96 92 97 95 97 92 ...
##  $ Measles                        : num [1:2350] 680 6 0 901 237 ...
##  $ BMI                            : num [1:2350] 38.3 57.3 24 17.2 17 ...
##  $ under-five deaths              : num [1:2350] 70 0 0 25 70 1 4 0 1 1 ...
##  $ Polio                          : num [1:2350] 49.5 98 97 49.5 96 98 97 96 95 95 ...
##  $ Total expenditure              : num [1:2350] 7.97 9.47 7.84 4.16 2.88 8.46 9.78 8.1 7.81 8.3 ...
##  $ Diphtheria                     : num [1:2350] 49.5 98 97 49.5 96 98 97 96 95 95 ...
##  $ HIV/AIDS                       : num [1:2350] 0.3 0.1 1.2 1.85 0.1 0.1 0.4 0.1 0.1 0.1 ...
##  $ GDP                            : num [1:2350] 1476 5276 844 254 952 ...
##  $ Population                     : num [1:2350] 10832552 9378126 159328 397612 10832552 ...
##  $ thinness  1-19 years           : num [1:2350] 3.3 1.3 6.9 1.2 15.3 ...
##  $ thinness 5-9 years             : num [1:2350] 3.3 1.3 6.8 1.2 15.6 1 2.1 0.2 1.1 0.8 ...
##  $ Income composition of resources: num [1:2350] 0.461 0.895 0.521 0.315 0.565 0.881 0.614 0.902 0.895 0.83 ...
##  $ Schooling                      : num [1:2350] 7 15.8 10.2 5.4 10 16.5 11.6 18.6 16 15.3 ...
model_vif <- lm(
  `Life expectancy` ~ 
    `Adult Mortality` +
    `infant deaths` +
    Alcohol +
    `percentage expenditure` +
    `Hepatitis B` +
    Measles +
    BMI +
    `under-five deaths` +
    Polio +
    `Total expenditure` +
    Diphtheria +
    `HIV/AIDS` +
    GDP +
    Population +
    `thinness  1-19 years` +
    `thinness 5-9 years` +
    `Income composition of resources` +
    Schooling,
  data = Life_Expectancy_Clean
)

vif_values <- vif(model_vif)

vif_df <- data.frame(
  Variabel = names(vif_values),
  VIF = as.numeric(vif_values)
)

cat("=== HASIL VIF (Vertikal) ===\n")
## === HASIL VIF (Vertikal) ===
print(vif_df)
##                             Variabel        VIF
## 1                  `Adult Mortality`   1.716368
## 2                    `infant deaths` 106.746383
## 3                            Alcohol   1.604219
## 4           `percentage expenditure`   3.819646
## 5                      `Hepatitis B`   1.487448
## 6                            Measles   1.605689
## 7                                BMI   1.859041
## 8                `under-five deaths` 112.466522
## 9                              Polio   3.767173
## 10               `Total expenditure`   1.196539
## 11                        Diphtheria   3.926215
## 12                        `HIV/AIDS`   2.285519
## 13                               GDP   4.199764
## 14                        Population   1.201641
## 15            `thinness  1-19 years`   9.230862
## 16              `thinness 5-9 years`   9.317550
## 17 `Income composition of resources`   3.452700
## 18                         Schooling   4.168052
cat("\n=== INTERPRETASI OTOMATIS ===\n")
## 
## === INTERPRETASI OTOMATIS ===
for (i in 1:length(vif_values)) {
  if (vif_values[i] < 5) {
    cat(names(vif_values)[i], ": Tidak ada indikasi multikolinearitas (VIF < 5)\n")
  } else if (vif_values[i] >= 5 & vif_values[i] < 10) {
    cat(names(vif_values)[i], ": Ada indikasi multikolinearitas sedang (5 ≤ VIF < 10)\n")
  } else {
    cat(names(vif_values)[i], ": Multikolinearitas tinggi (VIF ≥ 10)\n")
  }
}  
## `Adult Mortality` : Tidak ada indikasi multikolinearitas (VIF < 5)
## `infant deaths` : Multikolinearitas tinggi (VIF ≥ 10)
## Alcohol : Tidak ada indikasi multikolinearitas (VIF < 5)
## `percentage expenditure` : Tidak ada indikasi multikolinearitas (VIF < 5)
## `Hepatitis B` : Tidak ada indikasi multikolinearitas (VIF < 5)
## Measles : Tidak ada indikasi multikolinearitas (VIF < 5)
## BMI : Tidak ada indikasi multikolinearitas (VIF < 5)
## `under-five deaths` : Multikolinearitas tinggi (VIF ≥ 10)
## Polio : Tidak ada indikasi multikolinearitas (VIF < 5)
## `Total expenditure` : Tidak ada indikasi multikolinearitas (VIF < 5)
## Diphtheria : Tidak ada indikasi multikolinearitas (VIF < 5)
## `HIV/AIDS` : Tidak ada indikasi multikolinearitas (VIF < 5)
## GDP : Tidak ada indikasi multikolinearitas (VIF < 5)
## Population : Tidak ada indikasi multikolinearitas (VIF < 5)
## `thinness  1-19 years` : Ada indikasi multikolinearitas sedang (5 ≤ VIF < 10)
## `thinness 5-9 years` : Ada indikasi multikolinearitas sedang (5 ≤ VIF < 10)
## `Income composition of resources` : Tidak ada indikasi multikolinearitas (VIF < 5)
## Schooling : Tidak ada indikasi multikolinearitas (VIF < 5)