Package: mfp2 1.0.2

Edwin Kipruto

mfp2: Multivariable Fractional Polynomial Models with Extensions

Multivariable fractional polynomial algorithm simultaneously selects variables and functional forms in both generalized linear models and Cox proportional hazard models. Key references are Royston and Altman (1994) <doi:10.2307/2986270> and Royston and Sauerbrei (2008, ISBN:978-0-470-02842-1). In addition, the implementation can model semi-continuous covariates with a “spike at zero” using a two-stage selection procedure. This extension follows the framework proposed by Becher et al. (2012) <doi:10.1002/bimj.201100263>. The package also includes the approximate cumulative distribution (ACD) transformation to model a sigmoid relationship between variable x and an outcome variable y, as described in Royston (2014) <doi:10.1177/1536867X1401400206> and Royston and Sauerbrei (2016) <doi:10.1177/1536867X1601600>. This feature distinguishes it from a standard fractional polynomial function, which lacks the ability to achieve such modeling.

Authors:Edwin Kipruto [aut, cre], Michael Kammer [aut], Patrick Royston [aut], Willi Sauerbrei [aut]

mfp2_1.0.2.tar.gz
mfp2_1.0.2.zip(r-4.7)mfp2_1.0.2.zip(r-4.6)mfp2_1.0.2.zip(r-4.5)
mfp2_1.0.2.tgz(r-4.6-any)mfp2_1.0.2.tgz(r-4.5-any)
mfp2_1.0.2.tar.gz(r-4.7-any)mfp2_1.0.2.tar.gz(r-4.6-any)
mfp2_1.0.2.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
mfp2/json (API)

