【问题标题】:t-values and Pr(>|t|) for coefficients of numpy.polyfitnumpy.polyfit 系数的 t 值和 Pr(>|t|)
【发布时间】:2023-04-09 05:33:02
【问题描述】:

我想确定使用 numpy.polyfit 拟合某些数据的多项式模型中系数的重要性。

This 是我想使用 R 实现的一个示例。基本上,我需要使用 scipy/numpy 获取 R 的“摘要”函数输出的内容。有没有一种简单的方法可以使用 scipy/numpy(一些内置的辅助函数?)或者我应该使用 rpy 来代替?

【问题讨论】:

    标签: numpy statistics scipy regression rpy2


    【解决方案1】:

    使用统计模型:

    import pandas as pd
    import statsmodels.formula.api as smf
    df = pd.DataFrame(
        {"year":[1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969],
        "population":[4835, 4970, 5085, 5160, 5310, 5260, 5235, 5255, 5235, 5210, 5175]})
    df.year -= 1964
    
    results = smf.ols('population ~ year + I(year**2)', data=df).fit()
    print results.summary()
    

    这是输出:

                                OLS Regression Results                            
    ==============================================================================
    Dep. Variable:             population   R-squared:                       0.941
    Model:                            OLS   Adj. R-squared:                  0.926
    Method:                 Least Squares   F-statistic:                     63.48
    Date:                Fri, 07 Mar 2014   Prob (F-statistic):           1.23e-05
    Time:                        14:53:22   Log-Likelihood:                -54.089
    No. Observations:                  11   AIC:                             114.2
    Df Residuals:                       8   BIC:                             115.4
    Df Model:                           2                                         
    ================================================================================
                       coef    std err          t      P>|t|      [95.0% Conf. Int.]
    --------------------------------------------------------------------------------
    Intercept     5263.1585     17.655    298.110      0.000      5222.446  5303.871
    year            29.3182      3.696      7.933      0.000        20.796    37.841
    I(year ** 2)   -10.5886      1.323     -8.002      0.000       -13.640    -7.537
    ==============================================================================
    Omnibus:                       10.349   Durbin-Watson:                   1.669
    Prob(Omnibus):                  0.006   Jarque-Bera (JB):                4.954
    Skew:                           1.379   Prob(JB):                       0.0840
    Kurtosis:                       4.789   Cond. No.                         20.2
    ==============================================================================
    

    【讨论】:

    • 你知道我是否也可以使用 statsmodels 进行正则化最小二乘或岭回归吗?
    • 我在公式“人口〜年+ I(年**2)”中是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 2021-12-21
    • 2019-06-15
    • 2023-02-02
    • 2013-10-26
    • 2017-08-21
    相关资源
    最近更新 更多