Comments (4)
Thanks for this.
This is a pivoted stratified table. So stratify in the normal manner and then pivot.
You will need library(gt)
or similar to sort your final formatting, but finalfit
will give you all the numbers you need.
Something like this.
If this was useful to people it could be wrapped into a neat function.
All you should need to do is change the explanatory, dependent and split variable names.
Let me know if you have issues.
library(finalfit)
library(tidyverse)
# Table rows
explanatory = c("obstruct.factor", "perfor.factor")
# Table columns
dependent = "rx.factor"
split = c("sex.factor", "age.factor")
# Piped function to generate stratified crosstabs table
colon_s %>%
group_by(!!! syms(split)) %>%
group_modify(~ summary_factorlist(.x, dependent, explanatory)) %>%
mutate(label = na_if(label, "")) %>%
fill(label) %>%
pivot_wider(names_from = split,
values_from = colon_s %>% pull(dependent) %>% levels()) %>%
mutate(label = rm_duplicates(label)) %>%
as.data.frame()
label levels Obs_Female_<40 years Obs_Female_40-59 years Obs_Female_60+ years Obs_Male_<40 years Obs_Male_40-59 years
1 Obstruction No 8 (66.7) 50 (80.6) 57 (79.2) 7 (58.3) 51 (83.6)
2 Yes 4 (33.3) 12 (19.4) 15 (20.8) 5 (41.7) 10 (16.4)
3 Perforation No 12 (100.0) 60 (95.2) 73 (98.6) 12 (92.3) 60 (98.4)
4 Yes 0 (0.0) 3 (4.8) 1 (1.4) 1 (7.7) 1 (1.6)
Obs_Male_60+ years Lev_Female_<40 years Lev_Female_40-59 years Lev_Female_60+ years Lev_Male_<40 years Lev_Male_40-59 years
1 75 (83.3) 9 (90.0) 35 (71.4) 59 (81.9) 7 (77.8) 45 (70.3)
2 15 (16.7) 1 (10.0) 14 (28.6) 13 (18.1) 2 (22.2) 19 (29.7)
3 89 (96.7) 10 (100.0) 48 (96.0) 70 (95.9) 8 (88.9) 63 (96.9)
4 3 (3.3) 0 (0.0) 2 (4.0) 3 (4.1) 1 (11.1) 2 (3.1)
Lev_Male_60+ years Lev+5FU_Female_<40 years Lev+5FU_Female_40-59 years Lev+5FU_Female_60+ years Lev+5FU_Male_<40 years
1 88 (87.1) 9 (56.2) 43 (81.1) 76 (83.5) 9 (90.0)
2 13 (12.9) 7 (43.8) 10 (18.9) 15 (16.5) 1 (10.0)
3 101 (98.1) 16 (100.0) 52 (98.1) 91 (96.8) 10 (100.0)
4 2 (1.9) 0 (0.0) 1 (1.9) 3 (3.2) 0 (0.0)
Lev+5FU_Male_40-59 years Lev+5FU_Male_60+ years
1 41 (85.4) 63 (82.9)
2 7 (14.6) 13 (17.1)
3 51 (98.1) 76 (96.2)
4 1 (1.9) 3 (3.8)
from finalfit.
thanx! that solved the problem
from finalfit.
Actually, I have another question: can I get weighted frequencies for this table?
from finalfit.
See this discussion
#13
from finalfit.
Related Issues (20)
- finalfit does not show median, only mean HOT 1
- inverse OR in finalfit in R continuation closed event
- Fine-gray model visualization HOT 2
- Extending cont_cut to or_plot HOT 1
- Adjust axes for coef plots? HOT 1
- Multinomial Logistic Regression HOT 4
- About modifying the hr_plot function HOT 3
- Error with or_plot HOT 2
- `fct_explicit_na()` was deprecated in forcats 1.0.0 HOT 1
- missing_compare - discrepancy in the manual (Kruskal-Wallis) HOT 1
- `Namespace in Imports field not imported from: ‘tidyselect’` HOT 1
- The output from the stratified models example does not align with the results of the stratified Cox model. HOT 4
- Table format of the finalfit output only gives HTML format script HOT 4
- Potential bugs finalfit command HOT 1
- Finalfit package: Descriptive statistics query for p values and getting Median as statistics HOT 1
- p>0.05, but 95% confidence interval for the odds ratio DOES NOT include 1. How can I check and standardise the methods used to calculate the p-values and confidence intervals? HOT 2
- ff_remove_ref for summaryfactorlist HOT 4
- finalfit results in table with "Coefficient" instead of "OR" HOT 3
- ff_plot with interaction HOT 2
- Feature Request: Random effect in univariable models HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from finalfit.