ff_merge: Merge a 'summary_factorlist()' table with any number of model...

Description Usage Arguments Value See Also Examples

View source: R/ff_merge.R

Description

A function that takes the output from summary_factorlist(..., fit_id=TRUE) and merges with any number of model dataframes, usually produced with a model wrapper followed by the fit2df() function (see examples).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
ff_merge(
  factorlist,
  fit2df_df,
  ref_symbol = "-",
  estimate_name = NULL,
  last_merge = FALSE
)

finalfit_merge(
  factorlist,
  fit2df_df,
  ref_symbol = "-",
  estimate_name = NULL,
  last_merge = FALSE
)

Arguments

factorlist

Output from summary_factorlist(..., fit_id=TRUE).

fit2df_df

Output from model wrappers followed by fit2df().

ref_symbol

Reference symbol for model reference levels, typically "-" or "1.0".

estimate_name

If you have chosen a new 'estimate name' (e.g. "Odds ratio") when running a model wrapper (e.g. 'glmuni'), then you need to pass this new name to 'finalfit_merge' to generate correct table. Defaults to OR/HR/Coefficient

last_merge

Logical. Set to try for the final merge in a series to remove index and fit_id columns.

Value

Returns a dataframe of combined tables.

See Also

summary_factorlist fit2df

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
library(finalfit)
library(dplyr)

data(colon_s)
explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
explanatory_multi = c("age.factor", "obstruct.factor")
random_effect = "hospital"
dependent = "mort_5yr"

# Create separate tables
colon_s %>%
 summary_factorlist(dependent, explanatory, fit_id=TRUE) -> example.summary

colon_s %>%
 glmuni(dependent, explanatory) %>%
 fit2df(estimate_suffix=" (univariable)") -> example.univariable

colon_s %>%
 glmmulti(dependent, explanatory) %>%
 fit2df(estimate_suffix=" (multivariable)") -> example.multivariable

colon_s %>%
 glmmixed(dependent, explanatory, random_effect) %>%
 fit2df(estimate_suffix=" (multilevel)") -> example.multilevel

# Pipe together
example.summary %>%
 ff_merge(example.univariable) %>%
 ff_merge(example.multivariable) %>%
 ff_merge(example.multilevel, last_merge = TRUE)

# Using finalfit()
colon_s %>%
 finalfit(dependent, explanatory, keep_fit_id = TRUE) %>%
 ff_merge(example.multilevel, last_merge = TRUE)

Example output

Attaching package:dplyrThe following objects are masked frompackage:stats:

    filter, lag

The following objects are masked frompackage:base:

    intersect, setdiff, setequal, union

Note: dependent includes missing data. These are dropped.
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
        label      levels      Alive       Died          OR (univariable)
1         Age   <40 years   31 (6.1)   36 (8.9)                         -
2             40-59 years 208 (40.7) 131 (32.4) 0.54 (0.32-0.92, p=0.023)
3               60+ years 272 (53.2) 237 (58.7) 0.75 (0.45-1.25, p=0.270)
8         Sex      Female 243 (47.6) 194 (48.0)                         -
9                    Male 268 (52.4) 210 (52.0) 0.98 (0.76-1.27, p=0.889)
4 Obstruction          No 408 (82.1) 312 (78.6)                         -
5                     Yes  89 (17.9)  85 (21.4) 1.25 (0.90-1.74, p=0.189)
6 Perforation          No 497 (97.3) 391 (96.8)                         -
7                     Yes   14 (2.7)   13 (3.2) 1.18 (0.54-2.55, p=0.672)
         OR (multivariable)           OR (multilevel)
1                         -                         -
2 0.57 (0.34-0.98, p=0.041) 0.75 (0.39-1.44, p=0.382)
3 0.81 (0.48-1.36, p=0.426) 1.03 (0.55-1.96, p=0.916)
8                         -                         -
9 0.98 (0.75-1.28, p=0.902) 0.80 (0.58-1.11, p=0.180)
4                         -                         -
5 1.25 (0.90-1.76, p=0.186) 1.23 (0.82-1.83, p=0.320)
6                         -                         -
7 1.12 (0.51-2.44, p=0.770) 1.03 (0.43-2.51, p=0.940)
Note: dependent includes missing data. These are dropped.
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
Waiting for profiling to be done...
  Dependent: Mortality 5 year                  Alive       Died
1                         Age   <40 years  31 (46.3)  36 (53.7)
2                             40-59 years 208 (61.4) 131 (38.6)
3                               60+ years 272 (53.4) 237 (46.6)
8                         Sex      Female 243 (55.6) 194 (44.4)
9                                    Male 268 (56.1) 210 (43.9)
4                 Obstruction          No 408 (56.7) 312 (43.3)
5                                     Yes  89 (51.1)  85 (48.9)
6                 Perforation          No 497 (56.0) 391 (44.0)
7                                     Yes  14 (51.9)  13 (48.1)
           OR (univariable)        OR (multivariable)           OR (multilevel)
1                         -                         -                         -
2 0.54 (0.32-0.92, p=0.023) 0.57 (0.34-0.98, p=0.041) 0.75 (0.39-1.44, p=0.382)
3 0.75 (0.45-1.25, p=0.270) 0.81 (0.48-1.36, p=0.426) 1.03 (0.55-1.96, p=0.916)
8                         -                         -                         -
9 0.98 (0.76-1.27, p=0.889) 0.98 (0.75-1.28, p=0.902) 0.80 (0.58-1.11, p=0.180)
4                         -                         -                         -
5 1.25 (0.90-1.74, p=0.189) 1.25 (0.90-1.76, p=0.186) 1.23 (0.82-1.83, p=0.320)
6                         -                         -                         -
7 1.18 (0.54-2.55, p=0.672) 1.12 (0.51-2.44, p=0.770) 1.03 (0.43-2.51, p=0.940)

finalfit documentation built on June 11, 2021, 5:17 p.m.