Predict method for segmented model fits
predict.segmented.RdReturns predictions and optionally associated quantities (standard errors or confidence intervals) from a fitted segmented model object.
Arguments
- object
a fitted segmented model coming from
segmented.(g)lmorsegreg.- newdata
An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.
- se.fit
Logical. Should the standard errors be returned?
- interval
Which interval? See
predict.lm- type
Predictions on the link or response scale? Only if
objectis a segmented glm.- na.action
How to deal with missing data, if
newdatainclude them.- level
The confidence level.
- .coef
The regression parameter estimates. If unspecified (i.e.
NULL), it is computed internally bycoef().- ...
further arguments.
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.
Warning
For segmented glm fits with offset, predict.segmented returns the fitted values including the offset.
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
#> 1 2 3 4 5 6 7
#> 0.12154843 0.07957213 0.07957213 0.12154843 0.10514462 0.07893808 0.06179915
#> 8 9 10
#> 0.06179915 0.07893808 0.10514462
#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
#> [1] 0.10212152 0.07366948 0.05650195 0.06102983 0.08380529 0.06359044
#> [7] 0.05260029 0.05650192 0.07294363 0.09566456