residuals.vlmc {VLMC} | R Documentation |
Compute residuals of a fitted vlmc
object.
This is yet a matter of research and may change in the future.
## S3 method for class 'vlmc': residuals(object, type = c("classwise", "deviance", "pearson", "working", "response", "partial"), y = object$y, ...)
object |
typically the result of vlmc(..) . |
type |
The type of residuals to compute, defaults to
"classwise" which returns an n x m matrix,
see below. The other types only make sense when the discrete
values of y are ordered which always includes the binary case
(m=2).
The "deviance" residuals r are defined similarly as for logistic
regression, see below.
"pearson", "working" and "response" are currently identical and give the difference of the underlying integer code (of the discrete data). Note that "partial" residuals are not yet defined!
|
y |
discrete time series with respect to which the residuals are to be computed. |
... |
possibly further arguments (none at the moment). |
If type = "classwise"
(the default), a numeric matrix of dimension
n x m of values I[i,j] -
p[i,j] where the indicator I[i,j] is 1 iff
y[i] == a[j]
and a
is the alphabet (or levels) of
y
, and p[i,j] are the elements of the estimated (1-step
ahead) predicted probabilities, p <- predict(object)
.
Hence, for each i, 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"
,
r[i] = +- sqrt(-2 log(P[i]))
where P[i] is the predicted probability for the i-th
observation which is the same as p[i,y[i]] above (now
assuming y[i] in {1,2,...,m}).
The sum of the squared deviance residuals is the deviance of
the fitted model.
Martin Maechler
vlmc
,deviance.vlmc
, and
RCplot
for a novel residual plot.
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))