1

Stargazer and ggplot2 seem to be giving different median values for the same dataset. Does anyone know if they might be calculating the median differently?

joey5
  • 139
  • 1
  • 10
  • 1
    It's would be easier to help if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data and code that shows a difference. Neither of those packages provide a function themselves that calculates a median so it really depends on how you are using them. – MrFlick Oct 10 '17 at 13:57
  • yeah difficult to do without giving the whole dataset. – joey5 Oct 10 '17 at 16:24

1 Answers1

0

It does not seem to be the case.

library(stargazer)
library(tidyverse)

stargazer(mtcars[,-c(3,4)], type="text", median=TRUE)

=================================================
Statistic N   Mean  St. Dev.  Min   Median  Max  
-------------------------------------------------
mpg       32 20.091  6.027   10.400 19.200 33.900
cyl       32 6.188   1.786     4      6      8   
drat      32 3.597   0.535   2.760  3.695  4.930 
wt        32 3.217   0.978   1.513  3.325  5.424 
qsec      32 17.849  1.787   14.500 17.710 22.900
vs        32 0.438   0.504     0      0      1   
am        32 0.406   0.499     0      0      1   
gear      32 3.688   0.738     3      4      5   
carb      32 2.812   1.615     1      2      8   
-------------------------------------------------

ggplot(data = stack(mtcars[,-c(3,4)]), aes(x = ind, y = values)) + 
  geom_boxplot() 

enter image description here

We can clearly see the last four medians, 0, 0, 4 and 2. 19.2 also seems fine from a visual inspection.

Marco
  • 2,368
  • 6
  • 22
  • 48