Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mixtape/python/ols3.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 lines (21 sloc)
730 Bytes
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
import numpy as np | |
import pandas as pd | |
import statsmodels.api as sm | |
import statsmodels.formula.api as smf | |
from itertools import combinations | |
import plotnine as p | |
# read data | |
import ssl | |
ssl._create_default_https_context = ssl._create_unverified_context | |
def read_data(file): | |
return pd.read_stata("https://github.com/scunning1975/mixtape/raw/master/" + file) | |
coefs = np.zeros(1000) | |
for i in range(1000): | |
tb = pd.DataFrame({ | |
'x': 9*np.random.normal(size=10000), | |
'u': 36*np.random.normal(size=10000)}) | |
tb['y'] = 3 + 2*tb['x'].values + tb['u'].values | |
reg_tb = sm.OLS.from_formula('y ~ x', data=tb).fit() | |
coefs[i] = reg_tb.params['x'] | |
p.ggplot() +\ | |
p.geom_histogram(p.aes(x=coefs), binwidth = 0.01) |