Re: [R] Kalman filter for a time series

2017-07-30 Thread Staff
Thanks David, that's the clue I needed.  Since x monotonically increases,
all I needed to do was:

ssModel = SSModel( t ~ SSMtrend(degree=1, Q=matrix(NA)), H=matrix(NA),
distribution="gaussian")





On Sun, Jul 30, 2017 at 10:11 AM, David Winsemius 
wrote:

>
> > On Jul 30, 2017, at 5:10 AM, Spencer Graves  effectivedefense.org> wrote:
> >
> >
> >
> > On 2017-07-29 11:26 PM, Staff wrote:
> >> I found an example at
> >> http://www.bearcave.com/finance/random_r_hacks/kalman_smooth.html
> >
> >  That example is signed by "Ian Kaplan".  There's a box at the
> bottom of the page for you to email him.
> >
> >> shown
> >> below.  But it seems the structSSM function has been removed from KFAS
> >> library
> >
> >  or it never was part of KFAS.  I don't know.
>
> It was part of KFAS. Searching with Google finds both the code as well as
> postings to Rhelp and Freelancer.com with requests (some for pay) to write
> replacements.
>
> >
> >> so it won't run.  Does anyone know how to fix the code so that it
> >> runs?
> >
> >  Have you tried the vignette with KFAS?
>
> Indeed. The section on structural time series implies that the
> functionality of the structSSM function has been replaced with three
> functions: SSMtrend, SSMcycle, and SSMseasonal.
>
> If you (meaning Staff, not Spencer) are not up to the task of making the
> transition to the new version of KFAS, then perhaps you should hire a
> consultant who can provide both code and sufficient documentation that you
> will be able to understand what is "under the hood".
>
> Best;
> David.
> >
> >
> >  Hope this helps.
> >  Spencer Graves
> >>
> >> library(KFAS)
> >> library(tseries)
> snipped
> >>
> >>  [[alternative HTML version deleted]]
> >>
> >> __
>
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'
>  -Gehm's Corollary to Clarke's Third Law
>
>
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Kalman filter for a time series

2017-07-30 Thread Staff
Exactly.  I'm doing:

x=c(1:length(t))
ssModel = SSModel( t~x, distribution="gaussian",H=NA)

but it is not plotting the Kalman filter line and not giving any errors.
I'm not sure what more the model needs?



On Sun, Jul 30, 2017 at 9:17 AM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> > structSSM
>
> Is no longer part of KFAS.  All you needed to do was:
>
> library(KFAS)
> ?KFAS
>
> and you would have seen that if you went to the index.  A structural state
> space model is now built up from its components,  much like in LM.   Look
> at;
>
> ?SSModel
>
> -Roy
>
> > On Jul 29, 2017, at 9:26 PM, Staff  wrote:
> >
> > I found an example at
> > http://www.bearcave.com/finance/random_r_hacks/kalman_smooth.html shown
> > below.  But it seems the structSSM function has been removed from KFAS
> > library so it won't run.  Does anyone know how to fix the code so that it
> > runs?
> >
> >
> >
> > library(KFAS)
> > library(tseries)
> > library(timeSeries)
> > library(zoo)
> > library(quantmod)
> >
> > getDailyPrices = function( tickerSym, startDate, endDate )
> > {
> >  prices = get.hist.quote( instrument = tickerSym, start = startDate,
> > end = endDate,
> >   quote="AdjClose", provider="yahoo",
> >   compression="d",  quiet=T)
> >
> >  prices.ts = ts(prices)
> >  return( prices.ts )
> > }
> >
> > kalmanFilter = function( x )
> > {
> >  t = x
> >  if (class(t) != "ts") {
> >t = ts(t)
> >  }
> >  ssModel = structSSM( y = t, distribution="Gaussian")
> >  ssFit = fitSSM(inits=c(0.5*log(var(t)), 0.5*log(var(t))), model =
> ssModel )
> >  kfs = KFS( ssFit$model, smoothing="state", nsim=length(t))
> >  vals = kfs$a
> >  lastVal = vals[ length(vals)]
> >  return(lastVal)
> > }
> >
> > Start = "2011-01-01"
> > End   = "2012-12-31"
> > SandP = "^GSPC"
> >
> > windowWidth = 20
> > tsLength = 100
> >
> > SAndP.ts = getDailyPrices( SandP, Start, End )
> > SAndP.ts = SAndP.ts[1:tsLength]
> > SAndP.smoothed = rollapply( data=SAndP.ts, width=windowWidth,
> FUN=kalmanFilter)
> >
> > par(mfrow=c(1,1))
> > prices = coredata( SAndP.ts[windowWidth:length(SAndP.ts)])
> > plot(prices, col="blue", type="l")
> > lines(coredata(SAndP.smoothed), col="magenta")
> > par(mfrow=c(1,1))
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> **
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Kalman filter for a time series

2017-07-30 Thread David Winsemius

> On Jul 30, 2017, at 5:10 AM, Spencer Graves 
>  wrote:
> 
> 
> 
> On 2017-07-29 11:26 PM, Staff wrote:
>> I found an example at
>> http://www.bearcave.com/finance/random_r_hacks/kalman_smooth.html
> 
>  That example is signed by "Ian Kaplan".  There's a box at the bottom of 
> the page for you to email him.
> 
>> shown
>> below.  But it seems the structSSM function has been removed from KFAS
>> library
> 
>  or it never was part of KFAS.  I don't know.

It was part of KFAS. Searching with Google finds both the code as well as 
postings to Rhelp and Freelancer.com with requests (some for pay) to write 
replacements. 

> 
>> so it won't run.  Does anyone know how to fix the code so that it
>> runs?
> 
>  Have you tried the vignette with KFAS?

Indeed. The section on structural time series implies that the functionality of 
the structSSM function has been replaced with three functions: SSMtrend, 
SSMcycle, and SSMseasonal.

If you (meaning Staff, not Spencer) are not up to the task of making the 
transition to the new version of KFAS, then perhaps you should hire a 
consultant who can provide both code and sufficient documentation that you will 
be able to understand what is "under the hood".

Best;
David.
> 
> 
>  Hope this helps.
>  Spencer Graves
>> 
>> library(KFAS)
>> library(tseries)
snipped
>> 
>>  [[alternative HTML version deleted]]
>> 
>> __

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Kalman filter for a time series

2017-07-30 Thread Roy Mendelssohn - NOAA Federal
> structSSM

Is no longer part of KFAS.  All you needed to do was:

library(KFAS)
?KFAS

and you would have seen that if you went to the index.  A structural state 
space model is now built up from its components,  much like in LM.   Look at;

?SSModel

-Roy

> On Jul 29, 2017, at 9:26 PM, Staff  wrote:
> 
> I found an example at
> http://www.bearcave.com/finance/random_r_hacks/kalman_smooth.html shown
> below.  But it seems the structSSM function has been removed from KFAS
> library so it won't run.  Does anyone know how to fix the code so that it
> runs?
> 
> 
> 
> library(KFAS)
> library(tseries)
> library(timeSeries)
> library(zoo)
> library(quantmod)
> 
> getDailyPrices = function( tickerSym, startDate, endDate )
> {
>  prices = get.hist.quote( instrument = tickerSym, start = startDate,
> end = endDate,
>   quote="AdjClose", provider="yahoo",
>   compression="d",  quiet=T)
> 
>  prices.ts = ts(prices)
>  return( prices.ts )
> }
> 
> kalmanFilter = function( x )
> {
>  t = x
>  if (class(t) != "ts") {
>t = ts(t)
>  }
>  ssModel = structSSM( y = t, distribution="Gaussian")
>  ssFit = fitSSM(inits=c(0.5*log(var(t)), 0.5*log(var(t))), model = ssModel )
>  kfs = KFS( ssFit$model, smoothing="state", nsim=length(t))
>  vals = kfs$a
>  lastVal = vals[ length(vals)]
>  return(lastVal)
> }
> 
> Start = "2011-01-01"
> End   = "2012-12-31"
> SandP = "^GSPC"
> 
> windowWidth = 20
> tsLength = 100
> 
> SAndP.ts = getDailyPrices( SandP, Start, End )
> SAndP.ts = SAndP.ts[1:tsLength]
> SAndP.smoothed = rollapply( data=SAndP.ts, width=windowWidth, 
> FUN=kalmanFilter)
> 
> par(mfrow=c(1,1))
> prices = coredata( SAndP.ts[windowWidth:length(SAndP.ts)])
> plot(prices, col="blue", type="l")
> lines(coredata(SAndP.smoothed), col="magenta")
> par(mfrow=c(1,1))
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Kalman filter for a time series

2017-07-30 Thread Spencer Graves



On 2017-07-29 11:26 PM, Staff wrote:

I found an example at
http://www.bearcave.com/finance/random_r_hacks/kalman_smooth.html



  That example is signed by "Ian Kaplan".  There's a box at the 
bottom of the page for you to email him.




shown
below.  But it seems the structSSM function has been removed from KFAS
library



  or it never was part of KFAS.  I don't know.



so it won't run.  Does anyone know how to fix the code so that it
runs?



  Have you tried the vignette with KFAS?


  Hope this helps.
  Spencer Graves


library(KFAS)
library(tseries)
library(timeSeries)
library(zoo)
library(quantmod)

getDailyPrices = function( tickerSym, startDate, endDate )
{
   prices = get.hist.quote( instrument = tickerSym, start = startDate,
end = endDate,
quote="AdjClose", provider="yahoo",
compression="d",  quiet=T)

   prices.ts = ts(prices)
   return( prices.ts )
}

kalmanFilter = function( x )
{
   t = x
   if (class(t) != "ts") {
 t = ts(t)
   }
   ssModel = structSSM( y = t, distribution="Gaussian")
   ssFit = fitSSM(inits=c(0.5*log(var(t)), 0.5*log(var(t))), model = ssModel )
   kfs = KFS( ssFit$model, smoothing="state", nsim=length(t))
   vals = kfs$a
   lastVal = vals[ length(vals)]
   return(lastVal)
}

Start = "2011-01-01"
End   = "2012-12-31"
SandP = "^GSPC"

windowWidth = 20
tsLength = 100

SAndP.ts = getDailyPrices( SandP, Start, End )
SAndP.ts = SAndP.ts[1:tsLength]
SAndP.smoothed = rollapply( data=SAndP.ts, width=windowWidth, FUN=kalmanFilter)

par(mfrow=c(1,1))
prices = coredata( SAndP.ts[windowWidth:length(SAndP.ts)])
plot(prices, col="blue", type="l")
lines(coredata(SAndP.smoothed), col="magenta")
par(mfrow=c(1,1))

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Kalman filter for a time series

2017-07-29 Thread Staff
I found an example at
http://www.bearcave.com/finance/random_r_hacks/kalman_smooth.html shown
below.  But it seems the structSSM function has been removed from KFAS
library so it won't run.  Does anyone know how to fix the code so that it
runs?



library(KFAS)
library(tseries)
library(timeSeries)
library(zoo)
library(quantmod)

getDailyPrices = function( tickerSym, startDate, endDate )
{
  prices = get.hist.quote( instrument = tickerSym, start = startDate,
end = endDate,
   quote="AdjClose", provider="yahoo",
   compression="d",  quiet=T)

  prices.ts = ts(prices)
  return( prices.ts )
}

kalmanFilter = function( x )
{
  t = x
  if (class(t) != "ts") {
t = ts(t)
  }
  ssModel = structSSM( y = t, distribution="Gaussian")
  ssFit = fitSSM(inits=c(0.5*log(var(t)), 0.5*log(var(t))), model = ssModel )
  kfs = KFS( ssFit$model, smoothing="state", nsim=length(t))
  vals = kfs$a
  lastVal = vals[ length(vals)]
  return(lastVal)
}

Start = "2011-01-01"
End   = "2012-12-31"
SandP = "^GSPC"

windowWidth = 20
tsLength = 100

SAndP.ts = getDailyPrices( SandP, Start, End )
SAndP.ts = SAndP.ts[1:tsLength]
SAndP.smoothed = rollapply( data=SAndP.ts, width=windowWidth, FUN=kalmanFilter)

par(mfrow=c(1,1))
prices = coredata( SAndP.ts[windowWidth:length(SAndP.ts)])
plot(prices, col="blue", type="l")
lines(coredata(SAndP.smoothed), col="magenta")
par(mfrow=c(1,1))

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] Kalman Filter Forecast using 'SSPIR'

2012-12-02 Thread rahul143
Dear R Users, 

  

  I am new to state-space modeling. I am using SSPIR 
package for Kalman Filter. I have a data set containing one dependent 
variable and 7 independent variables with 250 data points. I want to use 
Kalman Filter for forecast the future values of the dependent variable 
using a multiple regression framework. I have used ssm function to 
produce the state space (SS) object, but I am bit confused that how can 
I predict the future values. 

  

Thanks a lot in advance. 

  



-
   TO GET MORE DETAILS CLICK HERE  





--
View this message in context: 
http://r.789695.n4.nabble.com/Kalman-Filter-Forecast-using-SSPIR-tp4651666.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


[R] Kalman Filter with dlm

2011-11-18 Thread Pearl
I have built a Kalman Filter model for flu forecasting as shown below. 

Y - Target Variable X1 - Predictor1 X2 - Predictor2 

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) + dlmModReg(pred, dV=0.5, dW=c(10,0.05,0.1)) 
Y.filter  <- dlmFilter(c(train$Y, rep(NA, noofsteps)), Y.model)   

I have two questions 

1) The flu season usually starts in early September and it usually peaks
during the last week of December or the first week of January. The following
are the stages 

Stage1 - September, October 
Stage2 - November, December 
Stage3 - January, February 
Stage4 - March, April 

The dlmModSeas captures this seasonality very well. But what do I do to
forecast an off season wave that has the same stages as above. Say it starts
in May and it peaks at end of August or early September. I am able to get
the information of this off season wave from the user during the start, i.e.
in May. How do I introduce this change in seasonality, I think I have to
change $JGG and introduce $X but I am not sure how to do it. Please help. 

2) Is there a better way to do this forecasting? Please Advise

--
View this message in context: 
http://r.789695.n4.nabble.com/Kalman-Filter-with-dlm-tp4084675p4084675.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Kalman Filter Estimation

2011-06-24 Thread Dennis Murphy
Hi:

Here are a couple of places to start:

http://www.jstatsoft.org/v39/i02/paper
http://stats.stackexchange.com/questions/4296/r-code-for-time-series-forecasting-using-kalman-filter

HTH,
Dennis

On Fri, Jun 24, 2011 at 6:24 AM, Patrick  wrote:
> Dear R users,
>
> I am a new R user and not very experienced in Statistics. I would like to
> regress a time series variable y on several other time series variables x. I
> read that the Kalman Filter would provide me with a better fit for my
> estimation. However, I have no idea how to translate this simple regression
> into a State-Based Model and how to do the estimation of the regression
> parameters with R. I hope that somebody can help me.
>
> Kind Regards,
> Patrick
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Kalman-Filter-Estimation-tp3622518p3622518.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org 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.
>

__
R-help@r-project.org 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.


[R] Kalman Filter Estimation

2011-06-24 Thread Patrick
Dear R users,

I am a new R user and not very experienced in Statistics. I would like to
regress a time series variable y on several other time series variables x. I
read that the Kalman Filter would provide me with a better fit for my
estimation. However, I have no idea how to translate this simple regression
into a State-Based Model and how to do the estimation of the regression
parameters with R. I hope that somebody can help me.

Kind Regards,
Patrick

--
View this message in context: 
http://r.789695.n4.nabble.com/Kalman-Filter-Estimation-tp3622518p3622518.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


[R] Kalman filter

2010-12-02 Thread Santiago Ramos

I can say is used as filter Kalman

thanks

Cordialmente,
 
JAVIER SANTIAGO PARRA RAMOS

INGENIERO DE SISTEMAS
ESP. EN GERENCIA DE SISTEMAS INFORMATICOS
CEL: (57) 313 416 71 21

 






  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Kalman filter

2010-11-22 Thread David Stoffer

It sounds like you've looked at the DLM, DSE, and SSPIR packages.  If not,
then certainly check them out.  Also, we have code for filtering, smoothing
and estimation in our text- go to www.stat.pitt.edu/stoffer/tsa3/ and look
at the code for chapter 6.  There's not a package for the text, but all the
code is in a compressed file that you can download.  The examples are
discussed in detail in the text, but I think looking at the code (and
Appendix R on the site) will be sufficient to set up your problem.

David



Garten Stuhl wrote:
> 
> Hello,
> 
> 
> 
> I have completed my kalman filter problem with more details.
> 
> 
> 
> The transition- and the measurement equation is given by
> 
> 
> 
> x[t]=A[t]*x[t-1]+B[t]*epsilon[t]
> 
> y[t]=C[t]*x[t]+eta[t]
> 
> 
> 
> A, y, B and C are Matrices. Y[t] is the data input vector with 800
> elements
> (every t has one element)
> 
> 
> 
> My Model is described by the following
> (discretisation)
> stochastic differential equation
> 
> 
> 
> Lambda[t]=lambda[t-1]+kappa*lambda[t]*delta_t+epsilon_l
> 
> R[t]=R[t-1]+mu*delta_t+epsilon_r
> 
> epsilon_l=sigma_l*sqroot(delta_t)
> 
> epsilon_r=sigma_r*sqroot(delta_t)
> 
> 
> 
> Ln(S[t])=lambda[t]+R[t]
> 
> 
> 
> The paramters for estimation are:
> 
> kappa
> 
> mu
> 
> sigma_l
> 
> sigma_r
> 
> 
> 
> The state-space-model for this problem is:
> 
> 
> 
> x[t]=(lambda[t], R[t])’
> 
> A[t]=(1-kappa+delta_t, 0; 0, 1+mu)
> 
> B[t]=(1,0;0,1)
> 
> epsilon[t]=(epsilon_l, epsilon_r)’
> 
> C[t]=(1,1)
> 
> Eta[t]=0
> 
> 
> 
> I used serveral alternative methods (dlm, kalmanLike, fkf, kfilter) for
> parameter estimation but I don’t understand the syntax and the correct
> input
> for model estimation.
> 
> 
> 
> Can anybody help me, which packed is the most best for my problem and how
> is
> it to control?
> 
> 
> 
> Thanks for helping.
> 
> 
> 
> Best,
> 
> Thomas
> 
>   [[alternative HTML version deleted]]
> 
> 
> __
> R-help@r-project.org 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.
> 
> 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Kalman-filter-tp3049591p3054858.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Kalman filter

2010-11-20 Thread Stefano Sofia
Federico,
as far as I understand Kalman filter works under gaussian conditions, and for 
this reason it is not implemented. (I have to admit that I do not know the 
sspir package)

hope this helps, and correct me if I am wrong
Best regards
Stefano Sofia PhD

On 11/17/2010 11:49 AM, feder wrote:
> Hi,
> I used sspir for managing non-gaussian State space models but I observed
> that for such models only the smoother is gave while the filter is missing.
> Why?

AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu? contenere 
informazioni confidenziali, pertanto ? destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
? il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si ? ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell'art. 6 della  DGR n. 1394/2008 si segnala che, in caso di necessit? ed 
urgenza, la risposta al presente messaggio di posta elettronica pu? essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.

__
R-help@r-project.org 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.


[R] Kalman filter

2010-11-18 Thread Garten Stuhl
Hello,



I have completed my kalman filter problem with more details.



The transition- and the measurement equation is given by



x[t]=A[t]*x[t-1]+B[t]*epsilon[t]

y[t]=C[t]*x[t]+eta[t]



A, y, B and C are Matrices. Y[t] is the data input vector with 800 elements
(every t has one element)



My Model is described by the following
(discretisation)
stochastic differential equation



Lambda[t]=lambda[t-1]+kappa*lambda[t]*delta_t+epsilon_l

R[t]=R[t-1]+mu*delta_t+epsilon_r

epsilon_l=sigma_l*sqroot(delta_t)

epsilon_r=sigma_r*sqroot(delta_t)



Ln(S[t])=lambda[t]+R[t]



The paramters for estimation are:

kappa

mu

sigma_l

sigma_r



The state-space-model for this problem is:



x[t]=(lambda[t], R[t])’

A[t]=(1-kappa+delta_t, 0; 0, 1+mu)

B[t]=(1,0;0,1)

epsilon[t]=(epsilon_l, epsilon_r)’

C[t]=(1,1)

Eta[t]=0



I used serveral alternative methods (dlm, kalmanLike, fkf, kfilter) for
parameter estimation but I don’t understand the syntax and the correct input
for model estimation.



Can anybody help me, which packed is the most best for my problem and how is
it to control?



Thanks for helping.



Best,

Thomas

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] kalman filter in sspir

2010-11-18 Thread Spencer Graves
  To learn why sspir does not have a filter function, you need to 
ask the package maintainer,  Claus Dethlefsen .  My belief is 
that he, Soren Lundbye-Christensen and Anette Luther Christensen found 
other outlets for their time since they completed the package and the 
companion paper, "C. Dethlefsen and S. Lundbye-Christensen. Formulating 
state space models in r with focus on longitudinal regression models. 
Journal of Statistical Software, 16(1), 2006."



  R works on volunteers.  If you know someone willing and able to 
write such a function, I suggest you contact Dethlefsen to see if they 
are willing to put the package on R-Forge and permit others to 
contribute to the package.  If they decline, you can create your own 
package, e.g., "sspirPlus", that would add the desired filter function.



  Hope this helps.
  Spencer


On 11/17/2010 11:49 AM, feder wrote:

Hi,
I used sspir for managing non-gaussian State space models but I observed
that for such models only the smoother is gave while the filter is missing.
Why?


__
R-help@r-project.org 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.


[R] kalman filter in sspir

2010-11-17 Thread feder

Hi,
I used sspir for managing non-gaussian State space models but I observed
that for such models only the smoother is gave while the filter is missing.
Why? 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/kalman-filter-in-sspir-tp3047486p3047486.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2010-11-15 Thread John Kerpel
Try the most excellent package dlm written by Giovanni Petris for your all
your Kalman filter needs.  Also buy the accompanying book - it really
integrates the dlm package with the theory behind it.

Best,

John

On Mon, Nov 15, 2010 at 8:39 AM, Garten Stuhl
wrote:

> Hello,
>
>
>
> thanks for answer my Question. I prefer use KalmanLike(y, mod, nit = 0,
> fast=TRUE). For parameter estimating I have a given time series. In these
> are several components: Season and noise; furthermore it gives a mean
> reversion process. The season is modelled as a fourierpolynom. From the
> given time series I have to estimate the
>
> - Season parameters
>
> - The mean reversion factor
>
> - variance from the noise
>
>
>
> I think in the function KalmanLike y is the vector of the time series; what
> does "mod" mean? How can I write the syntax for the state space?
>
>
>
> Have anybody a simple example for better understanding KalmanLike. Or is it
> better to use  other packages for parameter estimating?
>
>
>
> I have no experience in work with Kalman filters and I'm a new R user.
>
>
>
> Thanks for helping.
>
>
>
> Best,
>
> Thomas
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2010-11-15 Thread Garten Stuhl
Hello,



thanks for answer my Question. I prefer use KalmanLike(y, mod, nit = 0,
fast=TRUE). For parameter estimating I have a given time series. In these
are several components: Season and noise; furthermore it gives a mean
reversion process. The season is modelled as a fourierpolynom. From the
given time series I have to estimate the

- Season parameters

- The mean reversion factor

- variance from the noise



I think in the function KalmanLike y is the vector of the time series; what
does "mod" mean? How can I write the syntax for the state space?



Have anybody a simple example for better understanding KalmanLike. Or is it
better to use  other packages for parameter estimating?



I have no experience in work with Kalman filters and I'm a new R user.



Thanks for helping.



Best,

Thomas

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] kalman filter

2010-11-14 Thread gpetris


Hi,

There are a few packages that I would suggest to run Kalman filter.  
Take a look at dlm and KFAS. If you need more help you should be more  
precise in formulating your problem, providing a small example, as  
required by the posting guide.


Best,
Giovanni Petris

Quoting Garten Stuhl :


Hello,



I would like use Kalman filter for estimating parameters of a stochastic
model. I have developed the state space model but I don’t know the correct
way use Kalman filter for parameter estimation. Has anybody experience in
work with Kalman filter in R.



I don’t know the correct function. Maybe it is



-  KalmanLike; but what is the correct Input?

-  tsmooth?

-  kfilter?



Thanks for helping.



I have ask the same question in the help list “sig-dynamic-models”



Best,

Thomas

[[alternative HTML version deleted]]




__
R-help@r-project.org 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.


[R] kalman filter

2010-11-14 Thread Garten Stuhl
Hello,



I would like use Kalman filter for estimating parameters of a stochastic
model. I have developed the state space model but I don’t know the correct
way use Kalman filter for parameter estimation. Has anybody experience in
work with Kalman filter in R.



I don’t know the correct function. Maybe it is



-  KalmanLike; but what is the correct Input?

-  tsmooth?

-  kfilter?



Thanks for helping.



I have ask the same question in the help list “sig-dynamic-models”



Best,

Thomas

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Kalman filter

2010-08-13 Thread Spencer Graves
Other terms for Kalman filtering, prediction and smoothing are 
"state space modeling" and "dynamic linear models".


   Consider the following extension of Ben Bolker's suggestion to 
use the 'sos' package:


library(sos)
k <- ???Kalman
ss <- findFn('state space')
dlm <- findFn('dynamic linear model')
dlms <- findFn('dynamic linear models')
# NOT necessarily a subset of dlm
ksd <- (k | ss | dlm | dlms)
# union of the above 4
installPackages(ksd)
# Install the primary packages to get addition info for writeFindFn2xls
writeFindFn2xls(ksd)
getwd() # directory containing ksd.xls


   The first sheet of "ksd.xls" provides a one-line summary of the 
packages including date last updated, any vignettes, etc.  This file 
says that "ksd" found 31 matches in the "dse" package by Paul Gilbert, 
who has been a major contributor in this area for many years, using his 
own code at the Bank of Canada.  I have not used the second and third 
packages, expsmooth and MARSS, so I can't speak about them.  However, 
the next package is "dlm", for which a companion book appeared just over 
a year ago;  I've found it very powerful and relatively easy to use.  If 
your response variables are something other than the a linear 
combination of components of the state vector plus normal noise, then I 
suggest you consider the "sspir" package, which is number 6 on this list 
in terms of the number of help pages matching the search terms.


   Hope this helps.
   Spencer Graves


On 8/13/2010 2:06 PM, Bruno Mourato wrote:
> Take a look on this
>
> Packages:
>
> - KFTRACK
> - UKFSST
> - TRACKIT
>
>
>
> 2010/8/13 FMH
>
>> Dear All,
>>
>> Could anyone give me a hand to suggest few packages in R to running Kalman
>> prediction and filtration ?
>>
>> Thanks
>> Fir
>>
>>
>>
>>
>> __
>> R-help@r-project.org 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.
>>
>
>
>
> __
> R-help@r-project.org 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.

-- 
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Kalman filter

2010-08-13 Thread Bruno Mourato
Take a look on this

Packages:

- KFTRACK
- UKFSST
- TRACKIT



2010/8/13 FMH 

> Dear All,
>
> Could anyone give me a hand to suggest few packages in R to running Kalman
> prediction and filtration ?
>
> Thanks
> Fir
>
>
>
>
> __
> R-help@r-project.org 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.
>



-- 
<:(<___<:<___<:<

Bruno L. Mourato, Ph.D student

Pacific Islands Fisheries Science Center - PIFSC
National Marine Fisheries Service - NMFS
2570 Dole Street, Honolulu, Hawaii, US, 96822
Phone: 808-983-5317

Universidade Federal Rural de  Pernambuco - UFRPE
Departmento de Pesca e Aquicultura - DEPAq
Laboratório de Oceanografia Pesqueira - LOP
End: R. Dom Manoel de Medeiros, s/n - Dois Irmãos
52171-900 - Recife-PE, Brazil  Tel: 81 - 3320-6512

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Kalman filter

2010-08-13 Thread Ben Bolker
FMH  yahoo.com> writes:

> 
> Dear All,
> 
> Could anyone give me a hand to suggest few packages in R to running Kalman 
> prediction and filtration ?

  Teach a person to fish ...

 install.packages("sos")
library(sos)
findFn("kalman")

   ## perhaps this could be added to the posting guide?

__
R-help@r-project.org 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.


[R] Kalman filter

2010-08-13 Thread FMH
Dear All,

Could anyone give me a hand to suggest few packages in R to running Kalman 
prediction and filtration ?

Thanks
Fir




__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2010-05-30 Thread Johann Hibschman
Greigiano Jose Alves  writes:

> I am working on an article forecasting, which use the dynamic linear model,
> a model state space. I am wondering all the commands in R, to represent the
> linear dynamic model and Kalman filter.
> I am available for any questions.

There are a few libraries out there, available on CRAN:

  - dlm
  - dse
  - sspir

I tend to use dlm, myself.

Best of luck,
Johann

__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2010-05-26 Thread Giovanni Petris

To find out what tools are available in R, you can check out the Time
Series task view on CRAN:

http://cran.r-project.org/web/views/TimeSeries.html

My personal preference is for package dlm, but here I am probably
biased.

[discaimer: the following is a sponsored link]

For more information on DLMs in R:

http://www.springer.com/978-0-387-77237-0

Best,
Giovanni

On Tue, 2010-05-25 at 15:23 -0300, Greigiano Jose Alves wrote:
> Hello
> My name is greigiano am student of Applied Economics, Department of Rural
> Economy.
> I am working on an article forecasting, which use the dynamic linear model,
> a model state space. I am wondering all the commands in R, to represent the
> linear dynamic model and Kalman filter.
> I am available for any questions.
> 


-- 
Giovanni Petris  
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
R-help@r-project.org 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.


[R] Kalman Filter

2010-05-25 Thread Greigiano Jose Alves
Hello
My name is greigiano am student of Applied Economics, Department of Rural
Economy.
I am working on an article forecasting, which use the dynamic linear model,
a model state space. I am wondering all the commands in R, to represent the
linear dynamic model and Kalman filter.
I am available for any questions.

-- 
DEUS Seja Louvado
Que ELE Ilumine sua vida
Assim como ELE tem Iluminado a Minha

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Kalman Filter - dlm package

2009-02-15 Thread g.amo
Dear all,

 

I am currently trying to use the "dlm" package for Kalman filtering.

 

My model is very simple:

 

Y_t = F'_t Theta_t + v_t

Theta_t = G_t Theta_t-1 + w_t

 

v_t ~ N(0,V_t) = N(0,V)

w_t ~ N(0,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

buildSu <- function(x) {

Vsd <- exp(x[1:2])

Vcorr <- tanh(x[3])

V <- Vsd %o% Vsd

V[1,2] <- V[2,1] <- V[1,2] * Vcorr

Wsd <- exp(x[4:5])

Wcorr <- tanh(x[6])

W <- Wsd %o% Wsd

W[1,2] <- W[2,1] <- W[1,2] * Wcorr

return(list(

m0 = rep(0,2),

C0 = 1e7 * diag(2),

FF = diag(2),

GG = diag(2),

V = V,

W = W))

}

suMLE <- dlmMLE(NelPlo, rep(0,6), buildSu); suMLE

buildSu(suMLE$par)[c("V","W")]

 

Thanking you in advance for your help,

 

Gerardo Amo


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2008-11-03 Thread Giovanni Petris

> Date: Fri, 31 Oct 2008 16:39:32 +0100
> From: Sandrine LUNVEN <[EMAIL PROTECTED]>
> Sender: [EMAIL PROTECTED]
> Importance: Normal
> Precedence: list
> 
> 
> 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...

What do you mean, "it doesn't work"? Could you provide an example
substantiating your claim? What would you expect to obtain instead? 

> 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
> 
> __
> R-help@r-project.org 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.
  ^

Please do so. It makes much more easy to understand and answer your
questions. 

Best,
Giovanni Petris

-- 

Giovanni Petris  <[EMAIL PROTECTED]>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
R-help@r-project.org 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.


[R] Kalman Filter

2008-10-31 Thread Sandrine LUNVEN

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

__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2008-03-04 Thread David Stoffer

Vladimir- there are at least 3 packages that will facilitate state space
modeling: 
http://cran.r-project.org/src/contrib/Descriptions/dlm.html DLM ,
http://cran.r-project.org/src/contrib/Descriptions/dse.html DSE , and
http://cran.r-project.org/src/contrib/Descriptions/sspir.html SSPIR .

In addition, I have scripts and examples for fitting state space models and
running
the Kalman filter and smoother for Chapter 6 of our text,  
http://www.stat.pitt.edu/stoffer/tsa2/ tsa2 .  Go to "R CODE (Ch 6)" using
the
blue bar at the top.  There you will find the scripts and examples.  If you
have any
questions, feel free to contact me.


Vladimír Šamaj wrote:
> 
> Hi
> 
> My name is Vladimir Samaj. I am a student of Univerzity of Zilina. I am
> trying to implement Kalman Filter into my school work. I have some
> problems
> with understanding of R version of Kalman Filter in package stats(
> functions
> KalmanLike, KalmanRun, KalmanSmooth,KalmanForecast).
> 
> 1) Can you tell me how are you seting the initial values of state vector
> in
> Kalman Filter? Are you using some method?
> 
> 2) I have fond function StructTS in stats package. I dont understand, how
> exactly, are you computing(what method are you using) fitted values which
> are the output of this function( $fitted ) . In description od this
> function
> is that it fit a structural model for a time series by maximum likehood.
> Does it means, that the fitted values are fit by maximum likehood? If so
> how
> does look the likehood function?
> 
> 3)Finaly, I dont understand smooting problem.  What I know is that, if I
> have t observations of some time serie, I can use  function KalmanRun to
> get
> estimates of state vector. And if I gain aditional observations of time
> serie( T > t ), I shoud use KalmanSmooth function to smooth estimates of
> state vector. I dont understand, that how shoud I "tell" to KalmanSmooth
> funtion that I allready did filtering and it shoud use the values from
> filtering to smoothing.
> 
> I will be glad if you help me. I hope that my folmulations were correct.
> 
> Thank you very much.
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org 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.
> 
> 


-
The power of accurate observation is commonly called cynicism 
by those who have not got it.  George Bernard Shaw
-- 
View this message in context: 
http://www.nabble.com/Kalman-Filter-tp15696135p15826374.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Kalman Filter

2008-02-26 Thread Spencer Graves
  Have you looked at the 'dlm' package?  It has a vignette to help 
you learn to use it.  Also, I've heard that a book about that package is 
scheduled to appear in the next few months. 

  I have looked at the Kalman functions in the 'stats' package but 
have not found documentation that seemed sufficient to get me started 
using it. 

  RSiteSearch('Kalman', 'fun') produced 48 hits for me just now.  If 
you don't find what you want with 'dlm' (and maybe even if you do), you 
may wish to examine that list, if you haven't already. 

  Hope this helps. 
  Spencer

Vladimír Šamaj wrote:
> Hi
>
> My name is Vladimir Samaj. I am a student of Univerzity of Zilina. I am
> trying to implement Kalman Filter into my school work. I have some problems
> with understanding of R version of Kalman Filter in package stats( functions
> KalmanLike, KalmanRun, KalmanSmooth,KalmanForecast).
>
> 1) Can you tell me how are you seting the initial values of state vector in
> Kalman Filter? Are you using some method?
>
> 2) I have fond function StructTS in stats package. I dont understand, how
> exactly, are you computing(what method are you using) fitted values which
> are the output of this function( $fitted ) . In description od this function
> is that it fit a structural model for a time series by maximum likehood.
> Does it means, that the fitted values are fit by maximum likehood? If so how
> does look the likehood function?
>
> 3)Finaly, I dont understand smooting problem.  What I know is that, if I
> have t observations of some time serie, I can use  function KalmanRun to get
> estimates of state vector. And if I gain aditional observations of time
> serie( T > t ), I shoud use KalmanSmooth function to smooth estimates of
> state vector. I dont understand, that how shoud I "tell" to KalmanSmooth
> funtion that I allready did filtering and it shoud use the values from
> filtering to smoothing.
>
> I will be glad if you help me. I hope that my folmulations were correct.
>
> Thank you very much.
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.
>

__
R-help@r-project.org 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.


[R] Kalman Filter

2008-02-26 Thread Vladimír Šamaj
Hi

My name is Vladimir Samaj. I am a student of Univerzity of Zilina. I am
trying to implement Kalman Filter into my school work. I have some problems
with understanding of R version of Kalman Filter in package stats( functions
KalmanLike, KalmanRun, KalmanSmooth,KalmanForecast).

1) Can you tell me how are you seting the initial values of state vector in
Kalman Filter? Are you using some method?

2) I have fond function StructTS in stats package. I dont understand, how
exactly, are you computing(what method are you using) fitted values which
are the output of this function( $fitted ) . In description od this function
is that it fit a structural model for a time series by maximum likehood.
Does it means, that the fitted values are fit by maximum likehood? If so how
does look the likehood function?

3)Finaly, I dont understand smooting problem.  What I know is that, if I
have t observations of some time serie, I can use  function KalmanRun to get
estimates of state vector. And if I gain aditional observations of time
serie( T > t ), I shoud use KalmanSmooth function to smooth estimates of
state vector. I dont understand, that how shoud I "tell" to KalmanSmooth
funtion that I allready did filtering and it shoud use the values from
filtering to smoothing.

I will be glad if you help me. I hope that my folmulations were correct.

Thank you very much.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] kalman filter random walk

2007-12-05 Thread Giovanni Petris

You may want to look at package dlm.

Giovanni

> Date: Wed, 05 Dec 2007 12:05:00 -0600
> From: Alexander Moreno <[EMAIL PROTECTED]>
> Sender: [EMAIL PROTECTED]
> Precedence: list
> 
> Hi,
> 
> I'm trying to use the kalman filter to estimate the variable drift of a
> random walk, given that I have a vector of time series data.  Anyone have
> any thoughts on how to do this in R?
> 
> Thanks,
> Alex
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org 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.
> 
> 

-- 

Giovanni Petris  <[EMAIL PROTECTED]>
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
R-help@r-project.org 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.


Re: [R] kalman filter random walk

2007-12-05 Thread Roy Mendelssohn
sspir or ldm.

-Roy M.


On Dec 5, 2007, at 10:05 AM, Alexander Moreno wrote:

> Hi,
>
> I'm trying to use the kalman filter to estimate the variable drift  
> of a
> random walk, given that I have a vector of time series data.   
> Anyone have
> any thoughts on how to do this in R?
>
> Thanks,
> Alex
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org 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.

**
"The contents of this message do not reflect any position of the U.S.  
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division 
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: [EMAIL PROTECTED] (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."

__
R-help@r-project.org 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.


[R] kalman filter random walk

2007-12-05 Thread Alexander Moreno
Hi,

I'm trying to use the kalman filter to estimate the variable drift of a
random walk, given that I have a vector of time series data.  Anyone have
any thoughts on how to do this in R?

Thanks,
Alex

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] kalman filter estimation

2007-11-15 Thread Giovanni Petris

Kalman filter for general state space models, especially in its naive
version, is known for its numerical instability.  This is the reason
why people developed square root filters, based on Cholesky
decomposition of variance matrices. In package dlm the implementation
of Kalman filter is based on the singular value decomposition (SVD) of
the relevant variance matrices, providing for a more robust algorithm
than the standard square root filter.


The lack of convergence of optimization algorithms in finding MLEs of
unknown parameters is not surprising to me, especially if you have
many parameters. When using state space models it is easy to end up
with a fairly flat, or multimodal likelihood function. These are two
signs of poor identifiability of the model. You can live with it, but
be aware that it is there. My suggestion is to start the optimization
from several different initial values and compare maximized values of
the likelihood. Simulated annealing may be used to better explore the
parameter space. 

HTH,
Giovanni



