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 ith 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-nvars vector of covariate coefficient.

gamma

Length-nnodes vector of latent variable coefficient. Note that rarefit returns NA as gamma value when alpha is zero, in which case our problem becomes the lasso on beta.

A

nvars-by-nnodes binary matrix encoding ancestor-descendant relationships between leaves and nodes in the tree.

hc

An hclust tree of nvars leaves where each leaf corresponds to a covariate.

nbreaks

Number of breaks in binning beta elements (positive part and negative part are done separately). Each bin is associated with a color based on the magnitude and positivity/negativity of beta elements in the bin.

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)


[Package rare version 0.1.1 Index]