Learn R Programming

rENA (version 0.3.0)

get_x1_main_effect: Extract Main Effect Contribution of the First Predictor Using Elastic Net

Description

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.

Usage

get_x1_main_effect(V, X, alpha = 1, lambda = "lambda.min")

Value

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.

Arguments

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 (x1).

alpha

Elastic net mixing parameter (0 = ridge, 1 = lasso). Default is 1.

lambda

The value of the regularization parameter to use. Can be "lambda.min", "lambda.1se", or a specific numeric value. Default is "lambda.min".

Details

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.

Examples

Run this code
if (FALSE) {
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)
}

Run the code above in your browser using DataLab