{bentcableAR}R Documentation

Grid-based Bent-Cable Regression for Independent or AR Data


These functions compute the profile deviance over a (\tau,\gamma)-grid to either fit a bent-cable regression with known transition, or to generate initial values for a bent-cable regression with unknown transition. and form the main engine of

Usage, t.vect = NULL, tau.vect, gamma.vect, dev.mat,
	stick = FALSE), gamma.vect, y.vect, t.vect = NULL, p = 0), t.vect = NULL, n = NA,
	tau.vect, gamma.vect, dev.mat, p = 0)



A numeric vector of response values.


A numeric vector of design points. Specifying t.vect=NULL is equivalent to specifying the default time points c(0,1,2,...). Also see Warnings below.


Length of response vector (optional).


A numeric vector of \tau-coordinates of the grid points.


A numeric vector of \gamma-coordinates of the grid points.


A numeric matrix (can be single column) corresponding to the bent-cable profile deviance surface / function over the (\tau,\gamma)-grid.


The autoregressive order (non-negative integer). p=0 specifies independent data that may or may not be from a time series context.


A logical value; if TRUE then a broken stick (i.e. bent cable with \gamma=0.) is fitted.


Given the response data in y.vect and design points in t.vect, evaluates the bent-cable profile deviance surface / function over the user-specified (\tau,\gamma)-grid. The returned values are intended to be used in conjunction with contour or persp, in which case tau.vect and gamma.vect should have length greater than 1 so that the returned object is a matrix with at least two columns. If such a plot is not required, then tau.vect and/or gamma.vect can be scalar. This function is internal to the main plotting interface

The grid point at which the profile deviance is maximum corresponds to a bent-cable fit given a known transition that is best among the specified grid points. locates this peak and computes this fit. If multiple peaks exist (such as along a ridge), then only that at the smallest \tau and smallest \gamma is used.

For both functions, p=0 should be specified to indicate independent data (time series or otherwise). For time-series data, a positive integer p should be specified as the autoregressive order. Fitting is done by internally calling the built-in R function lm for p=0 and arima for non-zero p; this procedure is appropriate since bent-cable regression with a known transition is linear.

Note that the grid-based does not locate the true peak of the continuous profile deviance surface / function. However, for a grid that traps the true peak between grid points, the returned fit is approximately the overall best fit (with all parameters unknown), and thus can be fed into as initial values for computing the actual best fit. A special case is p=0 for independent data (time-series or otherwise), which can be handled by (called internally by calls when stick=FALSE but calls when stick=TRUE; in both cases, the built-in R function nls is utilized to perform maximum likelihood.

For all three functions, to fit a broken stick with a known break point, gamma.vect should be the single value 0, and thus dev.mat is a column matrix (see



Returned by and

For, $fit is the AR(p) bent-cable regression at the known transition grid point; if p=0, it is an lm object, otherwise it is an arima object.

For, $fit is an nls object that is the maximum likelihood bent-cable fit.


Returned by, containing the coefficients from $fit that can be used as initial values in bent-cable regression with unknown transition.


Same as y.vect: returned by


Same as t.vect: returned by

n, p, stick

As supplied by the user: returned by returns the evaluated profile deviance surface / function as a matrix.


For time-series data, t.vect MUST be equidistant with unit increments; otherwise, these functions will return meaningless values. (For independent data, t.vect can be non-equidistant.)

Grid-based bent-cable regression and its use in subsequent overall fits rely on locating the region in which the continous deviance surface truly peaks. The user should be aware of possible local maxima and/or coarse grids that result in less-than-best fits.


These functions are intended for internal use by and


Grace Chiu


See the bentcableAR package references.

See Also,, nls, lm, arima



# non-time-series data: compute grid-based profile deviance seq(-.04,.16,length=10), seq(.2,.65,length=10), 
	stagnant$loght, stagnant$logflow )
	# compare to this:
	# seq(-.04,.16,length=10), 
	#	seq(.2,.65,length=10), stagnant$loght, stagnant$logflow )$dev

# AR(2) bent cable, start time at 0: find best grid-based fit
dev <- seq(6,18,length=15), seq(.01,12,length=15),
		sockeye$logReturns, p=2 )
contour( seq(6,18,length=15), seq(.01,12,length=15), dev ) sockeye$logReturns, tau.v=seq(6,18,length=15), 
	gamma.v=seq(.01,12,length=15), dev.mat=dev, p=2 )

# AR(0) broken stick, start time at 80: find best overall fit
dev <- ( seq(85,97,length=15), 0, sockeye$logReturns, 
plot( seq(85,97,length=15), dev, type="l" ) sockeye$logReturns, sockeye$year,
	tau.v=seq(85,97,length=15), gamma.v=0, dev.mat=dev, 
	stick=TRUE )
	# compare to this:
	# sockeye$logReturns,
	#	seq(85,97,length=15), 0, sockeye$logReturns, sockeye$year, TRUE
	#	), stick=TRUE, t.vect=sockeye$year )

[Package bentcableAR version 0.3.1 Index]