Search code examples
rregressionlinear-regressionlmcoefplot

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.glm(mod2, decreasing = TRUE)

the coefficients aren't in descending order.

What am I missing?

EDIT I was missing sort = "magnitude". However, this doesn't work with multiplot:

data(tips, package = "reshape2")
mod1 <- lm(tip ~ day + sex + smoker, data = tips)
mod2 <- lm(tip ~ day + sex + smoker + size, data = tips)
multiplot(mod1, mod2, decreasing = TRUE, sort = "magnitude")

Solution

  • 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)).