Learn R Programming

segmented (version 2.1-1)

seg: Specifying a segmented/stepmented term in the segreg/stepreg formula

Description

Function used to define a segmented (stepmented) term within the segreg (stepreg) formula. The function simply passes relevant information to proper fitter functions.

Usage

seg(x, npsi = 1, psi = NA, est = NA, R = NA, fixed.psi = NULL, by = NULL, f.x = I)

Value

The function simply returns the covariate with added attributes relevant to segmented term

Arguments

x

The segmented/stepmented (numeric) covariate

npsi

The number of breakpoints/jumpoints to estimate. Default to npsi=1. If by has been specified, the same npsi applies to all categories of the factor by; otherwise it can be vector, wherein the entries represent the number of breakpoints of the segmented relationships within the categories of by. If npsi is specified as a vector, the corresponding est should be a list. The npsi starting values are computed according the specification of quant in seg.control.

psi

Numerical vector indicating possible starting value(s) for the breakpoint(s). When provided, psi overwrites npsi. If by has been specified, psi can be a list, wherein the components represent the starting values of the segmented/stepmented relationships within the categories of by.

est

Possible vector (of length equal to npsi+1) of 0's and 1's to indicate whether the slopes have to be estimated or fixed to zero. NA, the default, means all ones, namely every slope is estimated. Consecutive zeroes are not allowed. If by has been specified, the same est applies to all categories of the factor by; otherwise est can be a list, wherein the components represent the slope constraints of the segmented relationships within the categories of by. Note that, when a grouping variable has been specified in by, npsi can be specified as a vector, and est should be a list.

R

Matrix to constrain the slopes. If provided, it overwrites the matrix (which is built internally) coming from the specification of est.

fixed.psi

Possible fixed breakpoint values to be accounted for in addition to the estimated ones; slope and plot.segmented will account for them correctly.

by

A possible factor meaning an interaction with the segmented term x. Hence, if specified, a different segmented relationship is fitted within each category of by.

f.x

an optional function meaning a function to apply to the covariate before fitting

Author

Vito Muggeo

Details

The function is used within segreg and stepreg to 'build' information about the segmented relationships to fit.

See Also

segreg

Examples

Run this code
##see ?segreg

Run the code above in your browser using DataLab