by jrd79 · 4y ago · 0 comments
"Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something."
import numpy as np
import statsmodels.api as sm
n = 1000
desired_R2 = 0.05
mu = 0
sigma_noise = 0.1
sigma = np.sqrt(sigma_noise*2*(desired_R2/(1-desired_R2)))
X = np.random.normal(mu, sigma, n)
noise = np.random.normal(0, sigma_noise, n)
y = X + noise
X = sm.add_constant(X)
model = sm.OLS(y, X).fit()
model.summary()