Skip to contents

Computes a rotation (direction) `r` representing the contribution of the first column of `X` to the multivariate ENA matrix `V`. Supports optional subsetting by `groups`, optional inclusion of interaction terms when computing adjusted contributions.

Usage

gmr(
  V,
  X,
  groups = NULL,
  alpha = 1,
  lambda = "lambda.min",
  interactions = TRUE,
  verbose = TRUE
)

Arguments

V

Numeric ENA matrix (units × connections) ready for rotation.

X

Data frame or matrix of predictors; the first column is the target.

groups

Optional vector specifying target groups to subset. If `NULL` (default), all rows are used.

alpha

Elastic-net mixing parameter forwarded to `get_x1_main_effect` (default `1` — Lasso).

lambda

Lambda selection for `cv.glmnet` forwarded to `get_x1_main_effect` (default `"lambda.min"`).

interactions

Logical; if `TRUE` (default) interactions are included when computing the adjusted contribution.

verbose

Logical; if `TRUE` (default) the function emits messages about fails or successes.

Value

A numeric vector `r` (length = ncol(V)) giving the normalized rotation direction. Attributes attached:

`target`

The full-length target vector (un-subsetted).

`Vx1`

The unadjusted fitted values (`lm(V ~ target)`) embedded in a full-length matrix (rows outside subset filled with zeros).

If no valid direction can be found (including SVD failure), returns `NULL` and issues a warning.

See also

[get_x1_main_effect()]

Examples

if (FALSE) { # \dontrun{
set.seed(1)
V <- matrix(rnorm(200), nrow = 40)
X <- data.frame(group = rep(letters[1:4], each = 10),
                x2 = rnorm(40), x3 = rnorm(40))
r_all <- gmr2(V, X)
r_subset <- gmr2(V, X, groups = c("a", "b"), interactions = TRUE)
} # }