Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predict.segmented

Predict method for segmented model fits


Description

Returns predictions and optionally associated quantities (standard errors or confidence intervals) from a fitted segmented model object.

Usage

## S3 method for class 'segmented'
predict(object, newdata, .coef=NULL, ...)

Arguments

object

a fitted segmented model coming from segmented.lm or segmented.glm.

newdata

An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

.coef

The regression parameter estimates. If unspecified (i.e. NULL), it is computed internally by coef().

...

further arguments passed to predict.lm or predict.glm. Usually these are se.fit, or interval or type.

Details

Basically predict.segmented builds the right design matrix accounting for breakpoint and passes it to predict.lm or predict.glm depending on the actual model fit object.

Value

predict.segmented produces a vector of predictions with possibly associated standard errors or confidence intervals. See predict.lm or predict.glm.

Note

If type="terms", predict.segmented returns predictions for each component of the segmented term. Namely if ‘my.x’ is the segmented variable, predictions for ‘my.x’, ‘U1.my.x’ and ‘psi1.my.x’ are returned. These are meaningless individually, however their sum provides the predictions for the segmented term.

Author(s)

Vito Muggeo

See Also

Examples

n=10
x=seq(-3,3,l=n)
set.seed(1515)
y <- (x<0)*x/2 + 1 + rnorm(x,sd=0.15)
segm <- segmented(lm(y ~ x), ~ x, psi=0.5)
predict(segm,se.fit = TRUE)$se.fit

#wrong (smaller) st.errors (assuming known the breakpoint)
olm<-lm(y~x+pmax(x-segm$psi[,2],0))
predict(olm,se.fit = TRUE)$se.fit

segmented

Regression Models with Break-Points / Change-Points Estimation

v1.3-4
GPL
Authors
Vito M. R. Muggeo [aut, cre] (<https://orcid.org/0000-0002-3386-4054>)
Initial release
2021-04-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.