bfp: Functions to fit fractional polynomials in GAMLSS

Description Usage Arguments Details Value Warning Author(s) References See Also Examples

View source: R/fracpoly.R


The function bfp generate a power polynomial basis matrix which (for given powers) can be used to fit power polynomials in one x-variable. The function fp takes a vector and returns it with several attributes. The vector is used in the construction of the model matrix. The function fp() is not used for fitting the fractional polynomial curves but assigns the attributes to the vector to aid gamlss in the fitting process. The function doing the fitting is gamlss.fp() which is used at the backfitting function (but never used on its own). The (experimental) function pp can be use to fit power polynomials as in a+b1*x^p1+b2*x^p2., where p1 and p2 have arbitrary values rather restricted as in the fp function.


bfp(x, powers = c(1, 2), shift = NULL, scale = NULL)
fp(x, npoly = 2, shift = NULL, scale = NULL)
pp(x, start = list(), shift = NULL, scale = NULL)



the explanatory variable to be used in functions bfp() or fp(). Note that this is different from the argument x use in gamlss.fp (a function used in the backfitting but not by straight by the user)


a vector containing as elements the powers in which the x has to be raised


a number for shifting the x-variable. The default values is zero, if x is positive, or the minimum of the positive difference in x minus the minimum of x


a positive number for scalling the x-variable. The default values is 10^(sign(log10(range)))*trunc(abs(log10(range)))


a positive indicating how many fractional polynomials should be considered in the fit. Can take the values 1, 2 or 3 with 2 as default


a list containing the starting values for the non-linear maximization to find the powers. The results from fitting the equivalent fractional polynomials can be used here


The above functions are an implementation of the fractional polynomials introduced by Royston and Altman (1994). The three functions involved in the fitting are loosely based on the fractional polynomials implementation in S-plus written by Gareth Amber in 1999, (unfortunately the URL link for his work no longer exist). The function bfp generates the right design matrix for the fitting a power polynomial of the type a+b1*x^p1+b2*x^p2+...+bk*x^pk. For given powers p1,p2,...,pk given as the argument powers in bfp() the function can be used to fit power polynomials in the same way as the functions poly() or bs() (of package splines) are used to fit orthogonal or piecewise polynomials respectively. The function fp(), which is working as a smoother in gamlss, is used to fit the best fractional polynomials within a set of power values. Its argument npoly determines whether one, two or three fractional polynomials should used in the fitting. For a fixed number npoly the algorithm looks for the best fitting fractional polynomials in the list c(-2, -1, -0.5, 0, 0.5, 1, 2, 3) . Note that npolu=3 is rather slow since it fits all possible combinations 3-way combinations at each backfitting interaction. The function gamlss.fp() is an internal function of GAMLSS allowing the fractional polynomials to be fitted in the backfitting cycle of gamlss, and should be not used on its own.


The function bfp returns a matrix to be used as part of the design matrix in the fitting.

The function fp returns a vector with values zero to be included in the design matrix but with attributes useful in the fitting of the fractional polynomials algorithm in gamlss.fp.


Since the model constant is included in both the design matrix X and in the backfitting part of fractional polynomials, its values is wrongly given in the summary. Its true values is the model constant minus the constant from the fractional polynomial fitting ??? What happens if more that one fractional polynomials are fitted?


Mikis Stasinopoulos, Bob Rigby


Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion), Appl. Statist., 54, part 3, pp 507-554.

Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019) Distributions for modeling location, scale, and shape: Using GAMLSS in R, Chapman and Hall/CRC. An older version can be found in

Royston, P. and Altman, D. G., (1994). Regression using fractional polynomials of continuous covariates: parsimonious parametric modelling (with discussion), Appl. Statist., 43, 429-467.

Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007,

Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017) Flexible Regression and Smoothing: Using GAMLSS in R, Chapman and Hall/CRC.

(see also

See Also



#fits polynomials with power 1 and .5 
# fit the best of one fractional polynomial
# fit the best of two fractional polynomials
# fit the best of three fractional polynomials
# get the coefficient for the second model 
# now power polynomials using the best 2 fp c()
 m4 <- gamlss(y ~ pp(x, c(1,3)), data = abdom)
# This is not good idea in this case because
# if you look at the fitted values you see what it went wrong

Example output

Loading required package: splines
Loading required package:
Loading required package: gamlss.dist
Loading required package: MASS
Loading required package: nlme
Loading required package: parallel
 **********   GAMLSS Version 5.0-2  ********** 
For more on GAMLSS look at
Type gamlssNews() to see new features/changes/bug fixes.

GAMLSS-RS iteration 1: Global Deviance = 4948.285 
GAMLSS-RS iteration 2: Global Deviance = 4948.285 
GAMLSS-RS iteration 1: Global Deviance = 4967.042 
GAMLSS-RS iteration 2: Global Deviance = 4967.042 
GAMLSS-RS iteration 1: Global Deviance = 4941.099 
GAMLSS-RS iteration 2: Global Deviance = 4941.099 
GAMLSS-RS iteration 1: Global Deviance = 4933.937 
GAMLSS-RS iteration 2: Global Deviance = 4933.937 

lm(formula = y ~ x.fp, weights = w)

(Intercept)        x.fp1        x.fp2  
  -314.2734     123.1273      -0.8205  

GAMLSS-RS iteration 1: Global Deviance = 4924.698 
GAMLSS-RS iteration 2: Global Deviance = 4924.698 

gamlss documentation built on March 31, 2021, 5:10 p.m.