Solved – Improving exponential decay fit

rtime series

I'm fitting an exponential function to a time series in R using the formula lm(log(rate) ~ month). When I graph predicted values (in red) vs my data (in black points), I can see that the curve isn't fitting very well in the earlier months. Is there a better approach for this?

exponential decay fit

Best Answer

Without having your data, it is hard to completely address your problem, but I do have a suggestion that may help. If the linear model produced errors of constant size across all values of time, once they are exponentiated, they will become errors proportional to the y-value, that is, the errors for large y-values can be expected to be much larger than errors for small values. You can correct for this using exponentially decaying weights.

Here is a simple example. The data is the weekly box office gross receipts from the movie "The Magnificent Seven" taken from Box Office Mojo

M7 = structure(list(Week = 1:14, Gross = c(45905901L, 20859492L, 12862169L, 
7115805L, 3142159L, 1900503L, 630393L, 291382L, 300424L, 185613L, 
107141L, 60229L, 33921L, 17497L)), .Names = c("Week", "Gross"
), class = "data.frame", row.names = c(NA, -14L))

## Straight Linear Model
LLM1 = lm(I(log(Gross)) ~ Week, data=M7)
plot(M7, main="Ordinary Linear Model")
lines(1:14, exp(LLM1$fitted.values), col="red")

Ordinary Linear Model

## Weighted model
W = 0.27^(1:14)
LLM2 = lm(I(log(Gross)) ~ Week, data=M7, weights=W)
plot(M7, main="Weighted Linear Model")
lines(1:14, exp(LLM2$fitted.values), col="red")

Weighted Model

Notice that the error at week 1 is much smaller and the other points did not suffer too much. I hope that this helps on your data.