Skip to content

Instantly share code, notes, and snippets.

@ryxcommar
Created July 20, 2022 04:07
Show Gist options
  • Save ryxcommar/8c5c6ea7afce3461afe4b3b634df982e to your computer and use it in GitHub Desktop.
Save ryxcommar/8c5c6ea7afce3461afe4b3b634df982e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0d297e9a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" OLS Regression Results \n",
"==============================================================================\n",
"Dep. Variable: y R-squared: 0.430\n",
"Model: OLS Adj. R-squared: 0.430\n",
"Method: Least Squares F-statistic: 3.770e+04\n",
"Date: Wed, 20 Jul 2022 Prob (F-statistic): 0.00\n",
"Time: 00:06:01 Log-Likelihood: -71005.\n",
"No. Observations: 50000 AIC: 1.420e+05\n",
"Df Residuals: 49998 BIC: 1.420e+05\n",
"Df Model: 1 \n",
"Covariance Type: nonrobust \n",
"==============================================================================\n",
" coef std err t P>|t| [0.025 0.975]\n",
"------------------------------------------------------------------------------\n",
"const 1.9937 0.009 222.772 0.000 1.976 2.011\n",
"x 3.0050 0.015 194.173 0.000 2.975 3.035\n",
"==============================================================================\n",
"Omnibus: 2.649 Durbin-Watson: 2.005\n",
"Prob(Omnibus): 0.266 Jarque-Bera (JB): 2.634\n",
"Skew: 0.015 Prob(JB): 0.268\n",
"Kurtosis: 3.019 Cond. No. 4.38\n",
"==============================================================================\n",
"\n",
"Notes:\n",
"[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
" OLS Regression Results \n",
"==============================================================================\n",
"Dep. Variable: y_u R-squared: 0.274\n",
"Model: OLS Adj. R-squared: 0.274\n",
"Method: Least Squares F-statistic: 1.885e+04\n",
"Date: Wed, 20 Jul 2022 Prob (F-statistic): 0.00\n",
"Time: 00:06:01 Log-Likelihood: -88277.\n",
"No. Observations: 50000 AIC: 1.766e+05\n",
"Df Residuals: 49998 BIC: 1.766e+05\n",
"Df Model: 1 \n",
"Covariance Type: nonrobust \n",
"==============================================================================\n",
" coef std err t P>|t| [0.025 0.975]\n",
"------------------------------------------------------------------------------\n",
"const 2.0020 0.013 158.360 0.000 1.977 2.027\n",
"x 3.0017 0.022 137.304 0.000 2.959 3.044\n",
"==============================================================================\n",
"Omnibus: 2.342 Durbin-Watson: 1.994\n",
"Prob(Omnibus): 0.310 Jarque-Bera (JB): 2.362\n",
"Skew: 0.005 Prob(JB): 0.307\n",
"Kurtosis: 3.032 Cond. No. 4.38\n",
"==============================================================================\n",
"\n",
"Notes:\n",
"[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
" OLS Regression Results \n",
"==============================================================================\n",
"Dep. Variable: y R-squared: 0.032\n",
"Model: OLS Adj. R-squared: 0.032\n",
"Method: Least Squares F-statistic: 1679.\n",
"Date: Wed, 20 Jul 2022 Prob (F-statistic): 0.00\n",
"Time: 00:06:01 Log-Likelihood: -84228.\n",
"No. Observations: 50000 AIC: 1.685e+05\n",
"Df Residuals: 49998 BIC: 1.685e+05\n",
"Df Model: 1 \n",
"Covariance Type: nonrobust \n",
"==============================================================================\n",
" coef std err t P>|t| [0.025 0.975]\n",
"------------------------------------------------------------------------------\n",
"const 3.3818 0.006 521.223 0.000 3.369 3.395\n",
"x_u 0.2295 0.006 40.973 0.000 0.219 0.240\n",
"==============================================================================\n",
"Omnibus: 79.312 Durbin-Watson: 2.003\n",
"Prob(Omnibus): 0.000 Jarque-Bera (JB): 66.159\n",
"Skew: 0.012 Prob(JB): 4.30e-15\n",
"Kurtosis: 2.823 Cond. No. 1.64\n",
"==============================================================================\n",
"\n",
"Notes:\n",
"[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
]
}
],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import statsmodels.api as sm\n",
"\n",
"np.random.seed(12345)\n",
"\n",
"df = pd.DataFrame(index=range(50000))\n",
"df[\"const\"] = 1\n",
"df[\"x\"] = np.random.uniform(size=50000)\n",
"df[\"e\"] = np.random.normal(0, 1, size=50000)\n",
"df[\"u\"] = np.random.normal(0, 1, size=50000)\n",
"df[\"y\"] = 2 + df[\"x\"] * 3 + df[\"e\"]\n",
"df[\"y_u\"] = df[\"y\"] + df[\"u\"]\n",
"df[\"x_u\"] = df[\"x\"] + df[\"u\"]\n",
"\n",
"print(sm.OLS(df[\"y\"], df[[\"const\", \"x\"]]).fit().summary())\n",
"print(sm.OLS(df[\"y_u\"], df[[\"const\", \"x\"]]).fit().summary())\n",
"print(sm.OLS(df[\"y\"], df[[\"const\", \"x_u\"]]).fit().summary())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "582dd42d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment