uvarpro.RdIdentifies variables that help explain dependence in data without a
specified outcome. uvarpro forms local comparisons using forest
rules. get.beta.entropy summarizes which variables help
distinguish the groups in these comparisons. sdependent
displays the resulting relationships as a graph and highlights
candidate signal variables.
uvarpro(data,
method = c("auto", "unsupv", "rnd"),
ntree = 200, nodesize = NULL,
max.rules.tree = 20, max.tree = 200,
verbose = FALSE, seed = NULL,
...)
get.beta.entropy(o,
second.stage = FALSE,
pre.filter = TRUE,
papply = mclapply,
vimp.min = 0,
nfolds = 10,
maxit = 2500,
thresh = 1e-3,
parallel = FALSE,
use.cv = TRUE,
lambda.sel = c("lambda.1se", "lambda.min"),
nlambda = NULL,
lambda.min.ratio = NULL,
nlambda.lasso = nlambda,
lambda.min.ratio.lasso = lambda.min.ratio)
sdependent(I,
threshold = .25,
layout = "grid",
q.signal = .75,
directed = TRUE,
min.degree = NULL,
title = "s-Dependent Variable Detection",
plot = TRUE)Data frame containing the features to be analyzed, without an outcome or class-label column. Rows with missing values are omitted, unused factor levels are dropped, and categorical features are hot-encoded. See Details.
Method for growing the forest: "auto" learns to
reproduce the supplied variables, "unsupv" uses unsupervised
splitting, and "rnd" uses random splitting. See Details.
Number of trees to grow.
Minimum terminal node size. Larger values give broader groups of observations. The default is chosen from the number of complete observations.
Maximum number of rules sampled per tree for the local comparisons.
Maximum number of trees used to extract rules.
Currently unused.
Optional seed passed to the forest calculation. Use
set.seed before uvarpro to also control R-level
sampling, and seed the lasso analysis separately; see Note.
Additional named forest arguments recognized by
rfsrc, such as mtry or ytry, and a custom
scoring function supplied as entropy; see Details.
Supply lasso controls to get.beta.entropy.
An object returned by uvarpro, containing the
processed data in x and the group membership lists
in entropy.
If FALSE, return the mean absolute
logistic-lasso coefficient matrix. If TRUE, perform an
additional local linear lasso using the predictors selected by the
logistic stage, and return its mean absolute coefficients divided
by the standard deviation of the released variable. See Details.
Should preliminary importance from uvarpro
restrict the lasso analysis to variables with
get.vimp(o, pretty = FALSE) > vimp.min? The filter applies
to both predictors and release variables. It is skipped when
preliminary importance is unavailable.
An lapply-like function for processing released
variables. Use lapply for serial execution. The default
mclapply uses separate R worker sessions (a PSOCK cluster)
when getOption("mc.cores", 1L) is greater than one, and
serial execution otherwise. The parallel
argument controls parallelism across cross-validation folds.
Strict lower cutoff for preliminary importance when
pre.filter = TRUE. The default retains values greater than
zero. Ignored when pre.filter = FALSE.
Number of cross-validation folds for each local
logistic-lasso analysis. At least three folds are required.
Ignored when use.cv = FALSE.
Maximum number of iterations passed to glmnet
in both lasso stages.
Convergence tolerance passed to glmnet.
Should cv.glmnet process its folds in parallel?
A suitable foreach backend must be registered. Ignored when
use.cv = FALSE. Account for available resources when
enabling both levels of parallelism.
Should the logistic-lasso penalty be chosen by
cross-validation? If FALSE, coefficients are taken at the
last, smallest penalty on the computed glmnet path.
Cross-validation penalty choice for the logistic
stage. "lambda.1se" selects the largest penalty whose
cross-validation error is within one standard error of the minimum;
"lambda.min" selects the penalty minimizing that error.
Ignored when use.cv = FALSE.
Number of penalty values requested for the logistic
stage. NULL leaves the glmnet default unchanged. The
computed path can end before all requested values are reached.
Smallest requested logistic-stage penalty
relative to the largest penalty on the path. NULL uses the
glmnet default.
Corresponding path
controls for the optional second-stage linear lasso. They default
to the logistic-stage settings and are used only when
second.stage = TRUE. The second stage uses the last
computed penalty.
A finite, nonnegative numeric importance matrix, usually
obtained from get.beta.entropy, with released variables as
rows and predictors as columns. Supply unique, nonempty row and
column names. Row names must belong to the column names and may
occur in any order. Rows are aligned by name; missing release rows
are filled with zeros.
Positive edge cutoff on the scale of I.
An off-diagonal entry greater than or equal to this value creates
an edge. Increasing the cutoff removes edges; decreasing it can
recover weaker connections.
Graph layout. Supported names are "fr",
"dh", "gem", "kk", "lgl",
"mds", "sugiyama", "graphopt",
"nicely", "random", "sphere",
"grid", "circle", "star", "tree",
and "bipartite"; unambiguous abbreviations are accepted.
Layout-specific requirements of igraph still apply.
Alternatively, supply a numeric coordinate matrix with one row
per nonisolated vertex, in graph vertex order.
Quantile of the global importance scores among nonisolated vertices used for signal designation. Values range from zero to one; the default is the upper quartile. A signal must meet both this cutoff and the degree condition.
Should the graph be directed? In the directed graph, an edge goes from the released variable to the predictor used to distinguish its local comparison groups. For an undirected display, supply a symmetric importance matrix; see Note.
Minimum degree for candidate signal designation. With directed graphs this is the out-degree. The default is 1 for directed graphs and 2 for undirected graphs.
Title for the graph.
Should the graph be plotted? If FALSE, graph
construction and signal selection are still performed. The
igraph package is required in either case.
UVarPro helps identify variables that explain dependence in a data set without requiring a response. Every supplied column is treated as a variable to be studied. The results can be inspected as an importance matrix, summarized as a ranking, or displayed as a graph.
The main workflow uses three functions:
o <- uvarpro(data) uses a forest to define groups
of observations for local comparisons.
I <- get.beta.entropy(o, papply = lapply) estimates
which variables distinguish those groups and returns an
importance matrix.
sdependent(I) displays the relationships as a graph
and identifies candidate signal variables.
Inspect the matrix before plotting; get.beta.entropy can
return NULL when no usable coefficient estimates are found.
importance(o) gives a separate, preliminary summary used for
optional screening. It is not the lasso importance matrix used to
construct the graph.
A forest rule defines a group through conditions on variable values. For example, a rule might require \(x_1 \leq 0.5\) and \(x_2 > 0.3\). Removing the condition on \(x_1\), while keeping the other condition, is called releasing \(x_1\). The newly admitted observations form the near-miss, or complementary, group.
For a rule region \(R\) and released variable \(s\), write the enlarged region as \(R^{(s)}\). The near-miss set is $$C_s = R^{(s)} \setminus R.$$ Original-region observations are out-of-bag for the corresponding tree. Both groups must be nonempty for a comparison to be used.
get.beta.entropy assigns class 1 to the original group and
class 0 to the near-miss group. It then uses the other variables to
predict group membership with logistic lasso regression. The
released variable is excluded because its rule condition already
separates the groups. Variables that help distinguish the groups
provide evidence of local dependence. Repeating this calculation
across rules allows the relationships to differ across the data.
In the matrix returned by get.beta.entropy, rows identify
released variables and columns identify predictors. For example,
I["x1", "x2"] measures the average coefficient magnitude
for x2 when distinguishing groups formed by releasing
x1. The reverse entry answers a different
question, so the matrix is generally asymmetric.
Each entry is the mean absolute logistic-lasso coefficient across the usable comparisons for that row. The diagonal is zero because a variable is excluded from its own release comparison. Predictors not selected in a usable comparison contribute zero. Thus $$ I_{sj} = \frac{1}{|\mathcal K_s|} \sum_{r \in \mathcal K_s} |\widehat\beta_{srj}|, \qquad j \ne s, \qquad I_{ss} = 0, $$ where \(\mathcal K_s\) contains the usable comparisons for released variable \(s\).
A comparison is usable when fitting succeeds and at least one finite, nonzero predictor coefficient is obtained. Failed fits and intercept-only fits are excluded. Comparisons receive equal weight. A row is omitted when none of its comparisons is usable, so the matrix can have fewer rows than columns.
colSums(I) summarizes each predictor's contributions across
all release variables. Larger sums indicate larger total
contributions; column means give the same ranking.
sdependent(I) draws an arrow from variable s to
variable j when I[s, j] >= threshold. The arrow
means that j helps distinguish the groups formed by
releasing s. It describes a predictive relationship, not
a causal direction. Arrows in both directions and cycles are
allowed.
Increase threshold to show fewer connections or decrease
it to include weaker connections. The cutoff applies to the
coefficient magnitudes in I. The graph is based on the
adjacency matrix
$$
A_{sj} = \mathbf{1}\{I_{sj} \ge t\}, \quad s \ne j,
\qquad A_{ss} = 0,
$$
where \(t\) is threshold. Rows are matched to columns
by variable name, with zero rows added for missing release variables.
Variables with no connections are removed from the graph.
Candidate signals are selected using both connectivity and overall
importance. With the default directed graph, a variable must have
at least min.degree outgoing arrows and a column-sum score
at or above the q.signal quantile among variables remaining
in the graph. The defaults require one outgoing arrow and a score
in the upper quartile, including ties.
These two summaries describe different roles. Out-degree counts
predictors selected when a variable is released; column-sum
importance measures that variable's contributions when other
variables are released. In-degree counts the incoming arrows.
Column sums use all importance values, including those below the
edge cutoff, and are calculated before isolated variables are
removed. Consequently, changing threshold can also change
the set of variables used to determine the importance quantile.
Candidate signal vertices are blue and other vertices are gray.
Directed arrows are blue when their source is a candidate signal.
Vertex sizes increase with column-sum importance, and arrow widths
increase with their importance entries. Specifically, the size is
6 + 2 * log1p(imp.score) and an edge with value \(w\)
has width \(1 + 3w/w_{\max}\); widths are
rescaled within each plot. Use plot = FALSE to obtain the
graph summaries without drawing it.
The population goal is a signal set that accounts for dependence among the remaining variables (Zhou et al., 2026). Redundant or interchangeable variables can give more than one such set. The graph's signal designations are exploratory candidates.
The method argument chooses how the forest forms its rules:
"auto"The default uses copies of the variables as multiple regression responses, with the variables themselves as predictors. This forest autoencoder forms groups by learning to reproduce the observed variable values.
"unsupv"Uses unsupervised splitting, with some
variables temporarily serving as responses. ytry
controls how many are used.
"rnd"Uses random splitting with an independently generated Gaussian response.
All three methods use the same subsequent rule comparisons and
lasso analysis. ntree controls the number of trees grown;
max.tree and max.rules.tree limit rule extraction.
Larger nodesize values form broader groups of observations.
Rows with missing values are omitted. Categorical variables are
converted to numeric indicator columns, called hot-encoding.
The processed data are stored in o$x. All membership
indices refer to these rows, and each processed column is studied
separately. A factor can therefore contribute several rows or
columns to the importance matrix and several graph vertices.
importance(o) summarizes the preliminary scores calculated
by uvarpro. The default rule score compares how much the
variables vary within the original and near-miss groups with how
much they vary when the groups are pooled. If \(d(M)\) is the
average column standard deviation of a matrix \(M\), the score is
$$
H = \frac{d(X_C) + d(X_O)}{2 d(X_C \cup X_O)}.
$$
The union denotes row concatenation. Before scoring, each variable
is divided by its full-data standard deviation without centering;
near-zero standard deviations are replaced by one. All variables,
including the released variable, enter this calculation.
By default, get.beta.entropy limits both release variables
and lasso predictors to those with preliminary importance above
vimp.min. Set pre.filter = FALSE to make all
processed variables available to the lasso analysis. The filter
is skipped if the preliminary importance calculation fails.
Each local classification uses binomial lasso regression from
glmnet, with \(\alpha = 1\). By default,
cross-validation chooses a separate penalty for each comparison
using binomial deviance. lambda.sel = "lambda.1se" uses
the largest penalty within one standard error of the minimum;
"lambda.min" uses the penalty with minimum error. Set
use.cv = FALSE to use the last, smallest penalty on the
computed path instead. nlambda and lambda.min.ratio
control that path.
Before fitting, scale(X, center = FALSE) divides each
predictor by \(\sqrt{\sum_i X_{ij}^2/(m-1)}\),
where \(m\) is the local sample size. This measures spread
around zero rather than around the local mean. glmnet
also uses its default internal standardization and returns
coefficients on the scale of the matrix supplied to it. Predictors
that are constant within a comparison are excluded from that fit;
their contributions are zero in the importance matrix. A comparison
can use a single varying predictor.
With second.stage = TRUE, the variables selected by the
logistic lasso enter a second local regression. This time the
released variable is the response. The regression uses the pooled
observations from both groups and a Gaussian lasso, with the same
predictor scaling and response values from o$x. It uses
the last computed penalty, controlled by nlambda.lasso
and lambda.min.ratio.lasso.
The absolute second-stage coefficients are averaged over the
comparisons used by the logistic stage. Unselected predictors,
failed second-stage fits, and second-stage fits selecting no
predictors contribute zeros. Each row is then divided by the
released variable's full-data standard deviation:
$$
I^{(2)}_{sj} =
\frac{1}{\widehat\sigma_s |\mathcal K_s|}
\sum_{r \in \mathcal K_s} |\widehat\gamma_{srj}|.
$$
A zero or nonfinite response standard deviation gives NA
for that row. get.beta.entropy returns this second-stage
matrix instead of the logistic matrix. Choose the graph cutoff
for the scale of the matrix being displayed.
papply = lapply runs the release-variable analyses in
sequence. parallel separately controls the cross-validation
folds. Avoid using more simultaneous workers than the available
cores when enabling both levels of parallelism. See Note for
reproducibility.
The example uses four independent standard normal source variables,
w, x, y, and z. Each has five noisy
copies with independent Gaussian errors of variance 0.1. Two
additional variables are h1 = w + x + e21 and
h2 = y + z + e22, with independent Gaussian errors of
variance 0.4. All errors are independent of the sources, and all
26 variables are supplied to uvarpro.
The four sources form the signal set: conditional on them, the
other 22 variables are mutually independent. Releasing a noisy
copy of w has w as its \(s\)-dependent signal;
the other copy blocks have their respective sources. Releasing
h1 has signals w and x, while releasing
h2 has signals y and z.
Conversely, when w is released, its copies and h1
can help distinguish the groups; x can also contribute
through its component of h1. The graph can therefore have
arrows in both directions. Repeated contributions across releases
motivate the column-sum ranking. The example uses
pre.filter = FALSE to include every variable and compares
the estimates with this known dependence structure.
Supply entropy through ... to replace the preliminary
scoring function. It must accept xC, xO, and
.... The first two arguments contain the scaled near-miss
and original-group data, with the released variable first.
Additional information includes compMembership,
oobMembership, the processed data, and
xvar.names.
Return a numeric rule score, or a list with the score first and
additional information second. To use get.beta.entropy
afterwards, the second element must provide the memberships as
list(comp = compMembership, oob = oobMembership), in that
order. The custom-scoring example reproduces the default score
while preserving these memberships.
uvarpro returns an object of class "uvarpro". Its
principal components are:
The forest used to generate rules.
Rule-level information with columns tree,
branch, variable, n.oob, and imp.
The variable index refers to xvar.names. Unevaluated
comparisons have NA importance.
The complete-case, hot-encoded feature data, before the scaling used in scoring or local regressions.
Processed and original feature names, respectively.
With the default scoring function, membership pairs
grouped by released variable. Each pair contains comp
and oob observation indices into x. May be
NULL when no usable memberships are available. Custom
callbacks can change the auxiliary information stored here.
Rule extraction limits.
The value "unsupv", irrespective of the
forest construction method.
get.beta.entropy returns a named numeric matrix, with released
variables as rows and eligible predictors as columns. Entries are
mean absolute logistic-lasso coefficients when
second.stage = FALSE, and response-scaled mean absolute
linear-lasso coefficients when second.stage = TRUE. Rows
with no retained comparisons are omitted. Returns NULL if
no usable release rows remain.
sdependent invisibly returns a list with components:
Names of vertices meeting both the degree and importance-quantile conditions. Can be empty even when the graph is nonempty.
Named global column-sum scores for nonisolated vertices, sorted in increasing order.
Named degrees for nonisolated vertices, in graph
vertex order. These are out-degrees when directed = TRUE.
If no edges remain, sdependent returns a character diagnostic.
See Note.
For reproducible serial lasso calculations, call set.seed
immediately before get.beta.entropy(o, papply = lapply) to
control its randomized cross-validation folds. Also call
set.seed before uvarpro to control R-level sampling
in forest construction and rule extraction. The seed argument
supplies the forest seed but does not replace these R-level seeds.
Small local classes, degenerate predictors, and excessive preliminary filtering can leave no usable comparisons. A failed local lasso fit is excluded from the coefficient average.
For an undirected display, supply a symmetric importance matrix.
For square input with matching row and column order,
pmax(I, t(I)) retains either direction. Symmetrization can
change global scores and signal designations. Undirected edge
colors use the first endpoint in the internal edge list.
To admit weaker positive edges in an empty graph, decrease
threshold. Keep the cutoff positive, since >= admits
zero-valued entries at a zero cutoff. Check for NULL lasso
output before graph construction.
Tang F. and Ishwaran H. (2017). Random forest missing data algorithms. Statistical Analysis and Data Mining, 10:363-377.
Zhou L., Lu M. and Ishwaran H. (2026). Variable priority for unsupervised variable selection. Pattern Recognition, 172:112727. doi:10.1016/j.patcog.2025.112727 .
## Small forest for a quick check
set.seed(1)
o <- uvarpro(mtcars, ntree = 1)
# \donttest{
## ------------------------------------------------------------
## Latent-variable model: known signals and s-dependence
## ------------------------------------------------------------
set.seed(21)
n <- 1000
w <- rnorm(n)
x <- rnorm(n)
y <- rnorm(n)
z <- rnorm(n)
ei <- matrix(rnorm(n * 20, sd = sqrt(.1)), ncol = 20)
e21 <- rnorm(n, sd = sqrt(.4))
e22 <- rnorm(n, sd = sqrt(.4))
wi <- w + ei[, 1:5]
xi <- x + ei[, 6:10]
yi <- y + ei[, 11:15]
zi <- z + ei[, 16:20]
h1 <- w + x + e21
h2 <- y + z + e22
dta <- data.frame(w = w, wi = wi, x = x, xi = xi,
y = y, yi = yi, z = z, zi = zi, h1 = h1, h2 = h2)
signal <- c("w", "x", "y", "z")
## All 26 columns are observed features. The remaining 22 are
## mutually independent conditional on the four signal variables.
o <- uvarpro(dta)
print(importance(o))
## Retain every feature for the local lasso analysis, including
## the noisy-copy and mixed-variable releases that reveal signals.
set.seed(22)
beta <- get.beta.entropy(o, pre.filter = FALSE,
papply = lapply, nfolds = 5)
if (!is.null(beta)) {
## Compare the column-sum ranking with the known signal set.
score <- sort(colSums(beta), decreasing = TRUE)
print(data.frame(variable = names(score),
importance = unname(score),
signal = names(score) %in% signal))
## Inspect one copy from each block and the two mixed variables.
## Population targets: each copy points to its source; h1 points
## to w and x, and h2 to y and z. See Details for source releases.
release <- c("wi.1", "xi.1", "yi.1", "zi.1", "h1", "h2")
release <- intersect(release, rownames(beta))
print(round(beta[release, signal, drop = FALSE], 2))
## Inspect the corresponding adjacency block.
## A[s, j] = 1 gives the arrow s -> j.
threshold <- 0.25
A <- 1L * (beta[release, signal, drop = FALSE] >= threshold)
print(A)
if (all(is.finite(beta)) &&
requireNamespace("igraph", quietly = TRUE)) {
set.seed(23)
## Pass the lasso matrix directly; row alignment is automatic.
graph.info <- sdependent(beta, threshold = threshold, layout = "fr",
title = "Latent model: s-dependence")
if (is.list(graph.info)) {
print(graph.info$signal.vars)
print(graph.info$degree)
} else {
print(graph.info)
}
## Return graph summaries without drawing the figure:
## graph.info <- sdependent(beta, threshold = threshold, plot = FALSE)
}
}
## Optional second-stage lasso, keeping the same feature set.
## set.seed(22)
## beta.second <- get.beta.entropy(o, pre.filter = FALSE,
## second.stage = TRUE,
## papply = lapply, nfolds = 5)
## ------------------------------------------------------------
## Boston housing: alternative forest and categorical features
## ------------------------------------------------------------
if (requireNamespace("mlbench", quietly = TRUE)) {
data(BostonHousing, package = "mlbench")
## Every column is treated as a feature; no response is specified.
o.unsupv <- uvarpro(BostonHousing, method = "unsupv")
print(importance(o.unsupv))
## Random splitting uses the same subsequent analysis.
## o.random <- uvarpro(BostonHousing, method = "rnd")
Boston <- BostonHousing
Boston$zn <- factor(Boston$zn)
Boston$chas <- factor(Boston$chas)
Boston$lstat <- factor(round(0.2 * Boston$lstat))
Boston$nox <- factor(round(20 * Boston$nox))
Boston$rm <- factor(round(Boston$rm))
o.factor <- uvarpro(Boston)
print(importance(o.factor))
print(get.orgvimp(o.factor))
print(get.orgvimp(o.factor, pretty = FALSE))
}
## ------------------------------------------------------------
## Iowa housing: larger lasso analysis
## ------------------------------------------------------------
data(housing, package = "randomForestSRC")
iowa <- roughfix(housing)
## Numeric coding below is only a speed-oriented illustration;
## retain factors to use the usual hot-encoding instead.
iowa <- data.frame(data.matrix(iowa))
o.iowa <- uvarpro(iowa, ntree = 50, max.tree = 50,
max.rules.tree = 5)
set.seed(22)
beta.iowa <- get.beta.entropy(o.iowa, papply = lapply, nfolds = 5)
if (!is.null(beta.iowa)) {
print(sort(colMeans(beta.iowa), decreasing = TRUE))
## sdependent(beta.iowa)
}
## ------------------------------------------------------------
## Custom scoring callback: reproduces the default dispersion ratio
## ------------------------------------------------------------
my.entropy <- function(xC, xO, ...) {
mean.sd <- function(x) mean(apply(x, 2, sd, na.rm = TRUE))
imp <- 0.5 * (mean.sd(xC) + mean.sd(xO)) /
mean.sd(rbind(xC, xO))
dots <- list(...)
list(imp = imp,
membership = list(comp = dots$compMembership,
oob = dots$oobMembership))
}
if (requireNamespace("mlbench", quietly = TRUE)) {
data(BostonHousing, package = "mlbench")
o.custom <- uvarpro(BostonHousing, entropy = my.entropy,
ntree = 50, max.tree = 50, max.rules.tree = 5)
print(importance(o.custom))
## The stored memberships also allow the lasso analysis.
## beta.custom <- get.beta.entropy(o.custom, papply = lapply)
}
# }