I'm trying to find the best fit line for this data below but no matter what I try, the fit line seems to never be able to account for the lower values as shown below.

The x-values are just dates from 1/1/2014 to 7/20/2015 (566 values), but I don't know how to give you guys the y-values. I have it in my Environment but I don't know how to give you that without copying and pasting from the Console output.

Data with sinusodial fit

This is the code that I'm using to get that fit line:




This is the code to get the plot above:

    20")),ylim=range(c(-3.2,0)),xlab="Date (1/1/2014 to
    7/20/2015)",ylab="Total Net with Storage (bcf)",main="Total Burn with

What else can I do to generate a better fit line for this data? Also, if there's a good way to predict future data, I would appreciate help with that as well.

Sorry in advance, if I'm not giving enough information. Please feel free to ask for any information you need and I will promptly edit the post.

EDIT: I have added the work I did with ARIMA below.

I inputted the following code and got the following results:

fit.arima = arima(wbbcf,order=c(0,1,2))
pred.arima = predict(fit.arima,n.ahead=500)

ARIMA predictions

Here's the auto.arima() output:

Series: wbbcf 

          ma1      ma2
      -0.3023  -0.3188
s.e.   0.0397   0.0396

sigma^2 estimated as 0.05788:  log likelihood=3.02
AIC=-0.04   AICc=0.01   BIC=12.98

Is something wrong with what I'm doing with ARIMA?

  • 2
    $\begingroup$ If this is a time-series, have you considered using time-series methods? $\endgroup$ Aug 6, 2015 at 16:41
  • 6
    $\begingroup$ Looking at your plot, I think you might already have fit the best sinusoid to your data. A sinusoid just might not be the best description of these data. $\endgroup$
    – EdM
    Aug 6, 2015 at 16:47
  • $\begingroup$ If this isn't the best description, what is? Could you tell me more about "time-series methods"? $\endgroup$
    – Andy Kim
    Aug 6, 2015 at 16:56
  • $\begingroup$ Time series analysis is a subfield of statistics which accounts for the temporal structure of data. It is discussed all over the place on this website. Perhaps the most common method for this type of problem is ARIMA. $\endgroup$
    – Sycorax
    Aug 6, 2015 at 17:27
  • $\begingroup$ I actually tried using ARIMA already and it didn't seem to work... I will edit the post with my findings on that. $\endgroup$
    – Andy Kim
    Aug 6, 2015 at 17:29

1 Answer 1


As @EdM suggests, this may be the best it gets with a sinusoid. Sometimes, a sinusoid just isn't really the underlying relationship that the data is being generated from.

Here are four suggestions that are guaranteed to do at least as good, if not better. I'll assume you've dealt with the underlying time trend and that we're simply discussing the cyclical or seasonal pattern in the data.

First, if you're fitting something like $$\hat{y}_t = c_0 + c_1t + c_2\text{sin}(c_3 2\pi (t + a))$$ to your data instead of something like $$\hat{y}_t = c_0 + c_1t + f(t)\text{sin}(c_3 2\pi (t + a)),$$ you may consider the latter. The function $f(t)$ allows for the amplitude of your sinusoid to vary over its support (i.e. the interval $[\min\{t\}, \max\{t\}]$). This additional flexibility allows for the sinusoid to better accommodate the increased range occurring post-2015. I will acknowledge, however, that sinusoidal modeling can get very complicated for this very reason.

Another solution that would certainly do better than your sine wave in capturing the trend in the data would be to use a spline. I think a cubic spline would be sufficient. You can read more about splines in Chapter 5 of this book. The drawback of this approach is that it does poorly extrapolating into the future periods and it also will require significantly more parameters (which may not be problem judging by how your data looks).

A third and likely more robust solution is to use dummy variables to parametrize whatever "seasons" appear to be apparent in the data. For example, by looking at the 2014 year, we can see that roughly the first four months show an increasing linear trend, the second four months seem flat, and the third four months show a decreasing linear trend. If you include a dummy variable for the slope term of some linear regression of $y$ on $t$ (specifically you would have two of them, perhaps for the second and third trimesters only), you would be able to capture this increase-flat-decrease patter. You would also need to account for the fact that the constant term can different in each season as well. For the linear case, you will at most be estimating six parameters in total.

Finally, we can again notice that the seasonal pattern occurring every four months and difference the data accordingly. That is, instead of working with the series $\{y_t\}_{t=2014}^{t=2015.5}$, you may consider working with $\{y_t - y_{t-\tfrac{1}{3}}\}$, where the $\tfrac{1}{3}$ represents four months or one trimester. The only problem is that you currently don't have enough data to do this and, in general it's difficult to ascertain seasonal or cyclical trends when not enough time has elapsed. Thus, I only recommend this method if you can acquire data going back to at least 2005 or earlier.


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.