| get_x1_main_effect | R Documentation |
This function fits a multivariate elastic net regression model (using glmnet)
to estimate the main effect contribution of the first predictor variable (x1)
in the provided data frame X for each response variable in V.
The main effect is forced into the model by setting its penalty factor to zero.
get_x1_main_effect(V, X, alpha = 1, lambda = "lambda.min")
V |
A numeric matrix of response variables (dimensions: observations x responses). |
X |
A data frame containing all predictor variables. The first column is treated as the target predictor ( |
alpha |
Elastic net mixing parameter (0 = ridge, 1 = lasso). Default is 1. |
lambda |
The value of the regularization parameter to use. Can be |
The function constructs a model matrix including all main effects and two-way interactions.
It then fits a multivariate elastic net model using cv.glmnet, forcing the inclusion of the main effect of x1 by setting its penalty factor to zero.
The resulting coefficients for x1 are used to compute its contribution to the fitted values for each response variable.
A numeric matrix of the same dimensions as V, where each column contains the estimated main effect contribution of x1 for the corresponding response variable.
## Not run:
set.seed(123)
V <- matrix(rnorm(100 * 2), ncol = 2)
X <- data.frame(x1 = rnorm(100), x2 = sample(letters[1:3], 100, TRUE))
result <- get_x1_main_effect(V, X)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.