fitFixBP {gamlss.util} | R Documentation |
There are two functions here. The functions fitFixBP
allows the fit a univariate regression using
piecewise polynomials with known break points while the function fitFreeKnots
estimates the break points.
fitFixBP(x, y, w = NULL, knots = NULL, degree = 3, fixed = NULL, ...) fitFreeKnots(x, y, w = NULL, knots = NULL, degree = 3, fixed = NULL, trace = 0, ...)
x |
the x variable |
y |
the response variable |
w |
the prior weights |
knots |
the position of the interior knots for fitFixBP or starting values for fitFreeKnots |
degree |
the degree if the piecewise polynomials |
fixed |
this is to be able to fit fixed break points |
trace |
controlling the trace of of optim() |
... |
for extra arguments |
The functions fitFreeKnots()
is loosely based on the curfit.free.knot()
function of package
DierckxSpline of Sundar Dorai-Raj and Spencer Graves.
The functions fitFixBP
and fitFreeKnots
return an object FixBreakPointsReg
and
FreeBreakPointsReg
respectively with the following items:
fitted.values |
the fitted values of the model |
residuals |
the residuals of the model |
df |
the degrees of freedom fitted in the model |
rss |
the residuals sum of squares |
knots |
the knots used in creating the beta-function base |
fixed |
the fixed break points if any |
breakPoints |
the interior (estimated) break points (or knots) |
coef |
the coefficients of the linear part of the model |
degree |
the degree of the piecewise polynomial |
y |
the y variable |
x |
the x variable |
w |
the prior weights |
In predicting from a fitted FixBreakPointsReg
or FreeBreakPointsReg
model there are two choices
to be made:
The first is to create new end-points for all the x-variables including the newdata
. Note that in this case
the range of x could be bigger that the original one if newdata
has values outside the original x range.
The second is to have the old data end-points which were determine with the original range of x.
The second choice is implemented as a default in the predict
method for FixBreakPointsReg
and
FreeBreakPointsReg
objects with the argument old.x.range=TRUE
. Values outside the original x-range
in this case will be the determined by the global polynomial fitted to data.
If the argument of predict is set to old.x.range=FALSE
the prediction could be possible
better outside the x range but would not coincide with the original predictions i.e. fitted(model)
since the Beta-spline base has changed.
Mikis Stasinopoulos d.stasinopoulos@londonmet.ac.uk
Dierckx, P. (1991) Curve and Surface Fitting with Splines, Oxford Science Publications
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, http://www.jstatsoft.org/v23/i07.
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.com/)
# creating a linear + linear function x <- seq(0,10, length.out=201) knot <- 5 set.seed(12543) mu <- ifelse(x<=knot,5+0.5*x,5+0.5*x+(x-knot)) y <- rNO(201, mu=mu, sigma=.5) # plot the data plot(y~x, xlim=c(-1,13), ylim=c(3,17)) # fit model using fixed break points m1 <- fitFixBP(x, y, knots=5, degree=1) knots(m1) lines(fitted(m1)~x, col="red") m2 <- fitFreeKnots(x, y, knots=5, degree=1) knots(m2) lines(fitted(m2)~x, col="green", lwd=3) points(0:13,predict(m2, newdata=0:13), col="red",pch = 21, bg="blue") points(0:13,predict(m2, newdata=0:13, old.x.range=FALSE), col="red",pch = 21, bg="grey")