Adrien
Adrien

Reputation: 151

How to recombine seasonally decomposed stl components in R

I want to recombine the seasonal components to the seasonally adjusted components for a time series that is decomposed by stl. For example:

    library(fpp)
    fit <- stl(elecequip, s.window=7)
    plot(fit)

    sa_fit <- seasadj(fit)

How do I combine the seasonal component to sa_fit so that I get back the original seasonal data ?

Thanks in advance.

Upvotes: 2

Views: 675

Answers (1)

David Arenburg
David Arenburg

Reputation: 92282

In order to get the attributes of an unfamiliar (to you) class in R use attributes.

A quick look will show you that you need the time.series attribute, as in

unadjusted <- fit$time.series[, 1] + sa_fit

You can then check that the unadjusted equals to the original data by using all.equal

all.equal(unadjusted, elecequip)
## [1] TRUE

Upvotes: 5

Related Questions