1
$\begingroup$

I need to decompose a series to remove seasonality. The series has 2 columns date and volume.

This is what my time series object looks like:

salestsDec <- ts(salests, frequency=52, start=c(2010, 1), end=c(2014,12))

I ran the decompose() function on a 'ts' object.

salests = sales[, c(1,6)]
View(salests)
salestsDec <- ts(salests, frequency=52, start=c(2010, 1), end=c(2014,12))
salestsDec <- decompose(salestsDec, type=c("additive"))
plot(salestsDec)

Upon, running the decompose() function, I get a list of 6 components, observed, trend, seasonal, random for both date and volume. I should only be seeing, observed, trend, seasonal and random component for Volume in my plot.

I've attached an image of what the plot looks like.

Moreover, when I try to remove seasonal component from the series, I am getting an error. It appears that it's the same underlying issue.

Error:

Error in salests - salestsDec$seasonal : non-numeric argument to binary operator In addition: Warning message: Incompatible methods ("Ops.data.frame", "Ops.ts") for "-"

 Time series components plot after running decomposed()

$\endgroup$
0

1 Answer 1

1
$\begingroup$

I can't replicate (without having the data), but from what I see, you are trying to apply the decompose function to the entire object - it's probably expecting a single vector, but receives a data-frame-like object and attempts to apply the decomposition to both columns. either use a different time series package (like zoo) which does not store timestamps as a column, or apply decompose explicitly to salestsDec[,2].

$\endgroup$
2
  • $\begingroup$ Thanks @kpb. That worked like a charm. However, my plot looks fine now with observed, trend, seasonal and random component. I get a error when I try to subtract seasonal component from the decomposed series. It appears that I can perform a math operation on the series as it is not numeric and needs conversion. Error looks like this: code Error in -.default(salestsDec, salestsDec$seasonal) : non-numeric argument to binary operator code. $\endgroup$
    – kms
    Commented Aug 31, 2015 at 16:56
  • $\begingroup$ @keval: again, tricky without replication, but if I understand correctly you are trying to subtract the seasonality from the original series. If that is the case, either add the remaining components (trend + random) or subtract salestsDec$seasonal from salestsDec[,2] and not from salestsDec. Better still, can you post the output of str(salestsDec, max.level = 1) or somesuch? That should have info on object classes, dimensions etc. $\endgroup$
    – kpb
    Commented Sep 2, 2015 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.