2016-08-22 71 views
2

儘管我對於閱讀多元迴歸在Python大多建議中Statsmodels的OLS功能的線程。下面是我遇到了,我試圖通過對能夠解釋該基金的回報率14個獨立的變量回歸它的收益來解釋基金的回報率(HYFAX綠色高亮顯示)的問題。這應該有一個重要的F檢驗,並且在通過這些因子的逐步迭代之後發現具有最高調整R平方的最佳擬合模型。有沒有辦法在Python中做到這一點?多元迴歸(含因子選擇)

Fund returns vs Factors

回答

1

聽起來像是你只是想看看從你的模型擬合結果。繼承人1個預測,但很容易地擴展到14個例子:

導入statsmodels並指定要建立模型(這是你包括你14個預測):

import statsmodels.api as sm 

#read in your data however you want and assign your y, x1...x14 variables 

model = sm.OLS(x, y) 

擬合模型:

results = model.fit() 

現在只是顯示你的模型擬合的摘要:

print(results.summary()) 

釷在會給你調整後的R平方值,F檢驗值,二級權重等應該是這個樣子:

      OLS Regression Results        
============================================================================== 
Dep. Variable:      x R-squared:      0.601 
Model:       OLS Adj. R-squared:     0.594 
Method:     Least Squares F-statistic:      87.38 
Date:    Wed, 24 Aug 2016 Prob (F-statistic):   3.56e-13 
Time:      19:51:25 Log-Likelihood:    -301.81 
No. Observations:     59 AIC:        605.6 
Df Residuals:      58 BIC:        607.7 
Df Model:       1           
Covariance Type:   nonrobust           
============================================================================== 
       coef std err   t  P>|t|  [95.0% Conf. Int.] 
------------------------------------------------------------------------------ 
y    0.8095  0.087  9.348  0.000   0.636  0.983 
============================================================================== 
Omnibus:      0.119 Durbin-Watson:     1.607 
Prob(Omnibus):     0.942 Jarque-Bera (JB):    0.178 
Skew:       -0.099 Prob(JB):      0.915 
Kurtosis:      2.818 Cond. No.       1.00 
==============================================================================