Returns predictions and optionally associated quantities (standard errors or confidence intervals) from a fitted stepmented model object.
# S3 method for stepmented
predict(object, newdata, se.fit=FALSE, interval=c("none","confidence", "prediction"),
type = c("link", "response"), na.action=na.omit, level=0.95, .coef=NULL,
.vcov=NULL, apprx.fit=c("none","cdf"), apprx.se=c("cdf","none"), ...)
predict.stepmented
produces a vector of predictions with possibly associated standard errors or confidence intervals.
See predict.lm
, predict.glm
, or predict.segmented
.
a fitted stepmented model coming from stepmented.lm
or stepmented.glm
.
An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.
Logical. Should the standard errors be returned?
Which interval? See predict.lm
Predictions on the link or response scale? Only if object
is a stepmented glm.
How to deal with missing data, if newdata
include them.
The confidence level.
The regression parameter estimates. If unspecified (i.e. NULL
), it is computed internally by coef()
.
The estimate covariance matrix. If unspecified (i.e. NULL
), it is computed internally by vcov.stepmented()
.
The approximation of the \((x>\hat\psi)\) used to compute the predictions/fitted values of the piece-wise relationships.
The same abovementioned approximation to compute the standard error.
further arguments, for instance k
to be passed to vcov.stepmented
.
Vito Muggeo
For stepmented glm fits with offset obtained starting from the model glm(.., offset=..)
, predict.stepmented
returns the fitted values without considering the offset.
Basically predict.stepmented
builds the right design matrix accounting for breakpoint and passes it
to predict.lm
or predict.glm
depending on the actual model fit object
.
stepmented
, plot.stepmented
, 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
Run the code above in your browser using DataLab