<jupyter_start><jupyter_text>run regression in R, come back when done   results<jupyter_code>result_data = '/Users/boyuliu/Dropbox (MIT)/Boyu-Joann/Intermediate output/outputs/grid_search'\
            '/timed_reg_rolling_6m_ols.csv'
df = pd.read_csv(result_data)
slopes = df[df.item=='total_demand'].copy()
slopes['lb'] = slopes['Estimate'] - 1.96*slopes['Std. Error']
slopes['ub'] = slopes['Estimate'] + 1.96*slopes['Std. Error']
print(slopes.shape)

t = [i for i in reg_data.year_week.unique().tolist() if i>'2018-27']
t = list(map(fun, t))
print(len(t))

slopes.head()
from datetime import datetime, timedelta
def fun(yw):
    yr, wk = [int(i) for i in yw.split('-')]
    return datetime(yr, 1, 1) + timedelta(days=wk*7-7)
fig, ax = plt.subplots(1, figsize=(12,8))
ax.plot(t, slopes.Estimate, lw=2, label='Regression Coefficient')
ax.fill_between(t, slopes.lb, slopes.ub, facecolor='yellow', alpha=0.5,
                label='95% Confidence Interval')
ax.legend(loc='upper left')
plt.xticks(rotation='vertical')
ax.set_xlabel('6 months rolling window end date')
ax.set_ylabel('value')
ax.axhline(0, color='orange')
ax.grid()
grid_search_folder = '/Users/boyuliu/Dropbox (MIT)/Boyu-Joann/Intermediate output/outputs/grid_search/'
fig, ax = plt.subplots(1, figsize=(12,8))
ax.plot(t, slopes.Estimate, lw=2, label='Regression Coefficient')
ax.fill_between(t, slopes['CI Lower'], slopes['CI Upper'], facecolor='yellow', alpha=0.5,
                label='95% Confidence Interval')
ax.legend(loc='upper left')
plt.xticks(rotation='vertical')
ax.set_xlabel('6 months rolling window end date (month)')
ax.set_ylabel('coefficient for demand')
ax.axhline(0, color='orange')
plt.title('6 month rolling window OLS')
ax.grid()
plt.savefig(grid_search_folder+'6mo_ols.png')
plt.show()<jupyter_output><empty_output><jupyter_text>plot result for causal detrend<jupyter_code>result_data = '/Users/boyuliu/Dropbox (MIT)/Boyu-Joann/Intermediate output/outputs/grid_search'\
            '/timed_reg_rolling_6m_ols_causal_detrend.csv'
df = pd.read_csv(result_data)
slopes = df[df.item=='demand_shock'].copy()
slopes['lb'] = slopes['Estimate'] - 1.96*slopes['Std. Error']
slopes['ub'] = slopes['Estimate'] + 1.96*slopes['Std. Error']
print(slopes.shape)

t = [i for i in reg_data.year_week.unique().tolist() if i>'2018-27']
t = list(map(fun, t))
print(len(t))

slopes.head()
fig, ax = plt.subplots(1, figsize=(12,8))
ax.plot(t, slopes.Estimate, lw=2, label='Regression Coefficient')
ax.fill_between(t, slopes['CI Lower'], slopes['CI Upper'], facecolor='yellow', alpha=0.5,
                label='95% Confidence Interval')
ax.legend(loc='upper left')
plt.xticks(rotation='vertical')
ax.set_xlabel('6 months rolling window end date (month)')
ax.set_ylabel('coefficient for demand')
ax.axhline(0, color='orange')
plt.title('6 month rolling window OLS')
ax.grid()
plt.savefig(grid_search_folder+'6mo_ols_causal_detrend.png')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17499150526673463, 'fraction_numerical': 0.022765885151206252, 'mean_word_length': 5.9270588235294115, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '199590', 'license': 'MIT', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1087, 'n_words': 210, 'path': 'notebooks/analysis_w_2020/6 month rolling for ILM2 data .ipynb', 'repo_name': 'lbyiuou0329/Thai-Labor-Abuse-Project-Code', 'size': '2943'}