bfp generate a power polynomial basis matrix which (for given powers) can be used to fit power polynomials in one x-variable.
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+b1*x^p1+b2*x^p2., where p1 and p2
have arbitrary values rather restricted as in the
1 2 3
the explanatory variable to be used in functions
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
bfp() the function can be used to fit power polynomials
in the same way as the functions
splines) are used to fit orthogonal or piecewise
fp(), which is working as a smoother in
gamlss, is used to fit the best fractional polynomials within a set of power values.
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.
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.
bfp returns a matrix to be used as part of the design matrix in the fitting.
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
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?
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/).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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")
Loading required package: splines Loading required package: gamlss.data 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 http://www.gamlss.org/ 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 [] Call: lm(formula = y ~ x.fp, weights = w) Coefficients: (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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.