R: Smoothed Estimates or One-step-ahead Predictions of Fitted...
fitted.SSModel
R Documentation
Smoothed Estimates or One-step-ahead Predictions of Fitted Values
Description
Computes fitted values from output of KFS
(or using the SSModel object), i.e. one-step-ahead
predictions
f(θ[t] | y[t-1], ... , y[1]), (m) or smoothed estimates
f(θ[t] | y[n], ... , y[1]), (muhat),
where f is the inverse of the link function
(identity in Gaussian case), except in case of Poisson distribution where
f is multiplied with the exposure u[t].
Usage
## S3 method for class 'KFS'
fitted(object, start = NULL, end = NULL, filtered = FALSE,
...)
## S3 method for class 'SSModel'
fitted(object, start = NULL, end = NULL,
filtered = FALSE, nsim = 0, ...)
Arguments
object
An object of class KFS or SSModel.
start
The start time of the period of interest. Defaults to first time
point of the object.
end
The end time of the period of interest. Defaults to the last time
point of the object.
filtered
Logical, return filtered instead of smoothed estimates of
state vector. Default is FALSE.
...
Additional arguments to KFS.
Ignored in method for object of class KFS.
nsim
Only for method for for non-Gaussian model of class SSModel.
The number of independent samples used in importance sampling.
Default is 0, which computes the
approximating Gaussian model by approxSSM and performs the
usual Gaussian filtering/smoothing so that the smoothed state estimates
equals to the conditional mode of p(α[t]|y).
In case of nsim = 0, the mean estimates and their variances are computed using
the Delta method (ignoring the covariance terms).
Value
Multivariate time series containing fitted values.
See Also
signal for partial signals and their covariances.
Examples
data("sexratio")
model <- SSModel(Male ~ SSMtrend(1,Q = list(NA)),u = sexratio[, "Total"],
data = sexratio, distribution = "binomial")
model <- fitSSM(model,inits = -15, method = "BFGS")$model
out <- KFS(model)
identical(drop(out$muhat), fitted(out))
fitted(model)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(KFAS)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/KFAS/fitted.SSModel.Rd_%03d_medium.png", width=480, height=480)
> ### Name: fitted.SSModel
> ### Title: Smoothed Estimates or One-step-ahead Predictions of Fitted
> ### Values
> ### Aliases: fitted.KFS fitted.SSModel
>
> ### ** Examples
>
> data("sexratio")
> model <- SSModel(Male ~ SSMtrend(1,Q = list(NA)),u = sexratio[, "Total"],
+ data = sexratio, distribution = "binomial")
> model <- fitSSM(model,inits = -15, method = "BFGS")$model
> out <- KFS(model)
> identical(drop(out$muhat), fitted(out))
[1] TRUE
>
> fitted(model)
Time Series:
Start = 1751
End = 2011
Frequency = 1
[1] 0.5066511 0.5066629 0.5066995 0.5067572 0.5068369 0.5069363 0.5070550
[8] 0.5071461 0.5072273 0.5073084 0.5073665 0.5074216 0.5074847 0.5075184
[15] 0.5075507 0.5075750 0.5076258 0.5076650 0.5076862 0.5077209 0.5077150
[22] 0.5077174 0.5077345 0.5077500 0.5077503 0.5077853 0.5078492 0.5079136
[29] 0.5079797 0.5080239 0.5080692 0.5080907 0.5080372 0.5079898 0.5079923
[36] 0.5080473 0.5081079 0.5081333 0.5081632 0.5082400 0.5082988 0.5083593
[43] 0.5084385 0.5084914 0.5085409 0.5085489 0.5086004 0.5086702 0.5087118
[50] 0.5087362 0.5087423 0.5087626 0.5087959 0.5088151 0.5088392 0.5088212
[57] 0.5088239 0.5088365 0.5088177 0.5087765 0.5087590 0.5087442 0.5087357
[64] 0.5087186 0.5087195 0.5087315 0.5087759 0.5088603 0.5089367 0.5089756
[71] 0.5090077 0.5090266 0.5090439 0.5090930 0.5090992 0.5091371 0.5091903
[78] 0.5092383 0.5092827 0.5093131 0.5093003 0.5093049 0.5093670 0.5093944
[85] 0.5094130 0.5094055 0.5094212 0.5094617 0.5094896 0.5095072 0.5095775
[92] 0.5096363 0.5097078 0.5097541 0.5098334 0.5098977 0.5099123 0.5099372
[99] 0.5099862 0.5100826 0.5102156 0.5103694 0.5105196 0.5106624 0.5107437
[106] 0.5108126 0.5108909 0.5110175 0.5111197 0.5112031 0.5112690 0.5113217
[113] 0.5113966 0.5114350 0.5114845 0.5115273 0.5115692 0.5116431 0.5117073
[120] 0.5117342 0.5117774 0.5118653 0.5119421 0.5119998 0.5120381 0.5120480
[127] 0.5121536 0.5122955 0.5123285 0.5123761 0.5124117 0.5124169 0.5123993
[134] 0.5124257 0.5124565 0.5124743 0.5125069 0.5125928 0.5127352 0.5128247
[141] 0.5128881 0.5129691 0.5130381 0.5130768 0.5131393 0.5131995 0.5132922
[148] 0.5133672 0.5134374 0.5135187 0.5135727 0.5136355 0.5136780 0.5137097
[155] 0.5137469 0.5138614 0.5139745 0.5141166 0.5142252 0.5143514 0.5145002
[162] 0.5145610 0.5146102 0.5146137 0.5146284 0.5146523 0.5146919 0.5147281
[169] 0.5147673 0.5147580 0.5147385 0.5147415 0.5147496 0.5147210 0.5146586
[176] 0.5145749 0.5145124 0.5144306 0.5143391 0.5142829 0.5142557 0.5141771
[183] 0.5141497 0.5141292 0.5141744 0.5141599 0.5141657 0.5141553 0.5141019
[190] 0.5141370 0.5141825 0.5141856 0.5141881 0.5141458 0.5140671 0.5139260
[197] 0.5137983 0.5136453 0.5135094 0.5133403 0.5131709 0.5130147 0.5128571
[204] 0.5126953 0.5126205 0.5125276 0.5124390 0.5123310 0.5122582 0.5121838
[211] 0.5121196 0.5120897 0.5120595 0.5120257 0.5119843 0.5119490 0.5119761
[218] 0.5119842 0.5120224 0.5120381 0.5120657 0.5121434 0.5121580 0.5121128
[225] 0.5121062 0.5120548 0.5119821 0.5119072 0.5118089 0.5117770 0.5117246
[232] 0.5116793 0.5115841 0.5114964 0.5114243 0.5113807 0.5113291 0.5112666
[239] 0.5112036 0.5111355 0.5110579 0.5110244 0.5109783 0.5109664 0.5109962
[246] 0.5110307 0.5110347 0.5110870 0.5111544 0.5112299 0.5112384 0.5112539
[253] 0.5112250 0.5112270 0.5111857 0.5111771 0.5111887 0.5111686 0.5111526
[260] 0.5111626 0.5111343
>
>
>
>
>
> dev.off()
null device
1
>