This function compares different regression models by calculating their mean squared error (MSE)

compare_regression_models(
  data,
  x_vars,
  y_var,
  new_data,
  lambda = 1,
  alpha = 1,
  max_iter = 1000,
  tol = 1e-04,
  degree = 2,
  k = 5
)

Arguments

data

A data frame containing the data to fit the models

x_vars

A character vector of predictor variable names

y_var

A character string of the response variable name

new_data

A data frame containing the data for making predictions

lambda

A numeric value for the ridge and lasso regularization parameter (default 1)

alpha

A numeric value for the lasso mixing parameter (default 1)

max_iter

A numeric value for the maximum number of iterations for lasso (default 1000)

tol

A numeric value for the tolerance for lasso convergence (default 1e-4)

degree

A numeric value for the polynomial regression degree (default 2)

k

A numeric value for the number of neighbors for kNN regression (default 5)

Value

A data frame showing the models and their corresponding MSE values, sorted by smallest MSE