merge.factor {mining}R Documentation

Merge factor levels

Description

Merges factor levels with similar response distributions (assumed normal).

Usage

merge.factor(f,x,n,same.var=T,trace=T,xlab=NA,ylab=NA)

Arguments

f a factor
x a numerical vector, same length as f
n the desired number of factor levels
same.var argument passed to ward
trace If TRUE, a merging trace is plotted (plot.hclust.trace)
xlab,ylab axis labels. If NA, taken from f and x arguments.

Details

Calls ward(split(x,f)) to get a tree, cuts the tree, and constructs a new factor. The tree is shown via boxplot.hclust.

Value

A new factor, same length as f, but with n levels.

Author(s)

Tom Minka

Examples

n <- 20
x <- c(rnorm(n)+1, rnorm(n)+2, rnorm(n)*4+2)
f <- gl(3,n)
levels(f) <- c("a","b","c")
merge.factor(f,x,2,same.var=T)
merge.factor(f,x,2,same.var=F)

# an ordered factor
data(va.deaths)
merge.factor(va.deaths$Age,va.deaths$Rate,2)

[Package Contents]