{bentcableAR}R Documentation

Bent-Cable Regression for Independent or AR Data, With Exception


This function is the main engine for It performs bent-cable (including broken-stick) regression to AR(p) time-series data or independent data (time-series or otherwise). However, it cannot fit broken sticks to independent data (see

Usage, y.vect, t.vect = NULL, n = NA, tol,
	method0 = "css", method1 = "yw", stick = FALSE)



A numeric vector of initial values, in the form of c(b0,b1,b2,tau,gamma,phi.1,...,phi.p) when stick=FALSE, and c(b0,b1,b2,tau,phi.1,...,phi.p) when stick=TRUE. phi values correspond to AR(p) coefficients - if not included, then independent data are assumed.


A numeric vector of response data.


A numeric vector of design points, which MUST be equidistant with unit increments if AR(p) is assumed. They need not be equidistant for independent data. Specifying t.vect=NULL is equivalent to specifying the default time points c(0,1,2,...).


Length of response vector (optional).


Tolerance for determining convergence.

method0, method1

The fitting method when p>0. "css" stands for conditional sum-of-squares and corresponds to conditional maximum likelihood. "yw" stands for Yule-Walker, and "mle" for (full) maximum likelihood estimation. If method0 fails to converge, then method1 is attempted.


A logical value; if TRUE, a broken-stick regression is performed.


The bent cable has the form f(t) = b_0 + b_1 t + b_2 q(t), where q(t) is the basic bent cable

q(t)=\frac{(t-\tau+\gamma)^2}{4\gamma} I\{|t-\tau|\le\gamma\} + (t-\tau) I\{t>\tau+\gamma\}

for \gamma\ge 0.

For independent data (time series or otherwise), bent-cable regression by maximum likelihood is performed via nonlinear least-squares estimation of \theta=(b_0,b_1,b_2,\tau,\gamma) through the built-in R function nls. For AR(p) data, conditional maximum likelihood (CML) estimation of (\theta,\phi) (conditioned on the first p data points) is performed through the built-in R function optim with the "BFGS" algorithm, where \phi=(\phi_1,\ldots,\phi_p) are the AR coefficients. In either case, the estimation relies on the user-supplied initial values in init. A Gaussian model is assumed, so that CML estimation is equivalent to minimizing the conditional sum-of-squares error, specified as "css" by default for method0. However, "css" sometimes fails to converge, or the resulting \phi estimate sometimes corresponds to non-stationarity. In this case, the alternative estimation approach specified for method1 is attempted. "mle" specifies the CML-ML hybrid algorithm, and "yw" the CML-ML-MM hybrid algorithm (MM stands for method of moments; see References.) Both "yw" and "mle" guarantee stationarity, but often take much longer than "css" to converge.

The bent-cable likelihood / deviance often has multiple peaks. Thus, the user should be aware of different local maxima on which the optimization algorithm can converge despite initial values for \theta that are very similar. The user is advised to combine several exploratory analyses as well as model diagnoses before settling on a best fit. See Details on the help page for a detailed description.



An nls object, returned if independent data are assumed. It is the maximum likelihood bent-cable fit.


A numeric vector, returned if AR(p>0) is assumed. It is the estimated value of (\theta,\phi).

Returned if AR(p>0) is assumed. If "css" is used, converges, and yields a \phi estimate that corresponds to stationarity, then $ is an optim object containing the CML fit. If "yw" or "mle" is used and converges, then $ is an ar object containing the CML-ML(-MM) fit.

y, t, n, p, stick

As supplied by the user; always returned.


A character string, returned if AR(p>0) is assumed. It indicates the method that yielded the returned fit.


This function is intended for internal use by

For several fits that assume a common p, their (conditional) likelihood values should be compared to screen out those that result from local maxima. Equivalently, the (conditional) sum-of-squares error (SSE) can be compared and only the smallest kept. See Examples below. Also see Details on the help page.


Grace Chiu


See the bentcableAR package references.

See Also, fullcable.t,, nls, optim, ar.



# 'stagnant': independent data cable fit
fit0 <- c(.6,-.4,-.7,0,.5),
	stagnant$loght, stagnant$logflow )    # 'nls' fit
	# compare to this:
	# stagnant$loght, t.vect=stagnant$logflow,
	#	init.cable=c(.6,-.4,-.7,0,.5) )

fit0$fit   # 'fit0' SSE=0.005

# 'sockeye': AR(2) cable fit
fit1 <- c(13,.1,-.5,11,4,.5,-.5),
	sockeye$logReturns, tol=1e-4 )    # "css" successful
	# compare to this:
	# fit1 <- sockeye$logReturns, 
	#	init.cable=c(13,.1,-.5,11,4), p=2 )

fit1$$value     # 'fit1' SSE=4.9

# 'sockeye': AR(2) cable fit
fit2 <- c(10,0,0,5,.1,.5,-.5), sockeye$logReturns, 
	tol=1e-4 )    # "css" unsuccessful, switched to "yw"
	# compare to this:
	# fit2 <-$logReturns, 
	#	init.cable=c(10,0,0,5,.1), p=2 ) fit2$est, sockeye$logReturns, 
	tol=1e-4 )   # 'fit2' SSE=13.8 (from first line of screen output)

# 'sockeye': AR(4) stick fit c(13,.1,-.5,11,.5,-.5,.5,-.5),
	sockeye$logReturns, tol=1e-4, stick=TRUE )
	# compare to this:
	# sockeye$logReturns,
	#	init.cable=c(13,.1,-.5,11), p=4, stick=TRUE )

[Package bentcableAR version 0.3.1 Index]