本文介绍了numpy.polyfit 系数的 t 值和 Pr(>|t|)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 numpy.polyfit 确定拟合到某些数据的多项式模型中系数的显着性.
I want to determine the significance of the coefficients in a polynomial model fitted to some data using numpy.polyfit.
这个是我想使用 R 实现的一个例子.基本上,我需要使用 scipy/numpy 获取 R 的摘要"函数输出.有没有一种简单的方法可以使用 scipy/numpy(一些内置的帮助函数?)或者我应该使用 rpy 代替?
This is an example of what I want to achieve using R. Basically, I need to get what R's "summary" function outputs with scipy/numpy. Is there an easy way to do this with scipy/numpy (some built-in helper function?) or should I just go with rpy instead?
推荐答案
使用 statsmodels:
Use statsmodels:
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
==============================================================================
这篇关于numpy.polyfit 系数的 t 值和 Pr(>|t|)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!