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

Passing *.stats options when using summary.tableby or as.data.frame.tableby #357

Open
jwilliman opened this issue Oct 20, 2022 · 2 comments

Comments

@jwilliman
Copy link

Great package thanks :) tableby is my go to creating summary tables of patient characteristics.

I'm using tableby within a function and it isn't clear to me from the documentation whether it is meant to be possible to use *.stats arguments (eg. numeric.stats or cat.stats), from within the summary.tableby or as.data.frame.tableby functions? The documentation seems to imply these arguments will be passed via ... to tableby.control, but I assume they are enacted in the original tableby call and can't be changed? Whereas the stats.labels command does act within the summary function?

It would be helpful to be clearer which tableby.control arguments can only be used in tableby and which can (also) be used in summary.tableby and as.data.frame.tableby, and perhaps flag users when they had used an argument in the wrong function.

Thanks

library(arsenal)
set.seed(100)
## make 3+ categories for response
nsubj <- 90
mdat <- data.frame(Response=sample(c(1,2,3),nsubj, replace=TRUE),
                   Sex=sample(c("Male", "Female"), nsubj,replace=TRUE),
                   Age=round(rnorm(nsubj,mean=40, sd=5)),
                   HtIn=round(rnorm(nsubj,mean=65,sd=5)))

## allow default summaries on RHS variables
out <- tableby(Response ~ Sex + Age + HtIn, data=mdat)

summary(out, numeric.stats = "medianq1q3", stats.labels=c(meansd="Mean-SD", q1q3 = "Q1-Q3"), text=TRUE)
#> 
#> 
#> |           |    1 (N=25)     |    2 (N=31)     |    3 (N=34)     |  Total (N=90)   | p value|
#> |:----------|:---------------:|:---------------:|:---------------:|:---------------:|-------:|
#> |Sex        |                 |                 |                 |                 |   0.232|
#> |-  Female  |   17 (68.0%)    |   14 (45.2%)    |   19 (55.9%)    |   50 (55.6%)    |        |
#> |-  Male    |    8 (32.0%)    |   17 (54.8%)    |   15 (44.1%)    |   40 (44.4%)    |        |
#> |Age        |                 |                 |                 |                 |   0.547|
#> |-  Mean-SD | 40.200 (4.021)  | 40.161 (3.796)  | 39.265 (3.671)  | 39.833 (3.796)  |        |
#> |-  Range   | 29.000 - 48.000 | 33.000 - 51.000 | 30.000 - 48.000 | 29.000 - 51.000 |        |
#> |HtIn       |                 |                 |                 |                 |   0.093|
#> |-  Mean-SD | 63.360 (5.322)  | 66.516 (4.878)  | 65.000 (5.684)  | 65.067 (5.402)  |        |
#> |-  Range   | 52.000 - 78.000 | 57.000 - 78.000 | 50.000 - 79.000 | 50.000 - 79.000 |        |
as.data.frame(out, numeric.stats = "medianq1q3", stats.labels=c(meansd="Mean-SD", q1q3 = "Q1-Q3"))
#>   group.term group.label strata.term variable     term   label variable.type
#> 1   Response    Response                  Sex      Sex     Sex   categorical
#> 2   Response    Response                  Sex countpct  Female   categorical
#> 3   Response    Response                  Sex countpct    Male   categorical
#> 4   Response    Response                  Age      Age     Age       numeric
#> 5   Response    Response                  Age   meansd Mean-SD       numeric
#> 6   Response    Response                  Age    range   Range       numeric
#> 7   Response    Response                 HtIn     HtIn    HtIn       numeric
#> 8   Response    Response                 HtIn   meansd Mean-SD       numeric
#> 9   Response    Response                 HtIn    range   Range       numeric
#>                     1                   2                   3
#> 1                                                            
#> 2              17, 68  14.00000, 45.16129  19.00000, 55.88235
#> 3               8, 32  17.00000, 54.83871  15.00000, 44.11765
#> 4                                                            
#> 5 40.200000, 4.020779 40.161290, 3.795583 39.264706, 3.670594
#> 6              29, 48              33, 51              30, 48
#> 7                                                            
#> 8 63.360000, 5.321967 66.516129, 4.877643 65.000000, 5.683575
#> 9              52, 78              57, 78              50, 79
#>                 Total                       test    p.value
#> 1                     Pearson's Chi-squared test 0.23154962
#> 2  50.00000, 55.55556 Pearson's Chi-squared test 0.23154962
#> 3  40.00000, 44.44444 Pearson's Chi-squared test 0.23154962
#> 4                             Linear Model ANOVA 0.54654036
#> 5 39.833333, 3.796065         Linear Model ANOVA 0.54654036
#> 6              29, 51         Linear Model ANOVA 0.54654036
#> 7                             Linear Model ANOVA 0.09288762
#> 8 65.066667, 5.402455         Linear Model ANOVA 0.09288762
#> 9              50, 79         Linear Model ANOVA 0.09288762

Created on 2022-10-21 by the reprex package (v2.0.1)

@bethatkinson
Copy link
Member

bethatkinson commented Oct 21, 2022 via email

@jwilliman
Copy link
Author

jwilliman commented Nov 1, 2022 via email

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

2 participants