bfp | R Documentation |
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
additive.fit
(but never used on its own).
The (experimental) function pp
can be use to fit power polynomials as in a+b_1
x^{p_1}+b_2 x^{p_2}
., 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)
x |
the explanatory variable to be used in functions |
powers |
a vector containing as elements the powers in which the x has to be raised |
shift |
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 |
scale |
a positive number for scaling the x-variable. The default values is
|
npoly |
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 |
start |
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+b_1
x^{p_1}+b_2 x^{p_2}+\ldots+b_k x^p_k
. For given powers
p_1,p_2,\ldots,p_k
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 https://www.gamlss.com/.
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, https://www.jstatsoft.org/v23/i07/.
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 https://www.gamlss.com/).
gamlss
, gamlss.family
data(abdom)
#fits polynomials with power 1 and .5
mod1<-gamlss(y~bfp(x,c(1,0.5)),data=abdom)
# fit the best of one fractional polynomial
m1<-gamlss(y~fp(x,1),data=abdom)
# fit the best of two fractional polynomials
m2<-gamlss(y~fp(x,2),data=abdom)
# fit the best of three fractional polynomials
m3<-gamlss(y~fp(x,3),data=abdom)
# get the coefficient for the second model
m2$mu.coefSmo
# 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
plot(y~x,data=abdom)
lines(fitted(m2,"mu")~abdom$x,col="red")
lines(fitted(m4,"mu")~abdom$x,col="blue")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.