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

fct_infreq does not work when strata are present #334

Open
alexflaris opened this issue May 25, 2021 · 0 comments
Open

fct_infreq does not work when strata are present #334

alexflaris opened this issue May 25, 2021 · 0 comments

Comments

@alexflaris
Copy link

Hello,

I am trying to use fct_infreq with strata for tableby and the output is not correct.

Example with mtcars:

library(arsenal)

Table <- tableby( ~ fct_infreq(as.factor(gear)), strata = as.factor(cyl), data = mtcars)

summary(Table)

And the output is:

|as.factor(cyl) |                                | Overall (N=32) |
|:--------------|:-------------------------------|:--------------:|
|4              |**fct_infreq(as.factor(gear))** |                |
|               |&nbsp;&nbsp;&nbsp;3             |    1 (9.1%)    |
|               |&nbsp;&nbsp;&nbsp;4             |   8 (72.7%)    |
|               |&nbsp;&nbsp;&nbsp;5             |   2 (18.2%)    |
|6              |**fct_infreq(as.factor(gear))** |                |
|               |&nbsp;&nbsp;&nbsp;3             |   2 (28.6%)    |
|               |&nbsp;&nbsp;&nbsp;4             |   4 (57.1%)    |
|               |&nbsp;&nbsp;&nbsp;5             |   1 (14.3%)    |
|8              |**fct_infreq(as.factor(gear))** |                |
|               |&nbsp;&nbsp;&nbsp;3             |   12 (85.7%)   |
|               |&nbsp;&nbsp;&nbsp;4             |    0 (0.0%)    |
|               |&nbsp;&nbsp;&nbsp;5             |   2 (14.3%)    |

I would have guessed that the factors would be sorted by frequency within each stratum, so that the final output would have been something like:

stratum 4: 4, 5, 3
stratum 6: 4, 3, 5
stratum 8: 3, 5, 4

Is there something different that needs to be done so that factor levels are sorted within each stratum?

Thank you,
Alex

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

1 participant