predict_lasso_regression.Rd
This function predicts response variable values using a fitted Lasso regression model.
predict_lasso_regression(fit, new_data, x_vars)
A list containing the fitted coefficients and intercept from the fit_lasso_regression function
A data frame containing the predictor variables for which predictions are to be made
A character vector of column names corresponding to the predictor variables
A numeric vector of predicted response variable values
# Generate sample data
set.seed(123)
n <- 100
p <- 5
data <- data.frame(matrix(rnorm(n * p), n, p))
colnames(data) <- paste0("x", 1:p)
data$y <- data$x1 + data$x2 + rnorm(n)
# Fit the Lasso regression using the function
fit <- fit_lasso_regression(data, x_vars=c("x1", "x2", "x3", "x4", "x5"), y_var="y", lambda=0.1)
# Make predictions using the fitted model
predictions <- predict_lasso_regression(fit, new_data=data, x_vars=c("x1", "x2", "x3", "x4", "x5"))