Learn R Programming

segmented (version 0.2-3)

plot.segmented: Plot method for segmented objects

Description

Takes a fitted segmented object returned by segmented() and plots (or add) the fitted broken-line for the selected segmented term.

Usage

## S3 method for class 'segmented':
plot(x, term = NULL, se = FALSE, const = coef(x)["(Intercept)"],
  add = FALSE, linkinv = FALSE, h = 300, show.gap=TRUE, ...)

Arguments

x
a fitted segmented object
term
the segmented variable whose piece-wise relationship has to be plotted
se
when TRUE pointwise confidence intervals are drawn. Currently unimplemented.
const
constant to add to each fitted segmented relationship (on the scale of the linear predictor) before plotting
add
when TRUE the fitted lines are added to the current device
linkinv
when TRUE, the fitted lines are (possibly) tranformed on the inverse link scale before plotting
h
graphic parameter to regulate the number of points where the fitted lines have to be computed. See Details
show.gap
should the gap between the fitted lines at the estimated breakpoints to be shown?
...
other graphics parameters to pass on to plotting commands

Value

  • None.

Details

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. Due to the parameterization of the segmented terms, sometimes the fitted lines may not appear to join at the estimated breakpoints. If this is the case, try to increase the value of h; otherwise the apparent `gap' would indicate some lack-of-fit. However such `gap' may be hidden by setting show.gap=FALSE: in this case the new fitted values are re-computed by means of a linear model fit. Note that, as hidding could lead to a wrong impression of the fit, show.gap=TRUE is suggested only when the gap coefficients are nonsignificant.

See Also

point.psi

Examples

Run this code
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,seg.Z=~z,psi=list(z=.5))
par(mfrow=c(1,2))
plot(o.seg)
plot(z,y)
plot(o.seg,add=TRUE,linkinv=TRUE,lwd=2,col=2)
point.psi(o.seg,"z",col=2,pch=19,bottom=FALSE,lwd=2)

Run the code above in your browser using DataLab