# Install 'mfp2' in R:
install.packages('mfp2', repos = c('https://edwinkipruto.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/edwinkipruto/mfp2/issues

Datasets:
  • art - Artificial dataset with continuous response
  • gbsg - Breast cancer dataset used in the Royston and Sauerbrei (2008) book.
  • pima - Pima Indians dataset used in the Royston and Sauerbrei (2008) book.
  • prostate - Prostate cancer dataset used in the Royston and Sauerbrei (2008) book.

On CRAN:

Conda:

6.77 score 3 stars 3 packages 10 scripts 591 downloads 18 exports 20 dependencies

Last updated from:1bf3e78b3c. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK168
source / vignettesOK199
linux-release-x86_64OK165
macos-release-arm64OK211
macos-oldrel-arm64OK225
windows-develOK130
windows-releaseOK115
windows-oldrelOK138
wasm-releaseOK114

Exports:apply_shift_scaleassign_dfcenter_matrixcontr.cumulativecreate_dummy_variablesfind_scale_factorfind_shift_factorfit_acdfpfp2fracplotgenerate_powers_acdgenerate_powers_fpget_selected_variable_namesmfp2transform_matrixtransform_vector_acdtransform_vector_fp

Dependencies:clicpp11farverggplot2gluegtableisobandlabelinglatticelifecycleMatrixR6RColorBrewerrlangS7scalessurvivalvctrsviridisLitewithr

Multivariable Fractional Polynomials with Spike at Zero
Two-Stage Model Selection Procedure | Example: Simulation of Spike-at-Zero Data | Simulation of Spike-at-Zero (SAZ) Data | Fractional Polynomial Analysis with SAZ | References

Last update: 2026-02-18
Started: 2026-02-18

Multivariable Fractional Polynomials with Extensions
Introduction to Multivariable Fractional Polynomials (MFP) | Overview of MFP | Fractional polynomial models for a continuous variable | Function selection procedure (FSP) | MFP procedure | MFP -- Key issues and approaches to handling them | The variable has to be positive | Sample size and influential observations | Lack of fit | Local features | Introduction to the mfp2 package | Estimation algorithm | Installation | Linear regression | Fitting MFP models using the matrix and formula interfaces | Shifting and scaling of covariates | Setting degrees of freedom for each variable | Tuning parameters for MFP | Nominal significance levels | Information criteria | Model comparison tests | Subject matter knowledge may require changes in fractional polynomial powers | Explanation of output from model-selection algorithm | Methods defined for mfp2 | Graphical presentation of FP functions | Handling categorical variables | Logistic regression | Survival data | Stratified Cox model | MFP with ACD transformation | Modeling a sigmoid relationship | Spike-at-Zero Modeling with Positive-Only FP Transformation | Two-Stage Model Selection Procedure | Example: Simulation of Spike-at-Zero Data | Simulation of Spike-at-Zero (SAZ) Data | Fractional Polynomial Analysis with SAZ | References

Last update: 2025-10-10
Started: 2023-06-16

Readme and manuals

Help Manual

Help pageTopics
Function to apply Approximate Cumulative Distribution (ACD)apply_acd
Shift and scale vector xapply_shift_scale
Artificial dataset with continuous responseart
Helper to assign degrees of freedomassign_df
Backscale Columns of a Matrix (Internal)backscale_matrix
Function to compute F-statistic and p-value from deviancescalculate_f_test
Function to calculate p-values for likelihood-ratio testcalculate_lr_test
Function to compute model metrics to be used within 'mfp2'calculate_model_metrics
Calculates the total number of fractional polynomial powers in adjustment variables.calculate_number_fp_powers
Helper function to compute standard error of a partial predictorcalculate_standard_error
Simple function to center datacenter_matrix
Extract coefficients from object of class 'mfp2'coef.mfp2
Cumulative (Threshold) Contrast Coding for Ordered Factorscontr.cumulative
Helper to convert a nested list with same or different length into a matrixconvert_powers_list_to_matrix
Simple function to create dummy variables for ordinal and nominal variablescreate_dummy_variables
Helper to create overview table of fp termscreate_fp_terms
Deviance computations as used in mfp in statadeviance_gaussian
Helper function to ensure vectors have a specified lengthensure_length
Helper to run cycles of the mfp algorithmfind_best_fp_cycle
Function to estimate the best FP functions for a single variablefind_best_fp_step
Function to fit univariable FP1 models for acd transformationfind_best_fp1_for_acd
Function to find the best FP functions of given degree for a single variablefind_best_fpm_step
Function that calculates an integer used to scale predictorfind_scale_factor
Function that calculates a value used to shift predictorfind_shift_factor
Function to estimate approximate cumulative distribution (ACD)fit_acd
Function that fits Cox proportional hazards modelsfit_cox
Function that fits generalized linear modelsfit_glm
Function to fit linear model for variable of interestfit_linear_step
Function that fits models supported by 'mfp2'fit_model
Function to fit a null model excluding variable of interestfit_null_step
Helper to assign attributes to a variable undergoing FP-transformationfp fp2
Plot response functions from a fitted 'mfp2' objectfracplot plot_mfp
Breast cancer dataset used in the Royston and Sauerbrei (2008) book.gbsg
Helper function to generate combinations with replacementgenerate_combinations_with_replacement
Function that generates a matrix of FP powers for any degreegenerate_powers_acd generate_powers_fp
Function to generate all requested FP transformations for a single variablegenerate_transformations_acd generate_transformations_fp
Helper function to extract selected variables from fitted 'mfp2' objectget_selected_variable_names
Multivariable Fractional Polynomial Models with Extensionsmfp2 mfp2.default mfp2.formula
Helper function to name transformed variablesname_transformed_variables
Helper to order variables for mfp2 algorithmorder_variables order_variables_by_significance
Pima Indians dataset used in the Royston and Sauerbrei (2008) book.pima
Predict Method for 'mfp2'predict.mfp2
Helper function to prepare newdata for predict functionprepare_newdata_for_predict
Verbose printing of the function selection procedure (FSP)print_mfp_ic_step print_mfp_pvalue_step print_mfp_step
Print method for objects of class 'mfp2'print.mfp2
Prostate cancer dataset used in the Royston and Sauerbrei (2008) book.prostate
Helper to reset acd transformation for variables with few valuesreset_acd
Function selection procedure based on information criteriaselect_ic select_ic_acd
Helper function to select between null and linear term for a single variableselect_linear
Function selection procedure based on closed testing procedureselect_ra2
Function selection procedure for ACD based on closed testing procedureselect_ra2_acd
Summarizing 'mfp2' model fitssummary.mfp2
Transform each column of matrix using final FP powers or ACD transformationtransform_matrix
Functions to transform a variable using fractional polynomial powers or acdtransform_vector_acd transform_vector_fp
Simple function to transform vector by a single powertransform_vector_power