Learn R Programming

finalfit

The finalfit package provides functions that help you quickly create elegant final results tables and plots when modelling in R. These can easily be exported as Word documents, PDFs, or html files.

Its design follows Hadley Wickham's tidy tool manifesto.

In addition, it provides functions for identifying and handling missing data, together with a number of functions to bootstrap simulate regression model results.

Installation

You can install finalfit from CRAN:

install.packages("finalfit")

It is recommended that this package is used together with dplyr which can be installed via:

install.packages("dplyr")

Documentation

The package documentation is maintained independently at finalfit.org.

Examples

See Get started and the All tables vignettes for extensive examples.

Crosstable / table 1

# Crosstable 
explanatory = c("age.factor", "sex.factor", "obstruct.factor")
dependent = 'mort_5yr'
colon_s %>%
  summary_factorlist(dependent, explanatory, 
  p=TRUE, add_dependent_label=TRUE) -> t1
knitr::kable(t1, align=c("l", "l", "r", "r", "r"))

Regression table

explanatory = c("age.factor", "sex.factor", 
  "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'
colon_s %>%
  finalfit(dependent, explanatory, metrics=TRUE) -> t2
knitr::kable(t2[[1]], row.names=FALSE, align=c("l", "l", "r", "r", "r", "r"))
knitr::kable(t2[[2]], row.names=FALSE, col.names="")

When exported to PDF:

Regression plots

explanatory = c("age.factor", "sex.factor", 
  "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'
colon_s %>%
  or_plot(dependent, explanatory)

Copy Link

Version

Install

install.packages('finalfit')

Monthly Downloads

3,446

Version

1.0.8

License

MIT + file LICENCE

Issues

Pull Requests

Stars

Forks

Maintainer

Ewen Harrison

Last Published

July 24th, 2024

Functions in finalfit (1.0.8)

ff_glimpse

Descriptive statistics for dataframe
ff_label

Label a variable
ff_expand

Summarise with mode and mean/median and expand given factors
extract_fit

Extract model output to dataframe
ff_formula

Generate formula as character string
condense_fit

Condense model output dataframe for final tables
%$%

magrittr exposition pipe-operator
ff_plot

Produce a table and plot
ff_relabel

Relabel variables in a data frame
colon_s

Chemotherapy for Stage B/C colon cancer
ff_merge

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

Make an interaction variable and add to dataframe
ff_remove_p

Remove p-value from output
ff_relabel_df

Relabel variables from data frame after tidyverse functions
glmmixed

Mixed effects binomial logistic regression models: finalfit model wrapper
glmmulti

Binomial logistic regression multivariable models: finalfit model wrapper
format_n_percent

Format n and percent as a character
ff_percent_only

Include only percentages for factors in summary_factorlist output
missing_pairs

Missing values pairs plot
missing_pattern

Characterise missing data for finalfit models
metrics_hoslem

Hosmer-Lemeshow goodness of fit test
glmmulti_boot

Binomial logistic regression multivariable models with bootstrapped confidence intervals: finalfit model wrapper
missing_compare

Compare missing data
remove_labels

Remove variable labels.
missing_df

Missing values data frame
rm_duplicate_labels

Remove duplicate levels within summary_factorlist: finalfit helper function
missing_predictorMatrix

Create predictorMatrix for use with mice
missing_plot

Missing values occurrence plot
summary_factorlist

Summarise a set of factors (or continuous variables) by a dependent variable
extract_labels

Extract variable labels and names
extract_variable_label

Extract variable labels from dataframe
ff_parse_formula

Parse a formula to finalfit grammar
ff_newdata

Generate newdata for simulations
missing_glimpse

Summary of missing values
ff_stratify_helper

Help making stratified summary_factorlist tables
summary_factorlist_stratified

Summarise a set of factors (or continuous variables) by a dependent variable
finalfit-package

finalfit: Quickly create elegant final results tables and plots when modelling.
or_plot

Produce an odds ratio table and plot
p_tidy

Round p-values but keep trailing zeros
ff_metrics

Generate common metrics for regression model results
dependent_label

Make a label for the dependent variable
error_colon_fct_levels

Errors: colon in factor levels
glmuni

Binomial logistic regression univariable models: finalfit model wrapper
summary_mipo

Call to mice:::summary.mipo
ff_permute

Permuate explanatory variables to produce multiple output tables for common regression models
%>%

Pipe operator
lmmulti

Linear regression multivariable models: finalfit model wrapper
hr_plot

Produce a hazard ratio table and plot
labels_to_column

Labels to column names
plot_title

Label plot title
is.survival

Test character describes survival object
ff_mode

Return the most frequent level in a factor
rm_duplicates

Remove duplicates and replace
surv_plot

Plot survival curves with number-at-risk table
rm_empty_block

Remove rows where all specified variables are missing
lmuni

Linear regression univariable models: finalfit model wrapper
ff_remove_ref

Remove regression reference level row from table
ff_row_totals

Add row totals to summary_factorlist() output
finalfit

Final output tables for common regression models
fit2df

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

Labels to level
round_tidy

Round values but keep trailing zeros
lmmixed

Mixed effects linear regression models: finalfit model wrapper
summary_df

Summarise with mode for factors and mean/median for numeric variables
remove_intercept

Remove intercept from model output
print.data.frame.ff

Print methods for finalfit data frames
svyglmuni

Univariable survey-weighted generalised linear models
svyglmmulti

Multivariable survey-weighted generalised linear models
variable_type

Determine type/class of a variable
wcgs

Western Collaborative Group Study
coxphmulti

Cox proprotional hazards multivariable models: finalfit model wrapper
ff_eval

Eval for `lm` and `glm` model wrappers
coxphuni

Cox proprotional hazards univariable models: finalfit model wrapper
%<>%

magrittr compound assignment pipe-operator
crrmulti

Competing risks multivariable regression: finalfit model wrapper
boot_compare

Compare bootstrapped distributions
catTestfisher

Deprecated catTest from Hmisc for reverse dependencies
crruni

Competing risks univariable regression: finalfit model wrapper
ff_column_totals

Add column totals to summary_factorlist() output
boot_predict

Bootstrap simulation for model prediction
check_recode

Check accurate recoding of variables
coefficient_plot

Produce a coefficient table and plot