Hi, could you help to identify and fix my mistakes? I try to perform cross-validation but have
Question:
Hi, could you help to identify and fix my mistakes? I try to perform cross-validation but have no idea how answer to questions correctly.
1. Consider the following model: diabetic status (*Diabetes*; 0=non-diabetic, 1=diabetic) as a function of age (*age*; years), weight (*weight*; kg), hypertension status (*HTN*; 0=normotensive, 1=hypertensive), health status as indicated by high density lipoproteins (*hdl3cat*; 0=poor health, 1=intermediate health, 2=ideal health), the interaction between weight and hypertension status, the interaction between weight and age, and the interaction between weight and health status as indicated by high density lipoproteins.
# Load necessary libraries
library(fastDummies)
library(boot)
# Creating data set
data2 <- as_tibble(data %>% dplyr::select(Diabetes, age, weight, HTN, hdl3cat) %>% na.omit())
# Creating Dummy Variables
data2 <- dummy_cols(data2, select_columns = "Diabetes")
data2 <- dummy_cols(data2, select_columns = "HTN")
data2 <- dummy_cols(data2, select_columns = "hdl3cat")
colnames(data2)
# Create the model for diabetes
m3 <- glm(Diabetes ~ age + weight + as.factor(HTN) + as.factor(hdl3cat) +
HTN_1:weight + as.factor(hdl3cat):weight + weight:age,
data = data2, family = "binomial")
2. Perform 2-fold cross-validation.
# Perform k-fold cross-validation (2-fold)
cv_error <- cv.glm(data2, m3, K = 2)
cv_error$delta
Result: 0.1303832 0.1290684
Perform 5-fold cross-validation.
Result: 0.1274221 0.1273104
Perform 10-fold cross-validation.
Result: 0.1277733 0.1276991
Perform 25-fold cross-validation.
Result: 0.1276396 0.1276131
Perform 50-fold cross-validation.
Result: 0.1276981 0.1276844
Perform 100-fold cross-validation.
Result: 0.1277033 0.1276967
3. What did you observe, if anything, about the CV values?
CV(n) values for k-fold cross-validation for our model are the almost same for k=2; 5; 10; 25; 50; and 100. The difference in numbers is not significant.
4. What did you observe, if anything, about the processing time?
The processing time was pretty fast.
What can I say else?
International Marketing And Export Management
ISBN: 9781292016924
8th Edition
Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr