Takes output from finalfit model wrappers and extracts to a dataframe, convenient for further processing in preparation for final results table.

fit2df.lm is the model extract method for lm.

fit2df.lmlist is the model extract method for lmuni and lmmulti.

fit2df.glm is the model extract method for standard glm models, which have not used finalfit model wrappers.

fit2df.glmboot is the model extract method for glmmulti_boot models.

fit2df.glmlist is the model extract method for glmuni and glmmulti.

fit2df.lmerMod is the model extract method for standard lme4::lmer models and for the finalfit::lmmixed model wrapper.

fit2df.glmerMod is the model extract method for standard lme4::glmer models and for the finalfit::glmmixed model wrapper.

fit2df.coxph is the model extract method for survival::coxph.

fit2df.coxphlist is the model extract method for coxphuni and coxphmulti.

fit2df(...)

# S3 method for lm
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "Coefficient", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_level = 0.95, confint_sep = " to ",
  ...)

# S3 method for lmlist
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "Coefficient", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_level = 0.95, confint_sep = " to ",
  ...)

# S3 method for glm
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "OR", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_type = "profile",
  confint_level = 0.95, confint_sep = "-", ...)

# S3 method for glmboot
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "OR", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_sep = "-", ...)

# S3 method for glmlist
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "OR", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_type = "profile",
  confint_level = 0.95, confint_sep = "-", ...)

# S3 method for lmerMod
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "Coefficient", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_type = "Wald", confint_level = 0.95,
  confint_sep = "-", ...)

# S3 method for glmerMod
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "OR", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_type = "Wald", confint_level = 0.95,
  confint_sep = "-", ...)

# S3 method for coxph
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "HR", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_sep = "-", ...)

# S3 method for coxphlist
fit2df(.data, condense = TRUE, metrics = FALSE,
  remove_intercept = TRUE, explanatory_name = "explanatory",
  estimate_name = "HR", estimate_suffix = "", p_name = "p",
  digits = c(2, 2, 3), confint_sep = "-", ...)

Arguments

...

Other arguments: X: Design matrix from stanfit modelling. Details documented else where.

.data

Output from finalfit model wrappers.

condense

Logical: when true, effect estimates, confidence intervals and p-values are pasted conveniently together in single cell.

metrics

Logical: when true, useful model metrics are extracted.

remove_intercept

Logical: remove the results for the intercept term.

explanatory_name

Name for this column in output

estimate_name

Name for this column in output

estimate_suffix

Appeneded to estimate name

p_name

Name given to p-value estimate

digits

Number of digits to round to (1) estimate, (2) confidence interval limits, (3) p-value.

confint_level

The confidence level required.

confint_sep

String to separate confidence intervals, typically "-" or " to ".

confint_type

One of c("profile", "default") for GLM models (confint.glm) or c("profile", "Wald", "boot") for glmer/lmer models (confint.merMod.). Not implemented for lm, coxph or coxphlist.

Value

A dataframe of model parameters. When metrics=TRUE output is a list of two dataframes, one is model parameters, one is model metrics. length two

Details

fit2df is a generic (S3) function for model extract.

Examples

