I am trying to make the following Kalman filter equations work and therefore 
produce their graphs.
v_t=y_t - a_t
a_t+1=a_t+K_t*v_t
F_t=P_t+sigma.squared.epsilon
P_t+1=P_t*(1-K_t)+sigma.squared.eta
K_t=P_t/F_t

Given:
a_1=0,P_1=10^7,sigma.squared.epsilon=15099,
sigma.squared.eta=1469.1

I have attached my code,which of course doesnt work.It produces NAs for the 
Fs,Ks and the a.
Can somebody tell me please what am I doing wrong in this loop?
Why doesnt this loop work as it should be;to produce  plots of a declining 
filtered state variance(P_t),prediction errors(v_t),and a declining prediction 
variance(F_t)?
Also,how can I construct and plot the 90% confidence intervals around a_t?
Thanks for your help and look forward.
Leonard


 
---------------------------------
It's here! Your new message!
Get new email alerts with the free Yahoo! Toolbar.
y<-(Nile)
  n.y<-length(y)
  P<-numeric(n.y)
  a<-numeric(n.y)
  i<-y
  P[1]<-10000000
  a[1]<-0
  n<-100
  sigma.2.epsilon<-15099
  sigma.2.eta<-1469.1
  nv <- matrix(nrow=100, ncol=1)
  F1<-P[1]+sigma.2.epsilon
  K <-P[1]/F1    
  for (i in 2:n-1){
  P[i+1]<-P[i]*(1-K[i])+sigma.2.eta
  F[i]<-P[i]+sigma.2.epsilon
  K[i]<-P[i]/F[i]
  nv[i]<-y[i]-a[i]
  a[i+1] <-a[i]+K[i]*nv[i]
  }
______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to