In stats models, I run a regression and get the following SE from the regression output:
SE(const) = 0.028
SE(AveBedrms) = .017
SE(HouseAge) = .0001
From the sample dataset, I randomly sample with replacement and run a regression 50000 times. I then compute the standard deviation of the coefficients from these regressions and get:
std const coeffs = 0.049039
std AveBedrms coeffs = 0.038270
std HouseAge coeffs = 0.000665
These are almost double what statsmodels computes. Am I doing something wrong?
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
from sklearn.datasets import fetch_california_housing
# Loading dataset
cali = fetch_california_housing(as_frame=True)
features = cali.feature_names
sub_features = ["AveBedrms", "HouseAge"] # features I will use to keep simple
df = cali.frame
X = sm.add_constant(df[sub_features])
model = sm.OLS(df.iloc[:, -1], X)
results = model.fit()
print(results.summary())
# SE(const) = 0.028
# SE(AveBedrms) = .017
# SE(HouseAge) = .0001
bootstrap_values = []
N = 50_000
for i in range(N):
df_sampled = df.sample(len(df), replace=True) # sample all values with replacement
# fit regression
X = sm.add_constant(df_sampled[sub_features])
results = sm.OLS(df_sampled.iloc[:, -1], X).fit()
# get coeff results and save
bootstrap_values.append(results.params)
# data frame of coeffs
df_bs = pd.concat(bootstrap_values, axis=1).T
print(df_bs.std(axis=0, ddof=2))
model.fit(cov_type="hc3")
. 20K is a large sample, so asymptotic cov_params should be close to bootstrap standard errors, unless there are large violations of the OLS assumptions. One likely candidate for that might be heteroskedastisity (non-constant error variance across observations). $\endgroup$AveBedrms
. How do parameter estimates differ from the bootstrap estimates? $\endgroup$