search for: dlmfilter

Displaying 15 results from an estimated 15 matches for "dlmfilter".

Did you mean: clmilter
2013 Feb 20
1
Tracking time-varying objects with the DLM package (dynamic linear models in R)
Hello all, I am working with the dlm package, specifcially doing a dlm multivariate Y linear regression using dlmModReg and dlmFilter and dlmSmooth... I have altereted the inputs into dlmModReg to make them time-varying using JFF, JW etc. How do I track the results of the time varying system matrices? For example what I am really interested in is JW - my system variance matrix for each time period - I cannot get R to give me th...
2011 Nov 18
0
Kalman Filter with dlm
...While forecasting into the future, I will NOT have data for all three variables. So, I am predicting X1 and X2 using two Kalman filters. The code is below x1.model <- dlmModSeas(52) + dlmModPoly(1, dV=5, dW=10) x2.model <- dlmModSeas(52) + dlmModPoly(1, dV=10, dW=10) x1.filter <- dlmFilter(c(train$x1, rep(NA, noofsteps)), x1.model) x2.filter <- dlmFilter(c(train$x2, rep(NA, noofsteps)), x2.model) Now, I am forecasting Y using the predicted X1 and X2 as below pred <- cbind(c(train$x1, x1.filter$f[260:312]),c(train$x2, x2.filter$f[260:312])) Y.model <- dlmModSeas(52)...
2014 Jan 08
0
Strange behaviour of `dlm` package
...lt;- function (x) { dlmModPoly(order = 2, dV = exp(x[1]), dW = c(0,exp(x[2]))) } fit <- dlmMLE(y=tsdata, parm=c(0,0), build=buildfun) # Warning: a numerically singular 'V' has been slightly perturbed to make it nonsingular fit$conv dlmTsdata <- buildfun(fit$par) tsdataFilter <- dlmFilter(tsdata, mod=dlmTsdata) tsdataSmooth <- dlmSmooth(tsdata, mod=dlmTsdata) plot(tsdata, lwd=2) for (i in 1:10) lines(lty=6, col="blue", dropFirst(dlmBSample(tsdataFilter))[,1]) # looks ok! tsdataForecast <- dlmForecast(tsdataFilter, nAhead=20) sqrtR <- sapply(tsdataForecast$R,...
2008 Oct 31
1
Kalman Filter
Hi, I am studying Kalman Filter and it seems to be difficult for me to apply the filter on a simple ARMA. It is easy to construct the state-space model, for instance: dlmModARMA(ar=c(0.4,-0.2),ma=c(0.2,-0.1, sigma2=1) but applying the dlmFilter on it, it doesn't work... I don't know if my problem is clear but if anyone has already worked on Kalman filter, it could be great to advise me! Thank you in advance! Sandrine
2012 Jan 23
0
problems with dlmBSample of the dlm package
Dear R users, I am trying to use the dlm package, and in particular the dlmBSample function. For some reason that I am not able to understand, this function does not work properly and the plot of the result does not make sense, while dlmFilter works perfectly. I think that my_mod is correct, because the output of my_dlmFilter$mod is fine. Where is my mistake or my misunderstanding? This is the code: function (orig_ts){ library(dlm) dV_T <- 20000 dW_T <- c(100,10) m0_T <- rep(0,2) C0_T <- 10000*diag(nrow=2) my_dlmModPoly &lt...
2009 Mar 11
1
Forecasting with dlm
...2468) library(dlm) buildFun <- function(x) { dlmModPoly(1, dV = exp(x[1]), dW = exp(x[2])) } fit <- dlmMLE(CostUSD, parm = c(0,0), build = buildFun) fit$conv dlmCostUSD <- buildFun(fit$par) V(dlmCostUSD) W(dlmCostUSD) #For comparison StructTS(CostUSD, "level") CostUSDFilt <- dlmFilter(CostUSD, dlmCostUSD) CostUSDFore <- dlmForecast(CostUSDFilt, nAhead = 1) after which i return the error message: Error in mod$m[lastObsIndex, ] : incorrect number of dimensions Can anyone offer any insight to this problem? Thanks in advance Mike [[alternative HTML version deleted]]
2009 May 10
1
Help with kalman-filterd betas using the dlm package
...r follow a RW or AR(1) model. This is how I think it would be set up; I will have my time-series Y,X, where Y is the response variable this setup should give me a RW process if I have understood the example correctly mydlmModel = dlmModReg(X) + dlmModPoly(order=1) and then run on the dlm model dlmFilter(Y,mydlmModel ) but setting up a AR(1) process is unclear, should I use dlmModPoly or the dlmModARMA to set up the model. And at last but not the least, how do I set up a proper build function to use with dlmMLE to optimize the starting values. Regards Tom -- View this message in context: http:/...
2007 Nov 28
0
Package dlm version 0.8-1
...llowed in the observations. 2) Extractor and replacement functions for the matrices defining a dlm are now available. 3) The function for Kalman smoothing, "dlmSmooth", can take as arguments a data vector and a dlm object. Previously the argument had to be the output from "dlmFilter". 4) In addition to the "+" method function for objects of class "dlm", used to build complex models from simple components, all having the same dimensionality of the observation vector, there is now an outer sum, "%+%", which creates a joint model from...
2007 Nov 28
0
Package dlm version 0.8-1
...llowed in the observations. 2) Extractor and replacement functions for the matrices defining a dlm are now available. 3) The function for Kalman smoothing, "dlmSmooth", can take as arguments a data vector and a dlm object. Previously the argument had to be the output from "dlmFilter". 4) In addition to the "+" method function for objects of class "dlm", used to build complex models from simple components, all having the same dimensionality of the observation vector, there is now an outer sum, "%+%", which creates a joint model from...
2010 Sep 28
0
Time invariant coefficients in a time varying coefficients model using dlm package
...= (1, P_t, u_t) * (a1_t, a2_t, a3_t)' + v_t v_t ~ N(0,V) As far as I understand state space modeling the following restrictions on the Variance-covariance matrix W should imply a1_t=a1 and a2_t=a2 which is time invariant: (9) W=[(0,0,0),(0,0,0),(0,0,w_33)] However, if I apply the filter (dlmFilter) (not smoother) on this specification with estimated values for the unknown paramters (w_33 and matrix V) in order to get the series of the state vector (a1_t, a2_t, a3_t)' then for some reason a1_t and a2_t are not constant!!! a3_t isn't either but this is how it is supposed to be. How is...
2011 Jun 03
0
Package dlm generates unstable results?
...end of the mail)   BuildMod <- function(x){  return(dlm(   m0  = x[1],   C0  = x[2],   FF  = 1,   GG  = 1,   V   = x[3],   W   = x[4],   JFF = 1,   X   = X   )) } ModFit  <- dlmMLE(Y,rep(1,4),BuildMod,debug=T) dlmMod  <- BuildMod(ModFit$par) V <- dlmMod$V W <- dlmMod$W ModFilt <- dlmFilter(Y,dlmMod) v <- tail(dlmSvd2var(ModFilt$U.C,ModFilt$D.C),1) m <- tail(ModFilt$m,1)   The results are: V = 5.945003e-05 W = 0.0003086623 v = 9.850526e-05 (the estimated variance for a_t  after we observe the last pair of observations) m = -0.02965614 (the estimated mean for a_t after we obse...
2011 Jun 03
0
How to reconcile Kalman filter result (by package dlm) with linear regression?
...F  = matrix(1,1,nFactor),   GG  = diag(nFactor),   V   = tail(x,1)^2,   W   = crossprod(L1),   JFF = matrix(1:4,nr=1),   X   = X   )) } ModFit  <- dlmMLE(Y,rep(0.1,nTotal),BuildMod,debug=T) dlmMod  <- BuildMod(ModFit$par) V  = dlmMod$V W  = dlmMod$W m0 = dlmMod$m0 C0 = dlmMod$C0 ModFilt <- dlmFilter(Y,dlmMod) v <- tail(dlmSvd2var(ModFilt$U.C,ModFilt$D.C),1) m <- tail(ModFilt$m,1)   Here is the value of Y: 0.0125678739370109 -0.00241285475528163 0.00386919876129071 -0.00352839097011217 0.00285344714211614 0.00374266510625097 0.00797807743013259 -0.00543459628953192 -0.0138447399853609 -0...
2013 Mar 08
0
using dlmModPoly in library dlm
Hi Group, I'm trying to build a model to predict a product's sale price. I'm researching the dlm package. Looks like I should use dlmModPoly, dlmMLE, dlmFilter, dlmSmooth, and finally dlmForecast. I'm looking at the Nile River example and I have a few questions: 1. If I only want to predict future sale price based on observed sale price, I should use a univariate model, correct? 2. how do I initiate value for dV and dW? In the exampl...
2018 Mar 26
0
"dlm" Package: Calculating State Confidence Intervals
...y trends). The model is saved in the object titled "mod." Following the example in the documentation and using the commands below, I am attempting to use the function "dlmSvd2var" to implement SVD and calculate the 90% confidence errors for each time-varying state. outF <- dlmFilter(y,mod) v <- unlist(dlmSvd2var(outF$U.C, outF$D.C)) pl <- dropFirst(outF$m) + qnorm(0.05, sd=sqrt(v[-1])) pu <- dropFirst(outF$m) + qnorm(0.95, sd=sqrt(v[-1])) Since the dataset has 100 observations, I end up with a vector v that comprises 3636 atomic components: (1 + 100) x (6 x 6). If I...
2018 Mar 28
0
"dlm" Package: Calculating State Confidence Intervals
...y trends). The model is saved in the object titled "mod." Following the example in the documentation and using the commands below, I am attempting to use the function "dlmSvd2var" to implement SVD and calculate the 90% confidence errors for each time-varying state. outF <- dlmFilter(y,mod) v <- unlist(dlmSvd2var(outF$U.C, outF$D.C)) pl <- dropFirst(outF$m) + qnorm(0.05, sd=sqrt(v[-1])) pu <- dropFirst(outF$m) + qnorm(0.95, sd=sqrt(v[-1])) Since the dataset has 100 observations, I end up with a vector v that comprises 3636 atomic components: (1 + 100) x (6 x 6). If I...