def function_partial_autocorrelation(ts_data, window_size):
    ts_log_diff = differencing_log(ts_data, window_size, False, False)
    lag_pacf = pacf(ts_log_diff, nlags=20, method="ols")

    pyplot.plot(lag_pacf)
    pyplot.axhline(y=0, linestyle="--", color="gray")
    pyplot.axhline(y=-1.96 / np.sqrt(len(ts_log_diff)),
                   linestyle="--",
                   color="gray")
    pyplot.axhline(y=1.96 / np.sqrt(len(ts_log_diff)),
                   linestyle="--",
                   color="gray")
    pyplot.title("Partial Autocorrelation Function")
def function_autocorrelation(ts_data, window_size):
    ts_log_diff = differencing_log(ts_data, window_size, False, False)
    lag_acf = acf(ts_log_diff, nlags=20)

    pyplot.plot(lag_acf)
    pyplot.axhline(y=0, linestyle="--", color="gray")
    pyplot.axhline(y=-1.96 / np.sqrt(len(ts_log_diff)),
                   linestyle="--",
                   color="gray")
    pyplot.axhline(y=1.96 / np.sqrt(len(ts_log_diff)),
                   linestyle="--",
                   color="gray")
    pyplot.title('Autocorrelation Function')
def model_combined(ts_data, window_size, should_plot=True):
    ts_log = np.log(ts_data)
    ts_log_diff = differencing_log(ts_data, window_size, False, False)
    model = ARIMA(ts_log, order=(1, 1, 1))
    results_ARIMA = model.fit(disp=0)

    if should_plot:
        # root_mean_squared = sum((results_MA.fittedvalues - ts_log_diff) ** 2)
        pyplot.plot(ts_log_diff, color="blue", label="ts log difference")
        pyplot.plot(results_ARIMA.fittedvalues,
                    color="red",
                    label="results ARIMA fitted")
        pyplot.legend(loc="best")
        pyplot.title("Combined Model AR-I-MA")
        # pyplot.title("RSS: {}".format(root_mean_squared))

    return results_ARIMA