residuals.vlmc {VLMC} | R Documentation |
Compute Residuals of a Fitted VLMC Object
Description
Compute residuals of a fitted vlmc
object.
This is yet a matter of research and may change in the future.
Usage
## S3 method for class 'vlmc'
residuals(object,
type = c("classwise",
"deviance", "pearson", "working", "response", "partial"),
y = object$y, ...)
Arguments
object |
typically the result of |
type |
The type of residuals to compute, defaults to
|
y |
discrete time series with respect to which the residuals are to be computed. |
... |
possibly further arguments (none at the moment). |
Value
If type = "classwise"
(the default), a numeric matrix of dimension
of values
where the indicator
is 1 iff
y[i] == a[j]
and a
is the alphabet (or levels) of
y
, and are the elements of the estimated (1-step
ahead) predicted probabilities,
p <- predict(object)
.
Hence, for each , the only positive residual stands for the
observed class.
For all other type
s, the result is
a numeric vector of the length of the original time-series (with first
element NA
).
For type = "deviance"
,
where
is the predicted probability for the i-th
observation which is the same as
above (now
assuming
).
The sum of the squared deviance residuals is the deviance of
the fitted model.
Author(s)
Martin Maechler
See Also
vlmc
,deviance.vlmc
, and
RCplot
for a novel residual plot.
Examples
example(vlmc)
rp <- residuals(vlmc.pres)
stopifnot(all(abs(apply(rp[-1,],1,sum)) < 1e-15))
matplot(seq(presidents), rp, ylab = "residuals", type="l")
## ``Tukey-Anscombe'' (the following is first stab at plot method):
matplot(fitted(vlmc.pres), rp, ylab = "residuals", xaxt = "n",
type="b", pch=vlmc.pres$alpha)
axis(1, at = 0:(vlmc.pres$alpha.len-1),
labels = strsplit(vlmc.pres$alpha,"")[[1]])
summary(rd <- residuals(vlmc.pres, type = "dev"))
rd[1:7]
## sum of squared dev.residuals === deviance :
all.equal(sum(rd[-1] ^ 2),
deviance(vlmc.pres))