I used stl() in R to decompose count data into trend, seasonal & irregular components. The resulting trend values are not integers anymore. I have the following questions:

  1. Is stl() an appropriate way to deseasonalize count data?
  2. Since the resulting trend is not interger valued anymore, can I use lm() to model the trend components?

There is no inherent problem with using stl() to deseasonalize count data. One issue to be aware of however is that count data generally has an increasing variance as the mean increases. This is often seen in both the seasonal and random elements of the decomposition. Using stl() on the raw data will not take this into account, and hence it may be best to first take the logarithm (edit - or square root) of your data.

It doesn't matter that the trend values are not integers any more. They can be thought of in a similar way to the parameter in a Poisson distribution. Although a Poisson distributed variable must be an integer, the mean doesn't need to be.

However, this doesn't necessarily mean you can use lm() to model the trend component. There are many pitfalls in modelling trends in time series, as spurious correlations will be very difficult to avoid. More commonly people first detrend the series and then model the residual part.

  • 1
    $\begingroup$ How do you determine how many trends there are that need to be accomodated and the length of each trend ? Do you distinguish between level shifts and trends and in general how do you detrend in the presence pf outliers/inliers ? $\endgroup$ – IrishStat Dec 16 '12 at 17:01
  • $\begingroup$ @IrishStat - yes, those are all good points and I wasn't trying to address the full set of issues, just draw attention to the problems of using the trend component from the output of R's stl() as the response variable in a regression. stl() uses locally weighted regression in its decomposition which generally gives sensible results when it comes to trends changing direction, etc., although of course it has limitations compared to model-based methods particularly for forecasting. $\endgroup$ – Peter Ellis Dec 16 '12 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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