strengejacke / sjPlot

sjPlot - Data Visualization for Statistics in Social Science

Home Page:https://strengejacke.github.io/sjPlot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`digits.p = 1` gives incorrect p value

felixgolcher opened this issue · comments

Thanks a lot for that fantastic package. It saved so much time, effort and brain for me!

Setting digits.p to 1 shows (here, at least) pvals to be below .001 which are clearly not:

set.seed(20)
m0 <- lm(extra~group, sleep[sample(nrow(sleep), 20, replace = T),]) # get right amount of data
coefficients(summary(m0))["group2","Pr(>|t|)"] # pval ~ .02
sjPlot::tab_model(m0, digits.p = 1) # shows pval as < .001  ❌
sjPlot::tab_model(m0, digits.p = 2) # shows pval ~ 02       ✅

Session Info:

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Manjaro Linux

Matrix products: default
BLAS:   /usr/lib/libopenblasp-r0.3.18.so
LAPACK: /usr/lib/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sjPlot_2.8.9

loaded via a namespace (and not attached):
 [1] zoo_1.8-9         tidyselect_1.1.1  sjlabelled_1.1.8  xfun_0.26         performance_0.8.0 purrr_0.3.4       splines_4.1.1     lattice_0.20-45   parameters_0.14.0
[10] colorspace_2.0-2  vctrs_0.3.8       generics_0.1.0    utf8_1.2.2        survival_3.2-13   rlang_0.4.11      nloptr_1.2.2.2    pillar_1.6.3      glue_1.4.2       
[19] DBI_1.1.1         modelr_0.1.8      effectsize_0.5    emmeans_1.7.0     multcomp_1.4-17   lifecycle_1.0.1   sjmisc_2.8.7      munsell_0.5.0     gtable_0.3.0     
[28] bayestestR_0.11.0 mvtnorm_1.1-3     codetools_0.2-18  coda_0.19-4       knitr_1.36        datawizard_0.2.1  fansi_0.5.0       Rcpp_1.0.7        broom_0.7.9      
[37] TH.data_1.1-0     xtable_1.8-4      scales_1.1.1      backports_1.2.1   ggeffects_1.1.1   lme4_1.1-27.1     ggplot2_3.3.5     insight_0.14.4    dplyr_1.0.7      
[46] grid_4.1.1        tools_4.1.1       sjstats_0.18.1    sandwich_3.0-1    magrittr_2.0.1    tibble_3.1.5      crayon_1.4.1      tidyr_1.1.4       pkgconfig_2.0.3  
[55] MASS_7.3-54       ellipsis_0.3.2    Matrix_1.3-4      estimability_1.3  minqa_1.2.4       assertthat_0.2.1  R6_2.5.1          boot_1.3-28       nlme_3.1-153     
[64] compiler_4.1.1

Another, very small point: p-vals are not zero padded, right? With digits.p set to two you get .065, but also .01 instead of the .010 some might prefer.

Setting digits.p to 1 shows (here, at least) pvals to be below .001 which are clearly not:

This function simply works with round(), that's why you get 0, and 0 is formatted a <0.001:

round(.02)
#> [1] 0

Created on 2021-10-16 by the reprex package (v2.0.1)

Another, very small point: p-vals are not zero padded, right? With digits.p set to two you get .065, but also .01 instead of the .010 some might prefer.

Do you have a reproducible example? According to the code, the formatting should be 0.0100 when digits.p = 4.

This function simply works with round(), that's why you get 0, and 0 is formatted a <0.001:

Understood. Is that behavior intended though? I bet, there's a reason you did not use signif.

Do you have a reproducible example? According to the code, the formatting should be 0.0100 when digits.p = 4.

I don't because you are right and I was wrong. I did not figure out the rounding thing and got mixed up.

I bet, there's a reason you did not use signif.

Yes, when I started working on sjPlot, I just recently switched from SPSS to R and wasn't aware of that function ;-)

You switched from SPSS and immediately set out to write this gorgeous package? That's a feat.
Are you interested in a MR for that or do you like it just as it is?

Feel free to submit a PR, that would be great!