# [R] KalmanSmooth problem

Hazenberg21, Pieter Pieter.Hazenberg21 at wur.nl
Wed Jul 7 22:26:30 CEST 2004

```Dear Uwe and Spencer,
Thanks for replying so soon. The R version I wrote is indeed R 1.9.1, and the package is stats. Sorry I didn't wrote it in my first email. I've have tried to use the comments you gave, and simplified my function.
It is changed to:

> Kalm = function(x){
+ t=array(c(-1.4248, 2.5, .1250, 20, -19.3183, .6667, .1, .0667, 1.7945), dim=c(3,3))
+ h=0.5;
+ r=array(c(1,0,0,0,1,0,0,0,1),dim=c(3,3));
+ q=1;
+ v=r*q*t(r);
+ a=10.14286;
+ z=array(c(.3574, 0, 0, 0, 0, 0, 0, 0, .2), dim=c(3,3))
+ p=array(c(1,0,0,0,1,0,0,0,1),dim=c(3,3));
+ pn=array(c(1,0,0,0,1,0,0,0,1),dim=c(3,3));
+ kal=KalmanSmooth(x,list(T=t,Z=z,h=h,V=v,a=a,P=p,Pn=pn),nit=0)
+ kal}
>Kalm(deb)

Wonderfully it is running quite well now. Thank you for your spare time.
Best regards,
Pieter Hazenberg

-----Oorspronkelijk bericht-----
Van: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de]
Verzonden: wo 7-7-2004 22:09
Aan: Spencer Graves; Hazenberg21, Pieter
CC: R Help Mailing List
Onderwerp: Re: [R] KalmanSmooth problem

Spencer Graves wrote:

> Hi, Uwe:  "KalmanSmooth" is in the "stats" package in R 1.9.1.  R is
> moving so fast that it is impossible to keep current with all parts of
> it.  Best Wishes, Spencer Graves

Uhhhh .... thanks, Spencer. My apologies to Pieter.

Indeed, looks like I forgot to upgrade my R version on the machine at
home. I only did so in my office and on my laptop.

Uwe

> Uwe Ligges wrote:
>
>> Hazenberg21, Pieter wrote:
>>
>>> Hello,
>>> In R I am trying to use Kalman filtering to find a solution for an
>>> hydrological problem. With Kalman Filtering I want to estimate the
>>> discharge comming from three storage bassins. I have programmed a
>>> function in R which can run KalmanSmooth. When I'm asking for the
>>> function and putting in values, R detects the following error: "Error
>>> in as.vector(data) : Argument "S1" is missing, with no default".
>>> I have try to find a solution for this error in the R help file, and
>>> solution.
>>> Question: What does R mean with "S1" and what am I doing wrong?
>>> Here is the way I have programmed the hydrological problem in R.
>>>
>>>> deb=discharge[,1]
>>>> deb
>>>
>>>
>>>
>>>   [1] 11.545313  8.045465  5.670868  4.044584  2.919311  2.306668
>>> 2.940956
>>>   [8]  4.238159  5.017374  3.818236  2.928805  2.262183  1.757765
>>> 1.633945
>>>  [15]  2.295130  3.454054  4.035224  3.193967  2.533181  2.012406
>>> 1.600836
>>>  [22]  1.652155  2.428678  3.642827  4.019545  3.209473  2.563617
>>> 2.048347
>>>  [29]  1.637041  1.828952  2.757842  4.050821  4.147013  3.316503
>>> 2.652490
>>>  [36]  2.121535  1.696934  2.027763  3.107366  4.429670  4.160178
>>> 3.327950
>>>  [43]  2.662237  2.129710  1.703717  2.158095  3.337039  4.582359
>>> 3.905901
>>>  [50]  3.124690  2.499732  1.999772  1.599810  2.130893  3.302622
>>> 4.336081
>>>  [57]  3.468857  2.775081  2.220062  1.776048  1.560859  2.169537
>>> 3.348081
>>>  [64]  4.170552  3.336440  2.669151  2.135320  1.708256  1.648859
>>> 2.374217
>>>  [71]  3.624091  4.248563  3.398850  2.719080  2.175264  1.740211
>>> 1.826122
>>>  [78]  2.704749  4.056438  4.437309  3.549847  2.839878  2.271902
>>> 1.817522
>>>  [85]  2.053994  3.107875  4.548436  4.600601  3.680481  2.944385
>>> 2.355508
>>>  [92]  1.884406  2.273248  3.490148  4.949898  4.584409  3.667527
>>> 2.934022
>>>  [99]  2.347217  1.877774
>>>
>>>> Kalm = function(x,O1,O2,O3,T1,T2,T3,T4,T5,t,ga){
>>>
>>>
>>>
>>> +
>>> t=array(c(1+ga*O1+t/O1*(-(1/T2)-(1/T3)-(1/T1)),t/O1*(1/T2),t/O1*(1/T3),
>>> + t/O2*(1/T2),1+ga*O2+t/O2*(-(1/T2)-(1/T4)),t/O2*(1/T4),
>>> +
>>> t/O3*(1/T3),t/O3*(1/T4),1+ga*O3+t/O3*(-(1/T3)-(1/T4)-(1/T5))),dim=c(3,3));
>>>
>>> + h=0.5;
>>> + r=array(c(1,0,0,0,1,0,0,0,1),dim=c(3,3));
>>> + q=1;
>>> + v=r*q*t(r);
>>> + a=10.14286;
>>> + z=array(c((1/T1),0,0,0,0,0,0,0,(1/T5)), dim=c(3,3));
>>> + p=array(c(1,0,0,0,1,0,0,0,1),dim=c(3,3));
>>> + pn=array(c(1,0,0,0,1,0,0,0,1),dim=c(3,3));
>>> + kal=KalmanSmooth(x, list(T=t,Z=z,h=h,V=v,a=a,P=p,Pn=pn), nit=0)
>>> + kal}
>>>
>>>
>>>> Kalm(deb,4,.5,5,.7,.1,2,3,4,1,0.65)
>>>
>>>
>>>
>>> Error in as.vector(data) : Argument "S1" is missing, with no default
>>>
>>> First I thought I had to make a timeserie of deb. But this doesn't
>>> change the problem.
>>> Lot's of thanks trying to help me.
>>
>>
>>
>> a) Please tell us R Version and OS (OK, implicitly done that we are
>> talking about R-1.9.0 on Windows).
>> b) Please tell us which packages you are using (I don't know
>> KalmanSmooth(), for example).
>> c) Please try to specify reproducible examples.
>>
>>
>> My hint is to try to debug yourself, at least *try*, starting eith
>> calling traceback() right after the error appeared, in order to get a
>> guess where the error really happens. Then look at the data that is
>> passed to the function -  and I'm pretty sure you will get at least an
>> idea what goes wrong.
>>
>> Uwe Ligges
>>
>>
>>
>>
>>
>>> Best regards,
>>> Pieter Hazenberg
>>> Student Hydrology and Watermanagement
>>> Wageningen University
>>> The Netherlands
>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>> http://www.R-project.org/posting-guide.html
>>
>>
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://www.stat.math.ethz.ch/mailman/listinfo/r-help