Description Usage Arguments Details Value Note Author(s) See Also Examples
View source: R/dlmodeler-fit.R
Fits a DLM by maximum likelihood (MLE), minimum squared errror (MSE), minimum average deviation (MAD) or minimum standard deviation (sigma) methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | dlmodeler.fit(yt, model=NULL,
method=c("MLE","MSE","MAD","MAPE","sigma"), ...)
dlmodeler.fit.MLE(yt, build.fun, par,
backend = c('KFAS','FKF','dlm'), method = "L-BFGS-B",
verbose = FALSE, silent = FALSE, filter = TRUE,
smooth = FALSE, raw.result = FALSE, ...)
dlmodeler.fit.MSE(yt, build.fun, par,
ahead, iters = NCOL(yt)-ahead-start-1,
step = 1, start = 1,
backend = c('KFAS','FKF','dlm'), method = "L-BFGS-B",
verbose = FALSE, silent = FALSE,
filter = TRUE, smooth = FALSE,
raw.result=FALSE, ...)
dlmodeler.fit.MAD(yt, build.fun, par,
ahead, iters = NCOL(yt)-ahead-start-1,
step = 1, start = 1,
backend = c('KFAS','FKF','dlm'), method = "L-BFGS-B",
verbose = FALSE, silent = FALSE,
filter = TRUE, smooth = FALSE,
raw.result=FALSE, ...)
dlmodeler.fit.MAPE(yt, build.fun, par,
ahead, iters = NCOL(yt)-ahead-start-1,
step = 1, start = 1,
backend = c('KFAS','FKF','dlm'), method = "L-BFGS-B",
verbose = FALSE, silent = FALSE,
filter = TRUE, smooth = FALSE,
raw.result=FALSE, ...)
dlmodeler.fit.sigma(yt, build.fun, par,
backend = c('KFAS','FKF','dlm'), method = "L-BFGS-B",
verbose = FALSE, silent = FALSE,
filter = TRUE, smooth = FALSE,
raw.result=FALSE, ...)
|
yt |
matrix of observed values (one column per time step). |
model |
object of class |
build.fun |
function taking parameter vector |
par |
initial value of the parameter vector |
backend |
an optional argument which specifies the back-end to use for the computations. |
method |
optimization method passed to function |
verbose |
if |
silent |
if |
filter |
if |
smooth |
if |
raw.result |
if |
ahead |
in case of MSE fitting, the number of predictions to make for each iteration. |
iters |
in case of MSE fitting, the number of iterations. |
step |
in case of MSE fitting, the step between iterations. |
start |
in case of MSE fitting, the index of the first prediction. |
... |
additional arguments passed to |
dlmodeler.fit.MLE
is designed to find parameter values which maximize the
log-likelihood for the given data. This is called Maximum Likelihood Estimation.
dlmodeler.fit.MSE
is designed to find parameter values which minimize the
average n-step ahead prediction squared error (predicted-actual)^2
for the given data.
This is called Minimum Squared Error fitting. The squared error is averaged over
ahead
prediction steps. Note that having ahead==1
is roughly
equivalent to MLE fitting as long as only the mean is concerned.
dlmodeler.fit.MAD
is designed to find parameter values which minimize the
average n-step ahead prediction absolute error |predicted-actual|
for the given data.
This is called Minimum Average Deviation fitting. The absolute error is averaged over
ahead
prediction steps.
dlmodeler.fit.MAPE
is designed to find parameter values which minimize the
average n-step ahead prediction absolute percentage error |predicted-actual|
for the given data.
This is called Minimum Average Percentage Error fitting. The absolute percentage error
is averaged over ahead
prediction steps.
dlmodeler.fit.sigma
is designed to find parameter values which minimize the
one-step ahead prediction variance for the given data.
An object of class dlmodeler.fit
with the following values:
par |
optimal parameter returned by the optimization function |
message |
message returned by the optimization function |
convergence |
convergence code returned by the optimization function |
model |
optimal model found: |
logLik |
value of the log-likelihood or NA |
par0 |
initial value of |
filtered |
optionally, the filtered model: |
dlmodeler.fit
automatically fits models which contain NA
values.
Cyrille Szymanski <cnszym@gmail.com>
dlmodeler
,
dlmodeler.filter
,
dlmodeler.smooth
,
dlmodeler.forecast
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ## Not run:
require(dlmodeler)
# analysis from Durbin & Koopman book page 32
# load and show the data
y <- matrix(Nile,nrow=1)
plot(y[1,],type='l')
# y(t) = a(t) + eta(t)
# a(t+1) = a(t) + eps(t)
mod <- dlmodeler.build.polynomial(0,sigmaH=NA,sigmaQ=NA,name='p32')
# fit the model by maximum likelihood estimation
fit <- dlmodeler.fit(y, mod, method="MLE")
# compare the fitted parameters with those reported by the authors
fit$par[2] # psi = -2.33
fit$model$Ht[1,1] # H = 15099
fit$model$Qt[1,1] # Q = 1469.1
# compute the filtered and smoothed values
f <- dlmodeler.filter(y, fit$mod, smooth=TRUE)
# f.ce represents the filtered one steap ahead observation
# prediction expectations E[y(t) | y(1), y(2), ..., y(t-1)]
f.ce <- dlmodeler.extract(f, fit$model,
type="observation", value="mean")
# s.ce represents the smoothed observation expectations
# E[y(t) | y(1), y(2), ..., y(n)]
s.ce <- dlmodeler.extract(f$smooth, fit$model,
type="observation", value="mean")
# plot the components
plot(y[1,],type='l')
lines(f.ce$p32[1,],col='light blue',lty=2)
lines(s.ce$p32[1,],col='dark blue')
## End(Not run)
|
CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH : 0 in 33 iterations
[1] 7.292423
[1] 15098.71
[1] 1469.126
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.