Learn R Programming

finalfit (version 0.8.9)

fit2df: Extract model fit results to dataframe (generic): finalfit model extractors

Description

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.

Usage

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

Run this code
# NOT RUN {
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)")

# glmlist
explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = "mort_5yr"
colon_s %>%
	glmmulti(dependent, explanatory) %>%
	fit2df(estimate_suffix=" (univariable)")

# 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")

# 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))")

# lm
fit = lm(nodes ~  age.factor + sex.factor + obstruct.factor + perfor.factor,
  data=colon_s)
fit %>%
  fit2df(estimate_suffix=" (multivariable)")

# 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")

# coxphlist
explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = "Surv(time, status)"

colon_s %>%
	coxphuni(dependent, explanatory) %>%
	fit2df(estimate_suffix=" (univariable)")

colon_s %>%
	coxphmulti(dependent, explanatory) %>%
	fit2df(estimate_suffix=" (multivariable)")

# coxph
fit = coxph(Surv(time, status) ~ age.factor + sex.factor + obstruct.factor + perfor.factor,
  data = colon_s)

fit %>%
	fit2df(estimate_suffix=" (multivariable)")
# }

Run the code above in your browser using DataLab