<jupyter_start><jupyter_text>Regression Analysis Ordinary Least Squares (OLS) Estimation<jupyter_code>beef_model = ols("Quantity ~ Price", data=beef).fit()
print(beef_model.summary())<jupyter_output>OLS Regression Results                            
==============================================================================
Dep. Variable:               Quantity   R-squared:                       0.901
Model:                            OLS   Adj. R-squared:                  0.900
Method:                 Least Squares   F-statistic:                     811.2
Date:                Fri, 31 Aug 2018   Prob (F-statistic):           1.69e-46
Time:                        23:00:04   Log-Likelihood:                -77.493
No. Observations:                  91   AIC:                             159.0
Df Residuals:                      89   BIC:                             164.0
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|[...]<jupyter_text>The small P values indicate that we can reject the null hypothesis that Price has no effect on Quantity.Hight r squared indicates that our model explains a lot of the response variability.In regression analysis, we'd like our regression model to have significant variables and to produce a high R-squared value.We will show graphs to help interpret regression analysis results more intuitively.<jupyter_code>fig = plt.figure(figsize=(12,8))
fig = sm.graphics.plot_partregress_grid(beef_model, fig=fig)<jupyter_output><empty_output><jupyter_text>The trend indicates that the predictor variables (Price) provides information about the response (Quantity), and data points do not fall further from the regression line, and the predictions are very precise given a prediction interval that extends from about 29 to 31.  Component-Component plus Residual (CCPR) PlotsThe CCPR plot provides a way to judge the effect of one regressor on the response variable by taking into account the effects of the other independent variables.<jupyter_code>fig = plt.figure(figsize=(12, 8))
fig = sm.graphics.plot_ccpr_grid(beef_model, fig=fig)<jupyter_output><empty_output><jupyter_text>Regression plotsWe use plot_regress_exog function to quickly check model assumptions with respect to a single regressor, Price in our case.<jupyter_code>fig = plt.figure(figsize=(12,8))
fig = sm.graphics.plot_regress_exog(beef_model, 'Price', fig=fig)<jupyter_output><empty_output><jupyter_text>Recursive Least Square (RLS)Finally we apply Recursive Least Square (RLS) filter to investigate parameter instability.<jupyter_code>beef['Year'] = pd.to_datetime(beef['Year'], format="%Y")
beef.head()
from pandas.tseries.offsets import *
beef['Date'] = beef.apply(lambda x:(x['Year'] + BQuarterBegin(x['Quarter'])), axis=1)
beef.drop(['Year', 'Quarter'], axis=1, inplace=True)
beef.set_index('Date', inplace=True)
beef.head(10)
endog = beef['Quantity']

# To the regressors in the dataset, we add a column of ones for an intercept
exog = sm.add_constant(beef['Price'])<jupyter_output><empty_output><jupyter_text>RLS estimation<jupyter_code>mod = sm.RecursiveLS(endog, exog)
res = mod.fit()

print(res.summary())<jupyter_output>Statespace Model Results                           
==============================================================================
Dep. Variable:               Quantity   No. Observations:                   91
Model:                    RecursiveLS   Log Likelihood                 -84.326
Date:                Fri, 31 Aug 2018   AIC                            172.653
Time:                        23:38:41   BIC                            177.675
Sample:                    03-01-1977   HQIC                           174.679
                         - 09-01-1999                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
const         30.0515      0.413     72.700      0.0[...]<jupyter_text>The RLS model computes the regression parameters recursively, so there are as many estimates as there are datapoints, the summary table only presents the regression parameters estimated on the entire sample; these estimates are equivalent to OLS estimates.  RLS plotsWe can generate the recursively estimated coefficients plot on a given variable.<jupyter_code>res.plot_recursive_coefficient(range(mod.k_exog), alpha=None, figsize=(10,6));<jupyter_output><empty_output><jupyter_text>For convenience, we visually check for parameter stability using the plot_cusum function.<jupyter_code>fig = res.plot_cusum(figsize=(10,6));<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15044776119402986, 'fraction_numerical': 0.02945273631840796, 'mean_word_length': 2.4167233174711082, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '604626', 'license': 'MIT', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1267, 'n_words': 392, 'path': 'Price Elasticity of Demand.ipynb', 'repo_name': 'BeeChainFoundation/Brainstorming', 'size': '5025'}