Created
December 20, 2014 23:51
-
-
Save cancan101/61aef85e62f7ee19e827 to your computer and use it in GitHub Desktop.
Statsmodels Formula
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:968c8a914ea58c2d9f281bf1a4807e0855bcde20b39626d57618599147f74244" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import statsmodels.formula.api as smf" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"N = 10000" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"x = np.random.normal(size=N)\n", | |
"y = x * 1.344 + 1344" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"df = pd.DataFrame({'x': x, 'y': y})" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"model = smf.ols(formula=\"y ~ x\", data=df)\n", | |
"fit = model.fit()\n", | |
"fit.summary()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"html": [ | |
"<table class=\"simpletable\">\n", | |
"<caption>OLS Regression Results</caption>\n", | |
"<tr>\n", | |
" <th>Dep. Variable:</th> <td>y</td> <th> R-squared: </th> <td> 1.000</td> \n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Model:</th> <td>OLS</td> <th> Adj. R-squared: </th> <td> 1.000</td> \n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Method:</th> <td>Least Squares</td> <th> F-statistic: </th> <td>5.434e+27</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Date:</th> <td>Sat, 20 Dec 2014</td> <th> Prob (F-statistic):</th> <td> 0.00</td> \n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Time:</th> <td>18:50:53</td> <th> Log-Likelihood: </th> <td>2.5612e+05</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>No. Observations:</th> <td> 10000</td> <th> AIC: </th> <td>-5.122e+05</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Df Residuals:</th> <td> 9998</td> <th> BIC: </th> <td>-5.122e+05</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Df Model:</th> <td> 1</td> <th> </th> <td> </td> \n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Covariance Type:</th> <td>nonrobust</td> <th> </th> <td> </td> \n", | |
"</tr>\n", | |
"</table>\n", | |
"<table class=\"simpletable\">\n", | |
"<tr>\n", | |
" <td></td> <th>coef</th> <th>std err</th> <th>t</th> <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Intercept</th> <td> 1344.0000</td> <td> 1.82e-14</td> <td> 7.37e+16</td> <td> 0.000</td> <td> 1344.000 1344.000</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>x</th> <td> 1.3440</td> <td> 1.82e-14</td> <td> 7.37e+13</td> <td> 0.000</td> <td> 1.344 1.344</td>\n", | |
"</tr>\n", | |
"</table>\n", | |
"<table class=\"simpletable\">\n", | |
"<tr>\n", | |
" <th>Omnibus:</th> <td> 0.108</td> <th> Durbin-Watson: </th> <td> 0.019</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Prob(Omnibus):</th> <td> 0.947</td> <th> Jarque-Bera (JB): </th> <td> 0.131</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Skew:</th> <td>-0.002</td> <th> Prob(JB): </th> <td> 0.937</td>\n", | |
"</tr>\n", | |
"<tr>\n", | |
" <th>Kurtosis:</th> <td> 2.983</td> <th> Cond. No. </th> <td> 1.02</td>\n", | |
"</tr>\n", | |
"</table>" | |
], | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 5, | |
"text": [ | |
"<class 'statsmodels.iolib.summary.Summary'>\n", | |
"\"\"\"\n", | |
" OLS Regression Results \n", | |
"==============================================================================\n", | |
"Dep. Variable: y R-squared: 1.000\n", | |
"Model: OLS Adj. R-squared: 1.000\n", | |
"Method: Least Squares F-statistic: 5.434e+27\n", | |
"Date: Sat, 20 Dec 2014 Prob (F-statistic): 0.00\n", | |
"Time: 18:50:53 Log-Likelihood: 2.5612e+05\n", | |
"No. Observations: 10000 AIC: -5.122e+05\n", | |
"Df Residuals: 9998 BIC: -5.122e+05\n", | |
"Df Model: 1 \n", | |
"Covariance Type: nonrobust \n", | |
"==============================================================================\n", | |
" coef std err t P>|t| [95.0% Conf. Int.]\n", | |
"------------------------------------------------------------------------------\n", | |
"Intercept 1344.0000 1.82e-14 7.37e+16 0.000 1344.000 1344.000\n", | |
"x 1.3440 1.82e-14 7.37e+13 0.000 1.344 1.344\n", | |
"==============================================================================\n", | |
"Omnibus: 0.108 Durbin-Watson: 0.019\n", | |
"Prob(Omnibus): 0.947 Jarque-Bera (JB): 0.131\n", | |
"Skew: -0.002 Prob(JB): 0.937\n", | |
"Kurtosis: 2.983 Cond. No. 1.02\n", | |
"==============================================================================\n", | |
"\n", | |
"Warnings:\n", | |
"[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n", | |
"\"\"\"" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment