segmented(obj, seg.Z, psi, control = seg.control(),
model.frame = TRUE, ...)
## S3 method for class 'lm':
segmented(obj, seg.Z, psi, control = seg.control(),
model.frame = TRUE, ...)
## S3 method for class 'glm':
segmented(obj, seg.Z, psi, control = seg.control(),
model.frame = TRUE, ...)
seg.Z
argument.
Each vector includes starting values for the break-point(s) for the corresponding
variable in seg.Z
. If seg.Z
includesseg.control
for details.last
component returned by seg.control
.
If last=TRUE, the default, segmented returns an object of class "segmented" which inherits
from the class "lm" or "glm" depending on the class of obj
. Otherwise a list is
returned, where the last component is the fitted model at the final iteration,
see seg.control
.
An object of class "segmented" is a list containing the components of the
original object obj
with additionally the followings:psi
argument, must be provided with care. For instance visual
inspection of a, possibly smoothed,
scatter-plot is usually a good way to obtain some idea on breakpoint location.
Moreover it is also advisable to look at the coefficients of the `gap' variables. At the
convergence they should be small or at least, non-significantly different from zero.
summary.segmented
and print.summary.segmented
return
information of the `gap' coefficients.psi
argument, where initial
values for the break-points must be specified. The model
is estimated simultaneously yielding point estimates and relevant approximate
standard errors of all the model parameters, including the break-points.lm
, glm
set.seed(12)
xx<-1:100
zz<-runif(100)
yy<-2+1.5*pmax(xx-35,0)-1.5*pmax(xx-70,0)+15*pmax(zz-.5,0)+rnorm(100,0,2)
dati<-data.frame(x=xx,y=yy,z=zz)
out.lm<-lm(y~x,data=dati)
o<-segmented(out.lm,seg.Z=~x,psi=list(x=c(30,60)),
control=seg.control(display=FALSE))
slope(o)
out.lm<-lm(y~z,data=dati)
o1<-update(o,seg.Z=~x+z,psi=list(x=c(30,60),z=.3))
Run the code above in your browser using DataLab