> Date: Thu, 15 Nov 2007 04:41:26 + (GMT)
> From: [EMAIL PROTECTED]
> Sender: [EMAIL PROTECTED]
> Priority: normal
> Precedence: list
> 
> Hi,
> 
> Following convention below:
> y(t) = Ax(t)+Bu(t)+eps(t) # observation eq
> x(t) = Cx(t-1)+Du(t)+eta(t) # state eq
> 
> I modified the following routine (which I copied from: 
> http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an 
> exogenous input to the system. 
> 
> for (i in 2:N){
>  xp[[i]]=C%*%xf[[i-1]]
>  Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q
>siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R
>  sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric
>siginv=solve(sig[[i]])  # now siginv is sig[[i]]^{-1}
>  K=Pp[[i]]%*%t(A[[i]])%*%siginv
>  innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]]
>  xf[[i]]=xp[[i]]+K%*%innov[[i]]
>  Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]]
>  like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]]
>  }
>like=0.5*like
>list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K)
> }
> 
> I tried to fit my problem and observe that I got positive log likelihood 
> mainly because the log of determinant of my variance matrix is largely 
> negative. That's not good because they should be positive. Have anyone 
> experience this kind of instability?
> 
> Also, I realize that I have about 800 sample points. The above routine when 
> being plugged to optim becomes very slow. Could anyone share a faster way to 
> compute kalman filter? 
> 
> And my last problem is, optim with my defined feasible space does not 
> converge. I have about 20 variables that I need to identify using MLE method. 
> Is there any other way that I can try out? I tried most of the methods 
> available in optim already. They do not converge at all.. Thank you.
> 
> - adschai
> 
> __
> R-help@r-project.org 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.
> 
> 

-- 

Giovanni Petris  <[EMAIL PROTECTED]>
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
R-help@r-project.org 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.


Re: [R] kalman filter estimation

2007-11-15 Thread Giovanni Petris

> > You can live with it, but
> > be aware that it is there. My suggestion is to start the optimization
> > from several different initial values and compare maximized values of
> > the likelihood. Simulated annealing may be used to better explore the
> > parameter space. 
> 
> Yes.  Are you aware of any work on this in R?
> 
> Paul

The function dlmMLE in package dlm calls optim to find maximum
likelihood estimates. You can pass additional arguments to optim,
including method = "SANN" for simulated annealing.

Giovanni

__
R-help@r-project.org 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.


Re: [R] kalman filter estimation

2007-11-15 Thread Paul Gilbert


Giovanni Petris wrote:
> Kalman filter for general state space models, especially in its naive
> version, is known for its numerical instability.  This is the reason
> why people developed square root filters, based on Cholesky
> decomposition of variance matrices. In package dlm the implementation
> of Kalman filter is based on the singular value decomposition (SVD) of
> the relevant variance matrices, providing for a more robust algorithm
> than the standard square root filter.
> 
> 
> The lack of convergence of optimization algorithms in finding MLEs of
> unknown parameters is not surprising to me, especially if you have
> many parameters. When using state space models it is easy to end up
> with a fairly flat, or multimodal likelihood function. These are two
> signs of poor identifiability of the model. 

Lack of identification makes things worse, but these problems can occur 
even when the model is identified. The problem is actually worse then 
what you indicate. There can be large regions of parameter space where 
the likelihood increases as parameters diverge to infinity. This was the 
basis of the literature on chart switching procedures. Also, it is not 
so much the number of parameters that cause the problem as it is the 
dimension of the output (though they tend to be related). A univariate 
model with a large state is usually not too bad if it is identified and 
there is enough data. However, multiple series can cause problems even 
with relatively few parameters.

You can live with it, but
> be aware that it is there. My suggestion is to start the optimization
> from several different initial values and compare maximized values of
> the likelihood. Simulated annealing may be used to better explore the
> parameter space. 

Yes.  Are you aware of any work on this in R?

Paul
> 
> HTH,
> Giovanni
> 
> 
> 
> 
>>Date: Thu, 15 Nov 2007 04:41:26 + (GMT)
>>From: [EMAIL PROTECTED]
>>Sender: [EMAIL PROTECTED]
>>Priority: normal
>>Precedence: list
>>
>>Hi,
>>
>>Following convention below:
>>y(t) = Ax(t)+Bu(t)+eps(t) # observation eq
>>x(t) = Cx(t-1)+Du(t)+eta(t) # state eq
>>
>>I modified the following routine (which I copied from: 
>>http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an 
>>exogenous input to the system. 
>>
>>for (i in 2:N){
>> xp[[i]]=C%*%xf[[i-1]]
>> Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q
>>   siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R
>> sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric
>>   siginv=solve(sig[[i]])  # now siginv is sig[[i]]^{-1}
>> K=Pp[[i]]%*%t(A[[i]])%*%siginv
>> innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]]
>> xf[[i]]=xp[[i]]+K%*%innov[[i]]
>> Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]]
>> like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]]
>> }
>>   like=0.5*like
>>   list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K)
>>}
>>
>>I tried to fit my problem and observe that I got positive log likelihood 
>>mainly because the log of determinant of my variance matrix is largely 
>>negative. That's not good because they should be positive. Have anyone 
>>experience this kind of instability?
>>
>>Also, I realize that I have about 800 sample points. The above routine when 
>>being plugged to optim becomes very slow. Could anyone share a faster way to 
>>compute kalman filter? 
>>
>>And my last problem is, optim with my defined feasible space does not 
>>converge. I have about 20 variables that I need to identify using MLE method. 
>>Is there any other way that I can try out? I tried most of the methods 
>>available in optim already. They do not converge at all.. Thank you.
>>
>>- adschai
>>
>>__
>>R-help@r-project.org 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.
>>
>>
> 
> 


La version française suit le texte anglais.



This email may contain privileged and/or confidential information, and the Bank 
of
Canada does not waive any related rights. Any distribution, use, or copying of 
this
email or the information it contains by other than the intended recipient is
unauthorized. If you received this email in error please delete it immediately 
from
your system and notify the sender promptly by email that you have done so. 



Le présent courriel peut contenir de l'information privilégiée ou 
confidentielle.
La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute 
diffusion,
utilisation ou copie de ce courriel ou des renseignements qu'il contient par une
personne autre que le ou les destinataires désignés est interdite. Si vous 
recevez
ce cour

Re: [R] kalman filter estimation

2007-11-15 Thread Paul Gilbert


