Learn R Programming

gamlss.util (version 3.1-0)

fitFixBP: Functions to Fit Univariate Break Point Models

Description

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.

Usage

fitFixBP(x, y, w = NULL, knots = NULL, degree = 3, fixed = NULL, ...)
fitFreeKnots(x, y, w = NULL, knots = NULL, degree = 3, fixed = NULL, 
             trace = 0, ...)

Arguments

Value

The functions fitFixBP and fitFreeKnots return an object FixBreakPointsReg and FreeBreakPointsReg respectively with the following items:fitted.valuesthe fitted values of the modelresidualsthe residuals of the modeldfthe degrees of freedom fitted in the modelrssthe residuals sum of squaresknotsthe knots used in creating the beta-function basefixedthe fixed break points if anybreakPointsthe interior (estimated) break points (or knots)coefthe coefficients of the linear part of the modeldegreethe degree of the piecewise polynomialythe y variablexthe x variablewthe prior weights

Details

The functions fitFreeKnots() is loosely based on the curfit.free.knot() function of package DierckxSpline of Sundar Dorai-Raj and Spencer Graves.

References

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/)

Examples

Run this code
# 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")

Run the code above in your browser using DataLab