[R] Imputing missing values in time series

Joao Santos jcsantos at student.dei.uc.pt
Wed Nov 7 19:32:13 CET 2007


Hello,


I have a similar problem but in my case I have a seasonal time series and
the gaps are bigger.
Like I said the TS as a seasonality to the week and some gaps are so big
that seasonality is broken. 
I need a process to predict this values and keep the seasonality.
>From the search that I made I don't found any process to do this.

Any ideas are welcome!

Thanks in advance,

João Santos   



Horace Tso wrote:
> 
> Erik, indeed it gets the work done. I was hoping to avoid the dreaded
> looping, though.....
> 
> Thanks.
> 
> Horace
> 
>>>> Erik Iverson <iverson at biostat.wisc.edu> 6/22/2007 12:01 PM >>>
> I think my example should work for you, but I couldn't think of a way to 
> do this without an interative while loop.
> 
> test <- c(1,2,3,NA,4,NA,NA,5,NA,6,7,NA)
> 
> while(any(is.na(test)))
> test[is.na(test)] <- test[which(is.na(test))-1]
> 
>   test
>   [1] 1 2 3 3 4 4 4 5 5 6 7 7
> 
> Horace Tso wrote:
>> Folks,
>> 
>> This must be a rather common problem with real life time series data
>> but I don't see anything in the archive about how to deal with it. I
>> have a time series of natural gas prices by flow date. Since gas is not
>> traded on weekends and holidays, I have a lot of missing values,
>> 
>> FDate	Price
>> 11/1/2006	6.28
>> 11/2/2006	6.58
>> 11/3/2006	6.586
>> 11/4/2006	6.716
>> 11/5/2006	NA
>> 11/6/2006	NA
>> 11/7/2006	6.262
>> 11/8/2006	6.27
>> 11/9/2006	6.696
>> 11/10/2006	6.729
>> 11/11/2006	6.487
>> 11/12/2006	NA
>> 11/13/2006	NA
>> 11/14/2006	6.725
>> 11/15/2006	6.844
>> 11/16/2006	6.907
>>  
>> What I would like to do is to fill the NAs with the price from the
>> previous date * gas used during holidays is purchased from the week
>> before. Though real simple, I wonder if there is a function to perform
>> this task. Some of the imputation functions I'm aware of (eg. impute,
>> transcan in Hmisc) seem to deal with completely different problems. 
>> 
>> 2.5.0/Windows XP
>> 
>> Thanks in advance.
>> 
>> HT
>> 
>> ______________________________________________
>> R-help at 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.
> 
> ______________________________________________
> R-help at 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Imputing-missing-values-in-time-series-tf3966333.html#a13632881
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list