Plot method for segmented objects
Takes a fitted segmented
object returned by segmented()
and plots (or adds)
the fitted broken-line for the selected segmented term.
## S3 method for class 'segmented' plot(x, term, add=FALSE, res=FALSE, conf.level=0, interc=TRUE, link=TRUE, res.col=1, rev.sgn=FALSE, const=0, shade=FALSE, rug=!add, dens.rug=FALSE, dens.col = grey(0.8), transf=I, isV=FALSE, is=FALSE, var.diff=FALSE, p.df="p", .vcov=NULL, .coef=NULL, prev.trend=FALSE, smoos=NULL, ...)
x |
a fitted |
term |
the segmented variable having the piece-wise relationship to be plotted.
If there is a single segmented variable in the fitted model |
add |
when |
res |
when |
conf.level |
If greater than zero, it means the confidence level at which the pointwise confidence itervals have to be plotted. |
interc |
If |
link |
when |
res.col |
when |
rev.sgn |
when |
const |
constant to add to each fitted segmented relationship (on the scale of the linear predictor) before plotting. |
shade |
if |
rug |
when |
dens.rug |
when |
dens.col |
if |
transf |
A possible function to convert the fitted values before plotting. It is only effective
if |
isV |
logical value (to be passed to |
is |
logical value (to be passed to |
var.diff |
logical value to be passed to |
p.df |
degrees of freedom when |
.vcov |
The full covariance matrix of estimates to be used when |
.coef |
The regression parameter estimates. If unspecified (i.e. |
prev.trend |
logical. If |
smoos |
logical, indicating if the residuals (provided that |
... |
other graphics parameters to pass to plotting commands: ‘col’, ‘lwd’ and ‘lty’ (that
can be vectors and are recycled if necessary, see the example below) for the fitted piecewise lines; ‘ylab’, ‘xlab’, ‘main’, ‘sub’, ‘cex.axis’, ‘cex.lab’, ‘xlim’ and
‘ylim’ when a new plot is produced (i.e. when |
Produces (or adds to the current device) the fitted segmented relationship between the
response and the selected term
. If the fitted model includes just a single ‘segmented’ variable,
term
may be omitted.
The partial residuals are computed as ‘fitted + residuals’, where ‘fitted’ are the fitted values of the
segmented relationship relevant to the covariate specified in term
.
Notice that for GLMs the residuals are the response residuals if link=FALSE
and
the working residuals if link=TRUE
.
None.
For models with offset, partial residuals on the response scale are not defined. Thus plot.segmented
does not work
when link=FALSE
, res=TRUE
, and the fitted model includes an offset.
Vito M. R. Muggeo
segmented
to fit the model, lines.segmented
to add the estimated breakpoints on the current plot.
points.segmented
to add the joinpoints of the segmented relationship.
predict.segmented
to compute standard errors and confidence intervals for predictions from a
"segmented" fit.
set.seed(1234) z<-runif(100) y<-rpois(100,exp(2+1.8*pmax(z-.6,0))) o<-glm(y~z,family=poisson) o.seg<-segmented(o) #single segmented covariate and one breakpoint: 'seg.Z' and 'psi' can be omitted par(mfrow=c(1,2)) plot(o.seg, conf.level=0.95, shade=TRUE) points(o.seg, link=TRUE, col=2) ## new plot plot(z,y) ## add the fitted lines using different colors and styles.. plot(o.seg,add=TRUE,link=FALSE,lwd=2,col=2:3, lty=c(1,3)) lines(o.seg,col=2,pch=19,bottom=FALSE,lwd=2) #for the CI for the breakpoint points(o.seg,col=4, link=FALSE) ## using the options 'is', 'isV', 'shade' and 'col.shade'. par(mfrow=c(1,2)) plot(o.seg, conf.level=.9, is=TRUE, isV=TRUE, col=1, shade = TRUE, col.shade=2) plot(o.seg, conf.level=.9, is=TRUE, isV=FALSE, col=2, shade = TRUE, res=TRUE, res.col=4, pch=3)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.