predict.vlmc | R Documentation |
Compute predictions on a fitted VLMC object
for each (but the first) element of another discrete time series.
Computes by default a matrix of prediction probabilities. The argument
type
allows other predictions such as the most probable
"class"
or "response"
, the context length (tree
"depth"
), or an "ID"
of the corresponding context.
## S3 method for class 'vlmc'
predict(object, newdata,
type = c("probs", "class","response", "id.node", "depth", "ALL"),
se.fit = FALSE,
allow.subset = TRUE, check.alphabet=TRUE,
...)
## S3 method for class 'vlmc'
fitted(object, ...)
object |
typically the result of |
newdata |
a discrete “time series”, a numeric, character or
factor, as the |
type |
character indicating the type of prediction required,
options given in the Usage secion above, see also the
Value section below. The default |
se.fit |
a switch indicating if standard errors are required.
|
allow.subset |
logical; if |
check.alphabet |
logical; if |
... |
(potentially further arguments) required by generic. |
Depending on the type
argument,
"probs" |
an
|
"class" , "response" |
the corresponding most probable value of Y[];
as |
"id.node" |
an (integer) “ID” of the current context (= node of the tree represented VLMC). |
"depth" |
the context length, i.e., the depth of the
Markov chain, at the current observation (of |
"ALL" |
an object of class
which has its own print method ( |
The predict
method and its possible arguments may still be
developed, and we are considering to return the marginal
probabilities instead of NA
for the first value(s).
The print
method print.predict.vlmc
uses
fractions
from package MASS to display
the probabilities Pr[X = j]
, for
j \in \{0,1,\dots\}
, as these are rational
numbers, shown as fractions of integers.
vlmc
and residuals.vlmc
. For
simulation, simulate.vlmc
.
f1 <- c(1,0,0,0)
f2 <- rep(1:0,2)
(dt2 <- rep(c(f1,f1,f2,f1,f2,f2,f1),2))
(vlmc.dt2c15 <- vlmc(dt2, cutoff = 1.5))
draw(vlmc.dt2c15)
## Fitted Values:
all.equal(predict(vlmc.dt2c15, dt2), predict(vlmc.dt2c15))
(pa2c15 <- predict(vlmc.dt2c15, type = "ALL"))
## Depth = context length ([1] : NA) :
stopifnot(nchar(pa2c15 $ ctxt)[-1] ==
predict(vlmc.dt2c15, type = "depth")[-1])
same <- (ff1 <- pa2c15 $ fitted) ==
(ff2 <- int2alpha(predict(vlmc.dt2c15, type ="response"), alpha="01"))
which(!same) #-> some are different, since max.col() breaks ties at random!
ndt2 <- c(rep(0,6),f1,f1,f2)
predict(vlmc.dt2c15, ndt2, "ALL")
(newdt2 <- sample(dt2, 17))
pm <- predict(vlmc.dt2c15, newdt2, allow.subset = TRUE)
summary(apply(pm, 1, sum))# all 1
predict(vlmc.dt2c15, newdt2, type = "ALL")
data(bnrf1)
(vbnrf <- vlmc(bnrf1EB))
(pA <- predict(vbnrf, bnrf1EB[1:24], type = "ALL"))
pc <- predict(vbnrf, bnrf1EB[1:24], type = "class")
pr <- predict(vbnrf, bnrf1EB[1:24], type = "resp")
stopifnot(as.integer (pc[-1]) == 1 + pr[-1],
as.character(pc[-1]) == strsplit(vbnrf$alpha,NULL)[[1]][1 + pr[-1]])
##-- Example of a "perfect" fit -- just for illustration:
## the default, thresh = 2 doesn't fit perfectly(i=38)
(vlmc.dt2c0th1 <- vlmc(dt2, cutoff = 0, thresh = 1))
## "Fitted" = "Data" (but the first which can't be predicted):
stopifnot(dt2[-1] == predict(vlmc.dt2c0th1,type = "response")[-1])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.