How to add periodic component to linear regression model?

I have some cumulative frequency data. A line y=ax+b looks like it fits the data extremely well, but there is cyclic/periodic wiggle in the line. I would like to estimate when the cumulative frequency will reach a certain value c. When I plot the residuals vs. fitted values, I get a beautiful sinusoidal behavior.

Now, to add another complication, note that in the residuals plots

alt text

there are two cycles that have lower values than the others, which represents a weekend effect that also must be taken into account.

So, where do I go from here? How can I combine some cosine, sine, or cyclic term into a regression model to approx. estimate when the cumulative frequency will equal c?

Answer

You could try the wonderful stl() method — it decomposes (using iterated loess() fitting) into trend and seasonal and remainder. This may just pick up your oscillations here.

Attribution
Source : Link , Question Author : Ryan Rosario , Answer Author : Dirk Eddelbuettel

Leave a Comment