[Stats] How do you “Bootstrap”?

I. Bootstrap?

II. Inference v.s. Estimation

III. Asymptotic Hypothesis test

IV. Some codings

1. Estimation

beta_hat=inv(X.T@X)@X.T@yarray([[1.31986603e+02],
[9.49700802e+00],
[5.09767067e-02],
[4.56077098e-01]])

2. Construct covariance matrix

iden=np.identity(100,dtype=float)
M_x=iden-X@inv(X.T@X)@X.T
u_hat_un=M_x@y
def fvar_ols(u_hat_DGP):
s2=(u_hat_DGP.T@u_hat_DGP)/(n-k)
var_ols=s2*inv(X.T@X)
return var_ols
def fHC0(u_hat_DGP):
u_sq=np.square(u_hat_DGP)
omega0=np.diagflat(u_sq)
HC0=inv(X.T@X)@(X.T@omega0@X)@inv(X.T@X)
return HC0
P_x=X@inv(X.T@X)@X.T
ht=np.diag(P_x)
def fHC2(u_hat_DGP):
omega2_diag=[0 for i in range(n)
u_hat_DGP_sq=np.square(u_hat_DGP)
for i in range(n):
omega2_diag[i]=u_hat_DGP_sq[i]/(1-ht[i])
omega2=np.diagflat(omega2_diag)
HC2=inv(X.T@X)@(X.T@omega2@X)@inv(X.T@X)
return HC2

3. Wald Statistic and P values

R=np.matrix([[0,0,1,0],[0,0,0,1]])def coef(X,y):
beta_hat=inv(X.T@X)@X.T@y
return beta_hat
from scipy.stats import chi2
def p(var,X,y):
var_hat=var
beta_hat=coef(X,y)
Wald=(R@beta_hat).T@inv(R@var_hat@R.T)@(R@beta_hat)
pvalue=1-(chi2.cdf(Wald,2))
return np.array((Wald,pvalue)).reshape(2)

V. Conclusion

test_hat=np.array((p(var_ols,X,y)[0],p(HC0,X,y)[0],p(HC2,X,y)[0]),dtype=float).reshape(3)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store