Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

clusterICE

Clustering of ICE and d-ICE curves by kmeans.


Description

Clustering if ICE and d-ICE curves by kmeans. All curves are centered to have mean 0 and then kmeans is applied to the curves with the specified number of clusters.

Usage

clusterICE(ice_obj, nClusters, plot = TRUE, plot_margin = 0.05, 
           colorvec, plot_pdp = FALSE, x_quantile = FALSE, 
           avg_lwd = 3, centered = FALSE, 
           plot_legend = FALSE, ...)

Arguments

ice_obj

Object of class ice or dice to cluster.

nClusters

Number of clusters to find.

plot

If TRUE, plots the clusters.

plot_margin

Extra margin to pass to ylim as a fraction of the range of cluster centers.

colorvec

Optional vector of colors to use for each cluster.

plot_pdp

If TRUE, the PDP (ice object) or d-PDP (dice object) is plotted with a dotted black line and highlighted in yellow.

x_quantile

If TRUE, the plot is drawn with the x-axis taken to be quantile(gridpts). If FALSE, the predictor's original scale is used.

avg_lwd

Average line width to use when plotting the cluster means. Line width is proportional to the cluster's size.

centered

If TRUE, all cluster means are shifted to be to be 0 at the minimum value of the predictor. If FALSE, the original cluster means are used.

plot_legend

If TRUE a legend mapping line colors to the proportion of the data in each cluster is added to the plot.

...

Additional arguments for plotting.

Value

The ouput of the kmeans call (a list of class kmeans).

See Also

ice, dice

Examples

## Not run: 
require(ICEbox)
require(randomForest)
require(MASS) #has Boston Housing data, Pima

data(Boston) #Boston Housing data
X = Boston
y = X$medv
X$medv = NULL

## build a RF:
bh_rf = randomForest(X, y)

## Create an 'ice' object for the predictor "age":
bh.ice = ice(object = bh_rf, X = X, y = y, predictor = "age",
            frac_to_build = .1) 

## cluster the curves into 2 groups.
clusterICE(bh.ice, nClusters = 2, plot_legend = TRUE)

## cluster the curves into 3 groups, start all at 0.
clusterICE(bh.ice, nClusters = 3, plot_legend = TRUE, center = TRUE)

## End(Not run)

ICEbox

Individual Conditional Expectation Plot Toolbox

v1.1.2
GPL-2 | GPL-3
Authors
Alex Goldstein, Adam Kapelner, Justin Bleich
Initial release
2017-07-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.