library(finalfit) library(dplyr) library(survival) # glm fit = glm(mort_5yr ~ age.factor + sex.factor + obstruct.factor + perfor.factor, data=colon_s, family="binomial") fit %>% fit2df(estimate_suffix=" (multivariable)")
#> Waiting for profiling to be done...
#> explanatory OR (multivariable) #> 2 age.factor40-59 years 0.57 (0.34-0.98, p=0.041) #> 3 age.factor60+ years 0.81 (0.48-1.36, p=0.426) #> 4 sex.factorMale 0.98 (0.75-1.28, p=0.902) #> 5 obstruct.factorYes 1.25 (0.90-1.76, p=0.186) #> 6 perfor.factorYes 1.12 (0.51-2.44, p=0.770)
# glmlist explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor") dependent = "mort_5yr" colon_s %>% glmmulti(dependent, explanatory) %>% fit2df(estimate_suffix=" (univariable)")
#> Waiting for profiling to be done...
#> explanatory OR (univariable) #> 2 age.factor40-59 years 0.57 (0.34-0.98, p=0.041) #> 3 age.factor60+ years 0.81 (0.48-1.36, p=0.426) #> 4 sex.factorMale 0.98 (0.75-1.28, p=0.902) #> 5 obstruct.factorYes 1.25 (0.90-1.76, p=0.186) #> 6 perfor.factorYes 1.12 (0.51-2.44, p=0.770)
# glmerMod explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor") random_effect = "hospital" dependent = "mort_5yr" colon_s %>% glmmixed(dependent, explanatory, random_effect) %>% fit2df(estimate_suffix=" (multilevel)")
#> explanatory OR (multilevel) #> 2 age.factor40-59 years 0.75 (0.39-1.44, p=0.382) #> 3 age.factor60+ years 1.03 (0.55-1.96, p=0.916) #> 4 sex.factorMale 0.80 (0.58-1.11, p=0.180) #> 5 obstruct.factorYes 1.23 (0.82-1.83, p=0.320) #> 6 perfor.factorYes 1.03 (0.43-2.51, p=0.940)
# glmboot ## Note number of draws set to 100 just for speed in this example explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor") dependent = "mort_5yr" colon_s %>% glmmulti_boot(dependent, explanatory, R = 100) %>% fit2df(estimate_suffix=" (multivariable (BS CIs))")
#> explanatory OR (multivariable (BS CIs)) #> 2 age.factor40-59 years 0.57 (0.29-0.92, p=0.020) #> 3 age.factor60+ years 0.81 (0.38-1.38, p=0.480) #> 4 sex.factorMale 0.98 (0.76-1.23, p=1.020) #> 5 obstruct.factorYes 1.25 (0.92-1.72, p=0.220) #> 6 perfor.factorYes 1.12 (0.37-2.44, p=0.840)
# lm fit = lm(nodes ~ age.factor + sex.factor + obstruct.factor + perfor.factor, data=colon_s) fit %>% fit2df(estimate_suffix=" (multivariable)")
#> explanatory Coefficient (multivariable) #> 2 age.factor40-59 years -1.21 (-2.16 to -0.26, p=0.012) #> 3 age.factor60+ years -1.25 (-2.18 to -0.33, p=0.008) #> 4 sex.factorMale -0.07 (-0.54 to 0.40, p=0.779) #> 5 obstruct.factorYes -0.31 (-0.91 to 0.29, p=0.313) #> 6 perfor.factorYes 0.28 (-1.09 to 1.66, p=0.686)
# lmerMod explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor") random_effect = "hospital" dependent = "nodes" colon_s %>% lmmixed(dependent, explanatory, random_effect) %>% fit2df(estimate_suffix=" (multilevel")
#> Warning: P-value for lmer is estimate assuming t-distribution is normal. Bootstrap for final publication.
#> explanatory Coefficient (multilevel #> 2 age.factor40-59 years 0.45 (0.19-1.07, p=0.035) #> 3 age.factor60+ years 0.38 (0.16-0.87, p=0.011) #> 4 sex.factorMale 0.83 (0.54-1.27, p=0.195) #> 5 obstruct.factorYes 0.69 (0.40-1.19, p=0.091) #> 6 perfor.factorYes 1.26 (0.36-4.40, p=0.357)
# coxphlist explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor") dependent = "Surv(time, status)" colon_s %>% coxphuni(dependent, explanatory) %>% fit2df(estimate_suffix=" (univariable)")
#> explanatory HR (univariable) #> 1 age.factor40-59 years 0.76 (0.53-1.09, p=0.132) #> 2 age.factor60+ years 0.93 (0.66-1.31, p=0.668) #> 3 sex.factorMale 1.01 (0.84-1.22, p=0.888) #> 4 obstruct.factorYes 1.29 (1.03-1.62, p=0.028) #> 5 perfor.factorYes 1.17 (0.70-1.95, p=0.556)
colon_s %>% coxphmulti(dependent, explanatory) %>% fit2df(estimate_suffix=" (multivariable)")
#> explanatory HR (multivariable) #> 1 age.factor40-59 years 0.79 (0.55-1.13, p=0.196) #> 2 age.factor60+ years 0.98 (0.69-1.40, p=0.926) #> 3 sex.factorMale 1.02 (0.85-1.23, p=0.812) #> 4 obstruct.factorYes 1.30 (1.03-1.64, p=0.026) #> 5 perfor.factorYes 1.08 (0.64-1.81, p=0.785)
# coxph fit = coxph(Surv(time, status) ~ age.factor + sex.factor + obstruct.factor + perfor.factor, data = colon_s) fit %>% fit2df(estimate_suffix=" (multivariable)")
#> explanatory HR (multivariable) #> 1 age.factor40-59 years 0.79 (0.55-1.13, p=0.196) #> 2 age.factor60+ years 0.98 (0.69-1.40, p=0.926) #> 3 sex.factorMale 1.02 (0.85-1.23, p=0.812) #> 4 obstruct.factorYes 1.30 (1.03-1.64, p=0.026) #> 5 perfor.factorYes 1.08 (0.64-1.81, p=0.785)