cable.ar.p.iter {bentcableAR} | R Documentation |
This function is the main engine for bentcable.ar
. 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
stick.ar.0
).
cable.ar.p.iter(init, y.vect, t.vect = NULL, n = NA, tol,
method0 = "css", method1 = "yw", stick = FALSE)
init |
A numeric vector of initial values, in the form of
|
y.vect |
A numeric vector of response data. |
t.vect |
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 |
n |
Length of response vector (optional). |
tol |
Tolerance for determining convergence. |
method0 , method1 |
The fitting method when p>0. |
stick |
A logical value; if |
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
bentcable.ar
help page for a detailed description.
fit |
An |
estimate |
A numeric vector, returned if AR(p>0) is assumed. It is the
estimated value of ( |
ar.p.fit |
Returned if AR(p>0) is assumed. If |
y , t , n , p , stick |
As supplied by the user; always returned. |
method |
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 bentcable.ar
.
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 bentcable.ar
help
page.
Grace Chiu
See the bentcableAR
package references.
stick.ar.0
, fullcable.t
,
bentcable.dev.plot
,
nls
, optim
,
ar
.
data(stagnant)
data(sockeye)
# 'stagnant': independent data cable fit
fit0 <- cable.ar.p.iter( c(.6,-.4,-.7,0,.5),
stagnant$loght, stagnant$logflow ) # 'nls' fit
# compare to this:
# bentcable.ar( 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 <- cable.ar.p.iter( c(13,.1,-.5,11,4,.5,-.5),
sockeye$logReturns, tol=1e-4 ) # "css" successful
# compare to this:
# fit1 <- bentcable.ar( sockeye$logReturns,
# init.cable=c(13,.1,-.5,11,4), p=2 )
fit1$ar.p.fit$value # 'fit1' SSE=4.9
# 'sockeye': AR(2) cable fit
fit2 <- cable.ar.p.iter( c(10,0,0,5,.1,.5,-.5), sockeye$logReturns,
tol=1e-4 ) # "css" unsuccessful, switched to "yw"
# compare to this:
# fit2 <- bentcable.ar(sockeye$logReturns,
# init.cable=c(10,0,0,5,.1), p=2 )
cable.ar.p.iter( fit2$est, sockeye$logReturns,
tol=1e-4 ) # 'fit2' SSE=13.8 (from first line of screen output)
# 'sockeye': AR(4) stick fit
cable.ar.p.iter( c(13,.1,-.5,11,.5,-.5,.5,-.5),
sockeye$logReturns, tol=1e-4, stick=TRUE )
# compare to this:
# bentcable.ar( sockeye$logReturns,
# init.cable=c(13,.1,-.5,11), p=4, stick=TRUE )