[R] Updating a Time Series After Forecast()

Paul Gilbert pgilbert902 at gmail.com
Fri Jan 22 17:38:49 CET 2016


Lorenzo

Berend's suggestion may be the simplest if you have univariate ts style 
series. If you are writing code and you want it to work with 
multivariate series and other time representations then you might want 
to consider the splice() function in package tframe.
   library(tfplot)
   ts3 <- splice(ts2, pred2$mean)

(and tframePlus if you need zoo and other support.)

Regards,
Paul

On 01/16/2016 06:00 AM, r-help-request at r-project.org wrote:
> Date: Fri, 15 Jan 2016 13:02:58 +0100
> From: Berend Hasselman<bhh at xs4all.nl>
> To: Lorenzo Isella<lorenzo.isella at gmail.com>
> Cc:"r-help at r-project.org"  <r-help at r-project.org>
> Subject: Re: [R] Updating a Time Series After Forecast()
> Message-ID:<AC8189E0-4F20-479E-A75F-65A5CEE5F150 at xs4all.nl>
> Content-Type: text/plain; charset=us-ascii
>
>
>> >On 14 Jan 2016, at 22:36, Lorenzo Isella<lorenzo.isella at gmail.com>  wrote:
>> >
>> >Dear All,
>> >Perhaps I am drowning in a cup of water, since I am positive that the
>> >answer will be a one-liner.
>> >Consider the following short script
>> >
>> >
>> >########################################################
>> >library(forecast)
>> >
>> >ts2<-structure(c(339130, 356462, 363234, 378179, 367864, 378337, 392157,
>> >402153, 376361, 392204, 403483, 414034, 391967, 406067, 419464,
>> >434913, 410102, 424795, 437073, 448827, 415569, 430561, 444719,
>> >455764, 419892, 444190, 454648, 466312, 439922, 448963, 465153,
>> >475621, 445502, 457198, 473573, 485764, 463895, 470274, 484390,
>> >490678, 478003, 483570, 499141, 509216, 481395, 492345, 511184,
>> >513420, 483757, 490884, 514966, 515457, 497614, 510139, 523467,
>> >526406, 499784, 519033, 532009, 531260, 521539, 532590, 553118,
>> >557725, 548321, 556832, 578087, 578120, 566116, 580571, 587993,
>> >569985, 534326, 539641, 564824, 568445, 558614, 570192, 594584,
>> >598305, 593769, 598278, 620147, 615884, 611033, 609304, 630458,
>> >624325, 614356, 627192, 649324, 645988, 642965, 645125, 669471,
>> >665529, 664248, 669670, 694719), na.action = structure(1:64, class =
>> >"omit"), .Tsp = c(1991,
>> >2015.5, 4), class = "ts")
>> >
>> >fit2 <- auto.arima(ts2, approximation=FALSE,trace=FALSE)
>> >
>> >pred2 <- forecast(fit2, h=2)
>> >
>> >#######################################################
>> >
>> >So, I have an original quarterly time series ts2 and a forecast for 2
>> >quarters pred2.
>> >
>> >I would like to combine ts2 and pred2 (just the prediction) into a new
>> >time series (in other words, just stretch a bit ts2).
>> >How can I do that?
> A possible way is this
>
> ts3 <- ts(c(ts2,pred2$mean),start=start(ts2),frequency=frequency(ts2))
>
> Most  likely there are more ways of getting what you want.
>
> Berend
>
>> >Many thanks
>> >
>> >Lorenzo
>> >



More information about the R-help mailing list