1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import pandas as pd import numpy as np import statsmodels.api as sm from statsmodels.stats.outliers_influence import variance_inflation_factor from statsmodels.stats.diagnostic import het_breuschpagan, het_white,het_goldfeldquandt from patsy import dmatrices
data=pd.DataFrame() data=pd.DataFrame(pd.read_excel('C:\\Users\\cyx94a\\Desktop\\Python\\data\\al8-2.xls')) vars=['x','y'] df=data[vars]
y,X=dmatrices('y~x',data=df,return_type='dataframe')
print(data.describe()) print(data.corr())
model=sm.OLS(y,X) fit=model.fit() print(fit.summary())
X_with_const = sm.add_constant(X)
vif_values = [variance_inflation_factor(X_with_const.values, i) for i in range(X_with_const.shape[1])]
print("VIF values:", vif_values)
bpg_test = het_breuschpagan(fit.resid, X) print("Breusch-Pagan Test:", bpg_test)
white_test = het_white(fit.resid, X) print("White Test:", white_test)
gq_test=het_goldfeldquandt(fit.resid, X) print("Goldfeld-Quandt Test:",gq_test)
data=data.diff() data=data.dropna() x=np.array(data[['lr']]) y=np.array(data[['kf']]) X=sm.add_constant(x) model=sm.OLS(y,X) fit=model.fit() print(fit.summary())
|