merge.factor {mining} | R Documentation |
Merges factor levels with similar response distributions (assumed normal).
merge.factor(f,x,n,same.var=T,trace=T,xlab=NA,ylab=NA)
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. |
Calls ward(split(x,f))
to get a tree, cuts the tree, and
constructs a new factor. The tree is shown via boxplot.hclust
.
A new factor, same length as f
, but with n
levels.
Tom Minka
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)