View source: R/predict.segmented.r
| predict.segmented | R Documentation |
Returns predictions and optionally associated quantities (standard errors or confidence intervals) from a fitted segmented model object.
## S3 method for class 'segmented'
predict(object, newdata, se.fit=FALSE, interval=c("none","confidence", "prediction"),
type = c("link", "response"), na.action=na.omit, level=0.95, .coef=NULL, ...)
object |
a fitted segmented model coming from |
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 |
type |
Predictions on the link or response scale? Only if |
na.action |
How to deal with missing data, if |
level |
The confidence level. |
.coef |
The regression parameter estimates. If unspecified (i.e. |
... |
further arguments. |
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.
predict.segmented produces a vector of predictions with possibly associated standard errors or confidence intervals.
See predict.lm or predict.glm.
For segmented glm fits with offset, predict.segmented returns the fitted values including the offset.
Vito Muggeo
segreg, segmented, plot.segmented, broken.line, predict.lm, predict.glm
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.