You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have detected that add_p() doesn't work with columns of class difftime. As a matter of fact it is related with wilcox.test() which doesn't accept that class, but if the variable is parsed to numeric class with as.numeric() before using it on gtsummary workflow, it does work.
So my suggestion is that add_p() should check if variables are of difftime class and in that case parse them with as.numeric() before inputting them into wilcox.test().
(Sorry for the horrible reprex which is rendered with the html code included, but at least the tables are rendered)
library(dplyr)
#> #> Attaching package: 'dplyr'#> The following objects are masked from 'package:stats':#> #> filter, lag#> The following objects are masked from 'package:base':#> #> intersect, setdiff, setequal, union
library(lubridate)
#> #> Attaching package: 'lubridate'#> The following objects are masked from 'package:base':#> #> date, intersect, setdiff, union
library(gtsummary)
set.seed(123)
time_diff<-lubridate::as.difftime(rnorm(250, 2000, 100), units="mins")
group_sample<- sample(c("A", "B"), 250, replace=TRUE)
df<-data.frame(group_sample, time_diff)
df %>% select(group_sample, time_diff) %>%
tbl_summary(by=group_sample) %>% add_p()
#> There was an error in 'add_p()/add_difference()' for variable 'time_diff', p-value omitted:#> Error in wilcox.test.default(x = structure(c(2012.92877351609, 2171.50649868833, : 'x' must be numeric
t.test(df$time_diff~df$group_sample)
#>
#> Welch Two Sample t-test
#>
#> data: df$time_diff by df$group_sample
#> t = 0.38027 mins, df = 237.43, p-value = 0.7041 mins
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#> -19.11303 mins 28.25683 mins
#> sample estimates:
#> Time differences in mins
#> mean in group A mean in group B
#> 2001.558 1996.986
wilcox.test(df$time_diff~df$group_sample)
#> Error in wilcox.test.default(x = structure(c(2012.92877351609, 2171.50649868833, : 'x' must be numeric
Hi!
I have detected that add_p() doesn't work with columns of class difftime. As a matter of fact it is related with wilcox.test() which doesn't accept that class, but if the variable is parsed to numeric class with as.numeric() before using it on gtsummary workflow, it does work.
So my suggestion is that add_p() should check if variables are of difftime class and in that case parse them with as.numeric() before inputting them into wilcox.test().
PS: t.test() does accept difftime objects
This issue is somewhat related with (#343).
Thanks in advance!
(Sorry for the horrible reprex which is rendered with the html code included, but at least the tables are rendered)
1
class(df$time_diff)
#> [1] "difftime"
t.test(df$time_diff~df$group_sample)
#>
#> Welch Two Sample t-test
#>
#> data: df$time_diff by df$group_sample
#> t = 0.38027 mins, df = 237.43, p-value = 0.7041 mins
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#> -19.11303 mins 28.25683 mins
#> sample estimates:
#> Time differences in mins
#> mean in group A mean in group B
#> 2001.558 1996.986
wilcox.test(df$time_diff~df$group_sample)
#> Error in wilcox.test.default(x = structure(c(2012.92877351609, 2171.50649868833, : 'x' must be numeric
df$time_diff <- as.numeric(df$time_diff)
df %>% select(group_sample, time_diff) %>%
<style>html { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif; } #apvbhnlzhi .gt_table { display: table; border-collapse: collapse; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; } #apvbhnlzhi .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; } #apvbhnlzhi .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; border-bottom-color: #FFFFFF; border-bottom-width: 0; } #apvbhnlzhi .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 0; padding-bottom: 4px; border-top-color: #FFFFFF; border-top-width: 0; } #apvbhnlzhi .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; } #apvbhnlzhi .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; } #apvbhnlzhi .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 6px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; } #apvbhnlzhi .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; } #apvbhnlzhi .gt_column_spanner_outer:first-child { padding-left: 0; } #apvbhnlzhi .gt_column_spanner_outer:last-child { padding-right: 0; } #apvbhnlzhi .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 6px; overflow-x: hidden; display: inline-block; width: 100%; } #apvbhnlzhi .gt_group_heading { padding: 8px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; } #apvbhnlzhi .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; } #apvbhnlzhi .gt_from_md > :first-child { margin-top: 0; } #apvbhnlzhi .gt_from_md > :last-child { margin-bottom: 0; } #apvbhnlzhi .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; } #apvbhnlzhi .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 12px; } #apvbhnlzhi .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; } #apvbhnlzhi .gt_first_summary_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; } #apvbhnlzhi .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; } #apvbhnlzhi .gt_first_grand_summary_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; } #apvbhnlzhi .gt_striped { background-color: rgba(128, 128, 128, 0.05); } #apvbhnlzhi .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; } #apvbhnlzhi .gt_footnotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; } #apvbhnlzhi .gt_footnote { margin: 0px; font-size: 90%; padding: 4px; } #apvbhnlzhi .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; } #apvbhnlzhi .gt_sourcenote { font-size: 90%; padding: 4px; } #apvbhnlzhi .gt_left { text-align: left; } #apvbhnlzhi .gt_center { text-align: center; } #apvbhnlzhi .gt_right { text-align: right; font-variant-numeric: tabular-nums; } #apvbhnlzhi .gt_font_normal { font-weight: normal; } #apvbhnlzhi .gt_font_bold { font-weight: bold; } #apvbhnlzhi .gt_font_italic { font-style: italic; } #apvbhnlzhi .gt_super { font-size: 65%; } #apvbhnlzhi .gt_footnote_marks { font-style: italic; font-size: 65%; } </style>tbl_summary(by=group_sample) %>% add_p()
1
Created on 2021-04-29 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: