search for: dlmmle

Displaying 12 results from an estimated 12 matches for "dlmmle".

Did you mean: dlmglue
2012 May 25
1
question about TryCatch and lapply
Folks: I've replaced an outer for-loop with lapply and it works great. But, I can't seem to do the following type of exception handling: tryCatch(dlmMLE(x)$value==Inf,error = function(e) NULL) which basically says if the likelihood is Inf, throw an error. But what I want it to do is just go to the next index in the list. When I was using a for-loop I used: if(tryCatch(dlmMLE(x)$value==Inf,error = function(e) 1)==1) {next} else .... which worked...
2011 Jun 07
2
Setting up a State Space Model in dlm
...GG=diag(4), W=matrix(c(0,0,0,0, 0,0,0,0, 0,0,0.04,0, 0,0,0,0),4,4), V=exp(x[4]), m0=rep(0,4), C0=diag(1e07,4), JFF = t(matrix(c(1,1,0,0))), X=cbind( tvnairu.df$pilag, tvnairu.df$u)) return(modNAIRU) } (fitNAIRU <- dlmMLE(tvnairu.df$pi, parm=c(0,0,0,0) , build=buildNAIRU, hessian=TRUE, control=list(maxit=500))) (dlmNAIRU <- buildNAIRU(fitNAIRU$par)) ## Second attempt buildNAIRU <- function(x) { modNAIRU <- dlm(FF=t(matrix(c(1,1,0,0))), GG=diag(4), W=matrix(c(0,0,0,0,...
2014 Jan 08
0
Strange behaviour of `dlm` package
...954, 29659700, 31533579, 32513666, 33628559, 34494451)) plot(hotann, ylab="Annual hotel bookings") # Analysis with log data tsdata <- log(hotann) buildfun <- 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, l...
2009 Feb 15
0
Kalman Filter - dlm package
...W_t) = N(0,W) Y_ t is a univariate time series (1x1) F_t is a vector of factor returns (Kx1) Theta_t is the state vector (Kx1) G_t is the identity matrix My first challenge is to get the Maximum Likelihood estimators of V and W assuming they are time-invariant (homoscedastic) through the dlmMLE function. In the example provided in the user guide, F is the Identity matrix (diag(2)) and I would like to know how to adapt the coding such that F can vary over time and matches my case study described above. data(NelPlo) ### multivariate local level -- seemingly unrelated time series buil...
2011 Jun 03
0
Package dlm generates unstable results?
...+ noise(V),(no Intercept here) a_t = a_{t-1} + noise(W)   I first run the following code: (I shall provide data at the 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 v...
2012 May 09
1
Sweave, beamer and alert within code chunks
Hi all, Using Beamer, in order to highlight a piece of R code I do something like this - note the "\structure" and "\alert" commands: \begin{semiverbatim} > mleOut <- \structure{dlmMLE}(Nile, + parm = c(0.2, 120), # initial values for optimizer + lower = c(1e-7, 0)) \alert<2>{# V must be positive} > mleOut$convergence \alert<3>{# always check this!!!} [1] 0 \end{semiverbatim} How can I get a similar effect using Sweave? Thank yo...
2009 Mar 11
1
Forecasting with dlm
...setup my problem as follows, (following the manual as much as possible) data for example to run code CostUSD <- c(27.24031,32.97051, 38.72474, 22.78394, 28.58938, 49.85973, 42.93949, 35.92468) 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 e...
2011 Jun 30
0
Specifying State Space model to decompose structural shocks
...arameters to be estimated. I have also attached the paper that uses this specification. To specify above model in R, I am considering the dlm package, which suggests that multivariate series can be represented by combining two univariate expressions. First, I need to write a function and then use dlmMLE to estimate it. For example, I can start by writing a function x, which combines two univariate expressions: ab<-function(x) { dlmModPoly()%+%dlmModPoly() } fit<-dlmMLE(data, parm=c(....), build=ab) However, I am not sure how to write my model within this function. For instance, when I jus...
2009 May 10
1
Help with kalman-filterd betas using the dlm package
...tly 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://www.nabble.com/Help-with-kalman-filterd-betas-using-the-dlm-package-tp23473796p23473796.html Sent from the R help mailing list archive at Nabble.com.
2011 Jun 03
0
How to reconcile Kalman filter result (by package dlm) with linear regression?
...nction(x){  L1 = matrix(0,nFactor,nFactor)   L1[upper.tri(L1,T)] <- x[1:nMatrix]  return(dlm(   m0  = rep(0,nFactor),   C0  = diag(nFactor)*10,   FF  = 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.002412854...
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...
2011 Jul 29
0
dlmSum(...) and non-constant state space models
...= FALSE, + dV = exp(parm[8]), + dW = exp(parm[9]), + m0 = c(coef(pos)[2]), + C0 = diag(1)*10) + d <- rwdd + slpd+ + return(dlmSum(w, d))+ }> > > # estimate parameters> fit1 <- dlmMLE(y=cbind(pc[,4],pc[,2]),parm=c(rep(-2,9)),build=ssm1,hessian=T)Error in dlmSum(w, d) : Sum of dlm's is only implemented for constant models> -- Alan Fernihough IRCHSS Scholar UCD School of Economics [[alternative HTML version deleted]]