| cable.fit.known.change | R Documentation | 
These functions compute the profile deviance over a (τ,γ)-grid
to either fit a bent-cable regression with known transition, or to
generate initial values for a bent-cable regression with unknown
transition. cable.dev and cable.fit.known.change form
the main engine of bentcable.dev.plot.
cable.ar.0.fit(y.vect, t.vect = NULL, tau.vect, gamma.vect, dev.mat, stick = FALSE) cable.dev(tau.vect, gamma.vect, y.vect, t.vect = NULL, p = 0) cable.fit.known.change(y.vect, t.vect = NULL, n = NA, tau.vect, gamma.vect, dev.mat, p = 0)
y.vect | 
 A numeric vector of response values.  | 
t.vect | 
  A numeric vector of design points. Specifying
  | 
n | 
 Length of response vector (optional).  | 
tau.vect | 
 A numeric vector of τ-coordinates of the grid points.  | 
gamma.vect | 
 A numeric vector of γ-coordinates of the grid points.  | 
dev.mat | 
 A numeric matrix (can be single column) corresponding to the bent-cable profile deviance surface / function over the (τ,γ)-grid.  | 
p | 
  The autoregressive order (non-negative integer).
  | 
stick | 
  A logical value; if   | 
Given the response data in y.vect and design points 
in t.vect, cable.dev evaluates the bent-cable 
profile deviance surface / function over the user-specified
(τ,γ)-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 bentcable.dev.plot.
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. 
cable.fit.known.change locates this peak and computes 
this fit. If multiple peaks exist (such as along a ridge), 
then only that at the smallest τ and smallest γ 
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 cable.fit.known.change
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 bentcable.ar 
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 cable.ar.0.fit (called internally by 
bentcable.ar). cable.ar.0.fit calls
cable.ar.p.iter when stick=FALSE but calls stick.ar.0
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 
bentcable.dev.plot).
fit | 
  Returned by  For  For   | 
init | 
  Returned by   | 
y | 
  Same as   | 
t | 
  Same as   | 
n, p, stick | 
  As supplied by the user: returned by   | 
cable.dev 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 bentcable.dev.plot
and bentcable.ar.
Grace Chiu
 See the bentcableAR package references. 
bentcable.dev.plot, bentcable.ar,
nls, lm, arima 
data(stagnant) data(sockeye) # non-time-series data: compute grid-based profile deviance cable.dev( seq(-.04,.16,length=10), seq(.2,.65,length=10), stagnant$loght, stagnant$logflow ) # compare to this: # bentcable.dev.plot( 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 <- cable.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 ) cable.fit.known.change( 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 <- cable.dev ( seq(85,97,length=15), 0, sockeye$logReturns, sockeye$year) plot( seq(85,97,length=15), dev, type="l" ) cable.ar.0.fit( sockeye$logReturns, sockeye$year, tau.v=seq(85,97,length=15), gamma.v=0, dev.mat=dev, stick=TRUE ) # compare to this: # bentcable.ar( sockeye$logReturns, bentcable.dev.plot( # seq(85,97,length=15), 0, sockeye$logReturns, sockeye$year, TRUE # ), stick=TRUE, t.vect=sockeye$year )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.