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

selgmented

Selecting number of breakpoints in segmented regression


Description

This function selects the number of breakpoints of the segmented relationship according to the BIC criterion or sequential hypothesis testing.

Usage

selgmented(olm, seg.Z, alpha = 0.05, type = c("score", "davies", "bic"), 
  control = seg.control(), return.fit = TRUE, bonferroni = FALSE, Kmax = 2, msg=TRUE)

Arguments

olm

A starting lm or glm object

seg.Z

A one-side formula for the segmented variable. Only one term can be included, and it can be omitted if olm includes just one covariate.

alpha

The fixed type I error probability.

type

Which criterion should be used? Currently via sequential hypothesis testing score and davies, only Kmax=2 is allowed. Using the BIC allows to compare models with more than 2 breakpoints.

control

See seg.control.

return.fit

If TRUE, the fitted model (with the selected number of breakpoints according to type) is returned.

bonferroni

If TRUE, the Bonferroni correction is employed, i.e. alpha/Kmax is always taken as threshold value to reject or not. If FALSE, alpha is used in the second level of hypothesis testing.

Kmax

The maximum number of breakpoints being tested. If type='bic' any integer value can be specified, otherwise at most Kmax=2 breakpoints can be tested via the Score or Davies statistics.

msg

If FALSE the final fit is returned silently with the selected number of breakpoints, otherwise the message including information about the selection procedure (i.e. the BIC values) is printed.

Details

The function uses properly the functions segmented, pscore.test or davies.test to select the 'right' number of breakpoints.

Value

The returned object depends on argument return.fit. If FALSE, the returned object is a list with some information on the compared models (i.e. the BIC values), otherwise a classical segmented object with the component selection.psi including the aforemntioned information. See segmented for details.

Note

This is a sperimental function. Please use that with caution.

Author(s)

Vito Muggeo

References

Muggeo V (2020) Selecting number of breakpoints in segmented regression: implementation in the R package segmented https://www.researchgate.net/publication/343737604

See Also

Examples

## from ?segmented
## Not run: 
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)

os<-selgmented(out.lm) ## selects number of breakpoints via the Score test

os <-selgmented(out.lm, Kmax=3, type="bic") #BIC-based selection

## End(Not run)

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.