import numpy as npimport pandas as pdimport statsmodels.formula.api as smfimport scipy.stats as stats# set the random seed:np.random.seed(1234567)# set sample size and number of simulationsn = 1000r = 10000# set true parameters:beta0 = 1beta1 = 0.5su = 2sx = 1ex = 4# initialize b0 and b1 to store results later:b0 = np.empty(r)b1 = np.empty(r)# repeat r times:for i in range(r):# draw a sample:x = stats.norm.rvs(ex, sx, size=n)u = stats.norm.rvs(0, su, size=n)y = beta0 + beta1 * x + udf = pd.DataFrame({'y': y, 'x': x})# estimate OLS:reg = smf.ols(formula='y ~ x', data=df)results = reg.fit()b0[i] = results.params['Intercept']b1[i] = results.params['x']
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。