Learn R Programming

finalfit (version 1.0.8)

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

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

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 )

Value

Returns a dataframe of combined tables.

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.

See Also

summary_factorlist fit2df

Examples

Run this code
library(finalfit)
library(dplyr)

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)

Run the code above in your browser using DataLab