1

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")
invictus
  • 1,821
  • 3
  • 25
  • 30
  • 2
    @invictus, please add a new question. Don't make this a [chameleon question](http://meta.stackexchange.com/questions/43478/exit-strategies-for-chameleon-questions) – Ben Bolker Oct 22 '16 at 23:27
  • @BenBolker well, based on the highest voted answer in that thread, a slight extension to the question (from `coefplot()` to `multiplot()`) is fair game, but sure, whatever. Only trouble is a user (at least me) can only post once every 90 mins. – invictus Oct 22 '16 at 23:42
  • @ZheyuanLi the question came to me out of the blue after reading your answer. I wouldn't call it a great departure from the first question. – invictus Oct 22 '16 at 23:44
  • 1
    general question: how should sorting in decreasing order work when there's more than one model which might have different coefficient rank orders? Sort by coefficients of the first model? – Ben Bolker Oct 23 '16 at 01:20
  • @BenBolker first you demand a new post, then you go commenting on the old post... – invictus Oct 23 '16 at 01:24
  • "demand" is a little strong, maybe; "request"? but OK. I didn't see the new post. – Ben Bolker Oct 23 '16 at 01:29
  • "Commenting: it's a milder way to register my disapproval" -Ben Bolker – invictus Oct 23 '16 at 01:31

1 Answers1

2

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

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248