Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pander.lm() and pander.summary.lm(): Reordering of coefficients #232

Closed
krlmlr opened this issue Dec 7, 2015 · 7 comments
Closed

pander.lm() and pander.summary.lm(): Reordering of coefficients #232

krlmlr opened this issue Dec 7, 2015 · 7 comments
Assignees

Comments

@krlmlr
Copy link
Contributor

krlmlr commented Dec 7, 2015

The coefficient that appears first in the output of summary.lm() seems to appear last in the output of pander::pander.lm(). It looks like this is by design, but this makes models without intercept look very awkward.

> lm(Petal.Width~Petal.Length+Sepal.Width+Species-1, iris) %>% pander::pander

--------------------------------------------------------------------
                    Estimate   Std. Error   t value   Pr(>|t|) 
----------------------- ---------- ------------ --------- ----------
    **Sepal.Width**       0.202       0.0442      4.571    1.03e-05 

   **Speciessetosa**     -0.6953      0.1424     -4.882   2.739e-06 

 **Speciesversicolor**   0.04165      0.1546     0.2695     0.7879  

 **Speciesvirginica**     0.4806      0.1901      2.529    0.01251  

   **Petal.Length**       0.1701     0.03489      4.876   2.808e-06 
--------------------------------------------------------------------

Table: Fitting linear model: Petal.Width ~ Petal.Length + Sepal.Width + Species - 1

> lm(Petal.Width~Petal.Length+Sepal.Width+Species-1, iris) %>% summary

Call:
lm(formula = Petal.Width ~ Petal.Length + Sepal.Width + Species - 
    1, data = iris)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.55861 -0.08486 -0.00190  0.09073  0.48605 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
Petal.Length       0.17012    0.03489   4.876 2.81e-06 ***
Sepal.Width        0.20203    0.04420   4.571 1.03e-05 ***
Speciessetosa     -0.69529    0.14242  -4.882 2.74e-06 ***
Speciesversicolor  0.04165    0.15457   0.269   0.7879    
Speciesvirginica   0.48064    0.19005   2.529   0.0125 *  

---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1685 on 145 degrees of freedom
Multiple R-squared:  0.9864,    Adjusted R-squared:  0.9859 
F-statistic:  2100 on 5 and 145 DF,  p-value: < 2.2e-16

@daroczig
Copy link
Member

daroczig commented Dec 8, 2015

Good catch, thanks for reporting this issue! The above (very trivial, but hopefully OK) commit should resolve this behavior -- looking forward to any feedback.

@krlmlr
Copy link
Contributor Author

krlmlr commented Dec 8, 2015

Thanks. I'd prefer not to rearrange parameters at all (or at least make it optional), but you probably have a good reason to do this the way you're doing it.

@daroczig
Copy link
Member

daroczig commented Dec 8, 2015

@RomanTsegelskyi do you remember the motives behind moving the intercept to the bottom of the table?

@romantseg
Copy link
Contributor

I can't recall the reason right away, so it might be my mistake when I was refactoring the implementation

@daroczig
Copy link
Member

daroczig commented Dec 8, 2015

I spent some time digging the git history and found d28cf55 to be the related commit. This is due to #46, and we are moving the intercept to the bottom of the table as this looked appropriate based on the stargazer behavior.

@krlmlr @kovla does it make sense? Not sure if it's needed or not (personally, I do not care if the intercept is on the top or at the bottom of the table), looking forward to any feedback. And of course we can make this optional.

@krlmlr
Copy link
Contributor Author

krlmlr commented Dec 8, 2015

IMO, if some journals require this behavior, it's reasonable to support it as an option. Making it default confuses newbies that are used to R's output.

@daroczig daroczig reopened this Dec 10, 2015
@daroczig daroczig self-assigned this Dec 11, 2015
@daroczig
Copy link
Member

Makes sense, done with the above commit:

> pander(lm(am ~ wt, mtcars))

--------------------------------------------------------------
     &nbsp;        Estimate   Std. Error   t value   Pr(>|t|) 
----------------- ---------- ------------ --------- ----------
 **(Intercept)**    1.542       0.2256      6.838   1.378e-07 

     **wt**        -0.3532     0.06717     -5.258   1.125e-05 
--------------------------------------------------------------

Table: Fitting linear model: am ~ wt

> pander(lm(am ~ wt, mtcars), move.intercept = TRUE)

--------------------------------------------------------------
     &nbsp;        Estimate   Std. Error   t value   Pr(>|t|) 
----------------- ---------- ------------ --------- ----------
     **wt**        -0.3532     0.06717     -5.258   1.125e-05 

 **(Intercept)**    1.542       0.2256      6.838   1.378e-07 
--------------------------------------------------------------

Table: Fitting linear model: am ~ wt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants