merge_factor | 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 |
n |
the desired number of factor levels |
same.var |
argument passed to |
trace |
If TRUE, a merging trace is plotted
( |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.