[EMAIL PROTECTED] wrote:
> Hi,
> 
> Following convention below:
> y(t) = Ax(t)+Bu(t)+eps(t) # observation eq
> x(t) = Cx(t-1)+Du(t)+eta(t) # state eq
> 
> I modified the following routine (which I copied from: 
> http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an 
> exogenous input to the system. 
> 
> for (i in 2:N){
>  xp[[i]]=C%*%xf[[i-1]]
>  Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q
>siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R
>  sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric
>siginv=solve(sig[[i]])  # now siginv is sig[[i]]^{-1}
>  K=Pp[[i]]%*%t(A[[i]])%*%siginv
>  innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]]
>  xf[[i]]=xp[[i]]+K%*%innov[[i]]
>  Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]]
>  like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]]
>  }
>like=0.5*like
>list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K)
> }
> 
> I tried to fit my problem and observe that I got positive log likelihood 
> mainly because the log of determinant of my variance matrix is largely 
> negative. That's not good because they should be positive. Have anyone 
> experience this kind of instability?
> 
The determinant should not be negative (the line "# make sure sig is 
symmetric" should look after that) but the log can be negative.

> Also, I realize that I have about 800 sample points. The above routine when 
> being plugged to optim becomes very slow. Could anyone share a faster way to 
> compute kalman filter? 

The KF recursion you show is not time varying, but the code you show 
looks like it may allow for time varying models. (I'm just guessing, I'm 
not familiar with the code.) If you do not need the time varying aspect 
then this is probably a slow way to implement. Package dse1 in the dse 
bundle implements the recursion the way you show, with an exogenous 
input u(t), so you don't even have to modify the code. It is implemented 
in R for demonstration, but also in fortran for speed. See the dse Users 
Guide for more details, and also ?SS and ?l.SS. One caveat is that the 
way the likelihood is cumulated over i in your code above allows for 
time varying sig, which in theory can be important for a diffuse prior. 
In dse the likelihood is calculated using the residual to get a sample 
estimate of sig, which is faster. I have not found cases where this 
makes much difference (but would be interested to know of one).

> And my last problem is, optim with my defined feasible space does not 
> converge. I have about 20 variables that I need to identify using MLE method. 
> Is there any other way that I can try out? I tried most of the methods 
> available in optim already. They do not converge at all.. Thank you.

This used to be a well known problem for multivariate state space 
models, but seems to be largely forgotten. It does not seriously affect 
univariate models. For a review of the old literature see section 5 of 
Gilbert 1993, available at 
. 
The bottom line is that you are in trouble trying to use hill climbing 
methods and state-space models unless you have a very good starting 
point, or are luck. This is a feature of the parameter space, not a 
reflection on the optimization routine. One solution is to start by 
estimating a VAR or ARMA model and then convert it to a state space 
model, which was one of the original purposes of dse. (See ?bft for 
example.)

Paul Gilbert

> - adschai
> 
> __
> R-help@r-project.org 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.


La version française suit le texte anglais.



This email may contain privileged and/or confidential information, and the Bank 
of
Canada does not waive any related rights. Any distribution, use, or copying of 
this
email or the information it contains by other than the intended recipient is
unauthorized. If you received this email in error please delete it immediately 
from
your system and notify the sender promptly by email that you have done so. 



Le présent courriel peut contenir de l'information privilégiée ou 
confidentielle.
La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute 
diffusion,
utilisation ou copie de ce courriel ou des renseignements qu'il contient par une
personne autre que le ou les destinataires désignés est interdite. Si vous 
recevez
ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans 
délai à
l'expéditeur un message électronique pour l'aviser que vous avez éliminé de 
votre
ordina

Re: [R] kalman filter estimation

2007-11-15 Thread Prof Brian Ripley
On Thu, 15 Nov 2007, [EMAIL PROTECTED] wrote:

> Hi,
>
> Following convention below:
> y(t) = Ax(t)+Bu(t)+eps(t) # observation eq
> x(t) = Cx(t-1)+Du(t)+eta(t) # state eq
>
> I modified the following routine (which I copied from: 
> http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an 
> exogenous input to the system.
>
> for (i in 2:N){
> xp[[i]]=C%*%xf[[i-1]]
> Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q
>   siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R
> sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric
>   siginv=solve(sig[[i]])  # now siginv is sig[[i]]^{-1}
> K=Pp[[i]]%*%t(A[[i]])%*%siginv
> innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]]
> xf[[i]]=xp[[i]]+K%*%innov[[i]]
> Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]]
> like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]]
> }
>   like=0.5*like
>   list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K)
> }
>
> I tried to fit my problem and observe that I got positive log likelihood 
> mainly because the log of determinant of my variance matrix is largely 
> negative. That's not good because they should be positive. Have anyone 
> experience this kind of instability?

Why are you expecting that?  The magnitude of the log-likelihood depends 
on the scale of your data, and hence so does the sign of its log.

> Also, I realize that I have about 800 sample points. The above routine 
> when being plugged to optim becomes very slow. Could anyone share a 
> faster way to compute kalman filter?

Try

> help.search("kalman", agrep=FALSE)

kalsmo.car(cts) Compute Components with the Kalman Smoother
kalsmo.comp(cts)Estimate Componenents with the Kalman Smoother
nbkal(repeated) Negative Binomial Models with Kalman Update
extended(sspir) Iterated Extended Kalman Smoothing
kfilter(sspir)  Kalman filter for Gaussian state space model
kfs(sspir)  (Iterated extended) Kalman smoother
smoother(sspir) Kalman smoother for Gaussian state space model
tsmooth(timsac) Kalman Filter
KalmanLike(stats)   Kalman Filtering


> And my last problem is, optim with my defined feasible space does not 
> converge. I have about 20 variables that I need to identify using MLE 
> method. Is there any other way that I can try out? I tried most of the 
> methods available in optim already. They do not converge at all..

Most likely because of errors in your code.  Optim solves quite large 
Kalman filter problems for arima().

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org 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.


[R] kalman filter estimation

2007-11-14 Thread adschai
Hi,

Following convention below:
y(t) = Ax(t)+Bu(t)+eps(t) # observation eq
x(t) = Cx(t-1)+Du(t)+eta(t) # state eq

I modified the following routine (which I copied from: 
http://www.stat.pitt.edu/stoffer/tsa2/Rcode/Kall.R) to accommodate u(t), an 
exogenous input to the system. 

for (i in 2:N){
 xp[[i]]=C%*%xf[[i-1]]
 Pp[[i]]=C%*%Pf[[i-1]]%*%t(C)+Q
   siginv=A[[i]]%*%Pp[[i]]%*%t(A[[i]])+R
 sig[[i]]=(t(siginv)+siginv)/2 # make sure sig is symmetric
   siginv=solve(sig[[i]])  # now siginv is sig[[i]]^{-1}
 K=Pp[[i]]%*%t(A[[i]])%*%siginv
 innov[[i]]=as.matrix(yobs[i,])-A[[i]]%*%xp[[i]]
 xf[[i]]=xp[[i]]+K%*%innov[[i]]
 Pf[[i]]=Pp[[i]]-K%*%A[[i]]%*%Pp[[i]]
 like= like + log(det(sig[[i]])) + t(innov[[i]])%*%siginv%*%innov[[i]]
 }
   like=0.5*like
   list(xp=xp,Pp=Pp,xf=xf,Pf=Pf,like=like,innov=innov,sig=sig,Kn=K)
}

I tried to fit my problem and observe that I got positive log likelihood mainly 
because the log of determinant of my variance matrix is largely negative. 
That's not good because they should be positive. Have anyone experience this 
kind of instability?

Also, I realize that I have about 800 sample points. The above routine when 
being plugged to optim becomes very slow. Could anyone share a faster way to 
compute kalman filter? 

And my last problem is, optim with my defined feasible space does not converge. 
I have about 20 variables that I need to identify using MLE method. Is there 
any other way that I can try out? I tried most of the methods available in 
optim already. They do not converge at all.. Thank you.

- adschai

__
R-help@r-project.org 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.