Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

broken.line

Fitted values for segmented relationships


Description

Given a segmented model (typically returned by a segmented method), broken.line computes the fitted values (and relevant standard errors) for each ‘segmented’ relationship.

Usage

broken.line(ogg, term = NULL, link = TRUE, interc=TRUE, se.fit=TRUE, isV=FALSE, 
  .vcov=NULL, .coef=NULL, ...)

Arguments

ogg

A fitted object of class segmented (returned by any segmented method).

term

Three options. i) A named list (whose name should be one of the segmented covariates in the model ogg) including the covariate values for which segmented predictions should be computed; ii) a character meaning the name of any segmented covariate in the model, and predictions corresponding to the observed covariate values are returned; iii) It can be NULL if the model includes a single segmented covariate, and predictions corresponding to the observed covariate values are returned;

link

Should the predictions be computed on the scale of the link function? Default to TRUE.

interc

Should the model intercept be added? (provided it exists).

se.fit

If TRUE also standard errors for predictions are returned.

isV

A couple of logicals indicating if the segmented terms (x-ψ)_+ and I(x>ψ) in the model matrix should be replaced by their smoothed counterparts. If a single logical is provided, it is applied to both terms.

.vcov

Optional. The full covariance matrix of estimates. If NULL (and se.fit=TRUE), the matrix is computed internally via vcov.segmented().

.coef

The regression parameter estimates. If unspecified (i.e. NULL), it is computed internally by coef(ogg).

...

Additional arguments to be passed on to vcov.segmented() when computing the standard errors for the predictions, namely is, var.diff, p.df. See summary.segmented and vcov.segmented.

Details

If term=NULL or term is a valid segmented covariate name, predictions for each segmented variable are the relevant fitted values from the model. If term is a (correctly named) list with numerical values, predictions corresponding to such specified values are computed. If link=FALSE and ogg inherits from the class "glm", predictions and possible standard errors are returned on the response scale. The standard errors come from the Delta method. Argument link is ignored whether ogg does not inherit from the class "glm".

Value

A list having one component if (if se.fit=FALSE), and two components (if se.fit=TRUE) list representing predictions and standard errors for the segmented covariate values.

Author(s)

Vito M. R. Muggeo

See Also

Examples

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=.5)
## Not run: plot(z,y)
## Not run: points(z,broken.line(o.seg,link=FALSE)$fit,col=2) #ok, but use plot.segmented()!

segmented

Regression Models with Break-Points / Change-Points Estimation

v1.3-4
GPL
Authors
Vito M. R. Muggeo [aut, cre] (<https://orcid.org/0000-0002-3386-4054>)
Initial release
2021-04-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.