group.plot {rare} | R Documentation |
Visualize groups by coloring branches and leaves of an hclust tree
Description
The function plots an hclust
tree with branches and leaves colored
based on group membership. The groups span the covariate indices {1, ..., nvars
}.
Covariates from the same group share equal coefficient (beta
), and sibling
groups have different coefficients. The function determines groups based on
the sparsity in gamma
. In an hclust
tree with beta[i]
on the
i
th leaf, the branch and leaf are colored in blue, red or gray according to beta[i]
being positive, negative or zero, respectively. The larger the magnitude of beta[i]
is,
the darker the color will be. So branches and leaves from the same group will have the
same color.
Usage
group.plot(beta, gamma, A, hc, nbreaks = 20)
Arguments
beta |
Length- |
gamma |
Length- |
A |
|
hc |
An |
nbreaks |
Number of breaks in binning |
Examples
## Not run:
# See vignette for more details.
set.seed(100)
ts <- sample(1:length(data.rating), 400) # Train set indices
# Fit the model on train set
ourfit <- rarefit(y = data.rating[ts], X = data.dtm[ts, ], hc = data.hc, lam.min.ratio = 1e-6,
nlam = 20, nalpha = 10, rho = 0.01, eps1 = 1e-5, eps2 = 1e-5, maxite = 1e4)
# Cross validation
ourfit.cv <- rarefit.cv(ourfit, y = data.rating[ts], X = data.dtm[ts, ],
rho = 0.01, eps1 = 1e-5, eps2 = 1e-5, maxite = 1e4)
# Visualize the groups at optimal beta and gamma
ibest.lambda <- ourfit.cv$ibest[1]
ibest.alpha <- ourfit.cv$ibest[2]
beta.opt <- ourfit$beta[[ibest.alpha]][, ibest.lambda]
gamma.opt <- ourfit$gamma[[ibest.alpha]][, ibest.lambda] # works if ibest.alpha > 1
# Visualize the groups at optimal beta and gamma
group.plot(beta.opt, gamma.opt, ourfit$A, data.hc)
## End(Not run)