import wooldridge as wooimport numpy as npimport pandas as pdimport statsmodels.api as smimport statsmodels.formula.api as smfimport patsy as pthprice1 = woo.dataWoo('hprice1')# estimate model:reg = smf.ols(formula='np.log(price) ~ np.log(lotsize) + np.log(sqrft) + bdrms',data=hprice1)results = reg.fit()# BP test:y, X_bp = pt.dmatrices('np.log(price) ~ np.log(lotsize) + np.log(sqrft) + bdrms',data=hprice1, return_type='dataframe')result_bp = sm.stats.diagnostic.het_breuschpagan(results.resid, X_bp)bp_statistic = result_bp[0]bp_pval = result_bp[1]print(f'bp_statistic: {bp_statistic}\n')print(f'bp_pval: {bp_pval}\n')# White test:X_wh = pd.DataFrame({'const': 1, 'fitted_reg': results.fittedvalues,'fitted_reg_sq': results.fittedvalues ** 2})result_white = sm.stats.diagnostic.het_breuschpagan(results.resid, X_wh)white_statistic = result_white[0]white_pval = result_white[1]print(f'white_statistic: {white_statistic}\n')print(f'white_pval: {white_pval}\n')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。