Skip to contents

Computes the main-effect contribution of the first column of `X` (the "target") to the multivariate ENA matrix `V`. The function fits penalized regression models (via glmnet) and can optionally include interactions between the target and other covariates. It returns the fitted contribution matrix (units × connections).

Usage

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

Arguments

V

A numeric matrix (units × connections) of dependent variables.

X

A data frame or matrix of predictors / covariates. The **first** column is treated as the target variable whose contribution will be extracted.

alpha

Elastic-net mixing parameter passed to `cv.glmnet`. `alpha = 1` (default) is Lasso; `alpha = 0` is ridge.

lambda

Character or numeric. Which lambda from the `cv.glmnet` fit to use; e.g. `"lambda.min"` (default) or `"lambda.1se"`, or a numeric value.

include_interactions

Logical; if `TRUE`, include main-effect columns **and** all interaction columns that begin with the target name (default: `FALSE`, only main-effect columns).

...

Additional arguments are not used (kept for forward compatibility).

Value

A numeric matrix with the same dimensions as `V` containing the estimated contribution of `X[,1]` to each response. If no columns are matched or all coefficients are zero, a zero matrix is returned and a warning is issued.

Details

The function can compute contributions using either only main-effect columns (no interactions) or main-effect plus all interaction columns that start with the target name. If no matching columns are found or all fitted coefficients are zero, the function returns a zero matrix and emits a warning.

Internally this function builds `model.matrix(~ .^2, data = X)` to obtain main effects and pairwise interactions. It sets a `penalty.factor` that leaves the target-related columns unpenalized (0) and fits a multivariate `glmnet` (`family = "mgaussian"`). The returned matrix is dense (numeric).

See also

[gmr2()] for the rotation routine that uses this function.

Examples

if (FALSE) { # \dontrun{
set.seed(1)
V <- matrix(rnorm(50), ncol = 5)
X <- data.frame(CONFIDENCE = rnorm(10), Condition = factor(rep(1:2, 5)))
# main effects only
Vx_main <- get_x1_main_effect(V, X, include_interactions = FALSE)
# include interactions
Vx_full <- get_x1_main_effect(V, X, include_interactions = TRUE, alpha = 0) # ridge
} # }