# =============================================================================
# HỆ SINH THÁI HỌC THUẬT TNSAI — SACHKTL.TNSAI.VN & VIETLOD.TNSAI.VN
# Khóa học : Khóa 4: Kinh tế lượng Bayes, SEM, học máy nhân quả và mô hình cấu trúc
# Buổi học : Buổi 03 — Nhóm 12.3 Học máy kinh tế lượng
# Bài giảng: B188 — Hồi quy vectơ hỗ trợ nhân phi tuyến
# Tên quốc tế: Support Vector Regression with Cross-Validated Kernel & Permutation Effects
# Mã mô hình : svr_econometric
# Phần mềm : R 4.x — Gói lệnh: e1071
# Dữ liệu   : vietlod_svr_econometric_ecodata.csv
# Kiểm định : Out-of-fold $K$-fold CV RMSE, MAE và $R^2_{\text{OOS}}$, tỷ lệ support vectors, bảng độ quan trọng biến hoán vị kèm độ lệch chuẩn, đạo hàm riêng biên trung bình.
# =============================================================================

options(scipen = 999, digits = 4)

# 1. Nạp bộ dữ liệu thực hành chuẩn hóa
data_file <- "vietlod_svr_econometric_ecodata.csv"
if (!file.exists(data_file)) {
  data_file <- "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_svr_econometric_ecodata.csv"
}
df <- read.csv(data_file, stringsAsFactors = FALSE)
cat("Kich thuoc mau thuc hanh:", nrow(df), "quan sat,", ncol(df), "bien so\n")

# 2. Thực thi kịch bản ước lượng và kiểm định B188 — Hồi quy vectơ hỗ trợ nhân phi tuyến
df <- read.csv('vietlod_svr_econometric_ecodata.csv')
summary(df)
# e1071::svm(y ~ x1 + x2, data = df, kernel = 'radial', type = 'eps-regression')

cat("Hoan tat uoc luong mo hinh B188 (svr_econometric) tren R 4.x.\n")
