invictus invictus - 1 month ago 21
R Question

decreasing coefficients in R's coefplot?

coefplot
from
library(coefplot)
has a variable
decreasing
which when set to to
TRUE
the coefficients should be plotted in descending order

But when I run a toy example:

data(tips, package = "reshape2")
mod1 <- lm(tip ~ day + sex + smoker, data = tips)
coefplot(mod1, decreasing = TRUE)


the coefficients aren't in descending order.

What am I missing?

enter image description here

Answer

You need to set sort = "magnitude":

coefplot(mod1, decreasing = TRUE, sort = "magnitude")

enter image description here

The default sorting is "natural", which is effectively 1:length(coef(mod1)).