簡體   English   中英

百分比回歸-r,python和matlab中的結果不同

[英]regression for percentages - different results in r, python and matlab

我有百分比,需要計算回歸。 根據基本統計數據,使用邏輯回歸比OLS更好,因為百分比會使對連續且不受約束的值空間的要求無效。

到現在為止還挺好。 但是,我在R,Python和Matlab中得到了不同的結果。 實際上,Matlab甚至報告了python不會報告的重要值。

我的模型如下:

R:
summary(glm(foo ~ 1 + bar + baz  , family = "binomial", data = <<data>>))

Python via statsmodels:
smf.logit('foo ~ 1 + bar + baz', <<data>>).fit().summary()

Matlab:
fitglm(<<data>>,'foo ~ 1 + bar + baz','Link','logit')

Matlab當前產生最佳結果的地方。

可以有不同的初始化值嗎? 不同的求解器? 計算p值時alpha的不同設置? 如何至少在相似的數值范圍或檢測到的重要特征相同的情況下獲得相同的結果? 我不需要完全相等的數值輸出。

編輯

匯總統計

python:
Dep. Variable:  foo No. Observations:   104
Model:  Logit   Df Residuals:   98
Method: MLE Df Model:   5
Date:   Wed, 28 Aug 2019    Pseudo R-squ.:  inf
Time:   06:48:12    Log-Likelihood: -0.25057
converged:  True    LL-Null:    0.0000
LLR p-value:    1.000
coef    std err z   P>|z|   [0.025  0.975]
Intercept   -16.9863    154.602 -0.110  0.913   -320.001    286.028
bar -0.0278 0.945   -0.029  0.977   -1.880  1.824
baz 18.5550 280.722 0.066   0.947   -531.650    568.760
a   9.9996  153.668 0.065   0.948   -291.184    311.183
b   0.6757  132.542 0.005   0.996   -259.102    260.454
d   0.0005  0.039   0.011   0.991   -0.076  0.077


R:
glm(formula = myformula, family = "binomial", data = r_x)

Deviance Residuals: 
      Min         1Q     Median         3Q        Max  
-0.046466  -0.013282  -0.001017   0.006217   0.104467  

Coefficients:
                                       Estimate Std. Error z value Pr(>|z|)
(Intercept)                          -1.699e+01  1.546e+02  -0.110    0.913
bar                     -2.777e-02  9.449e-01  -0.029    0.977
baz                               1.855e+01  2.807e+02   0.066    0.947
a                       1.000e+01  1.537e+02   0.065    0.948
b                       6.757e-01  1.325e+02   0.005    0.996
d  4.507e-04  3.921e-02   0.011    0.991

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 0.049633  on 103  degrees of freedom
Residual deviance: 0.035684  on  98  degrees of freedom
AIC: 12.486

Matlab:
Estimated Coefficients:
                                            Estimate         SE         tStat        pValue  
                                            _________    __________    ________    __________

    (Intercept)                               -21.044         3.315     -6.3483    6.8027e-09
    bar                        -0.033507      0.022165     -1.5117       0.13383
    d    0.0016149    0.00083173      1.9416      0.055053
    baz                                    21.427        6.0132      3.5632    0.00056774
    a                            14.875        3.7828      3.9322    0.00015712
    b                           -1.2126        2.7535    -0.44038       0.66063


104 observations, 98 error degrees of freedom
Estimated Dispersion: 1.25e-06
F-statistic vs. constant model: 7.4, p-value = 6.37e-06

在MATLAB情況下,您實際上並沒有使用二項式分布。 您正在指定鏈接函數,但是該分布仍然是其正態分布的默認值,至少在百分比的樣本量較小的情況下,該分布不會提供預期的邏輯擬合。 它也為您提供了較低的p值,因為正態分布的方差比二項分布更受約束。

您需要將Distribution參數指定為Binomial

fitglm(<<data>>, 'foo ~ 1 + bar + baz', 'Distribution', 'binomial ', 'Link', 'logit')

R和Python代碼似乎匹配得很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM