I want to randomly draw N = 30 slope and intercept pairs, with replacement, and do it F = 5,000 times. For each draw I want to calculate the slope and intercept of the regression line and then plot the histogram of slope and intercept. Here is the code I have so far.
F = 10000 N = 30 X = sigma*(np.random.randn(F)/F) Y = beta*X + alpha + sigma*(np.random.randn(F)) Xbar = np.mean(X) Ybar = np.mean(Y) numer2 = 0 denom2 = 0 for i in range(F): for j in range(N): numer2 += (X[j]-Xbar)*(Y[j]-Ybar) denom2 += (X[j]-Xbar)**2 slope = numer2/denom2 intercept = Ybar - slope*Xbar plt.figure(1) plt.hist(slope, bins=50) plt.hist(intercept, bins=50) plt.grid() plt.show()
I want to get 30 slope and intercept pairs, 5,000 times. I thought the double for loop would do that. Unfortunately, all I can get is one value for each. How can I fix this?
https://stackoverflow.com/questions/66740154/python-random-draws-5-000-times March 22, 2021 at 11:56AM
没有评论:
发表评论