Statsmodels OLS 线性回归 - 为什么我有多个回归参数?
Statsmodels OLS Linear Regression - Why do I have multiple regression parameters?
我正在执行线性回归以拟合 y=x+c1+c2+c3+c4+...+cn(c1..cn 是协变量)。
输出汇总结果后发生了一些奇怪的事情,我不确定为什么会这样:
OLS Regression Results
==============================================================================
Dep. Variable: pgrs R-squared: 0.038
Model: OLS Adj. R-squared: -0.012
Method: Least Squares F-statistic: 0.7565
Date: Wed, 16 Aug 2017 Prob (F-statistic): 0.716
Time: 11:12:02 Log-Likelihood: -18.623
No. Observations: 284 AIC: 67.25
Df Residuals: 269 BIC: 122.0
Df Model: 14
Covariance Type: nonrobust
================================================================================
coef std err t P>|t| [0.025 0.975]
--------------------------------------------------------------------------------
Intercept 0.5331 0.272 1.957 0.051 -0.003 1.069
x[T.0] -0.2568 0.327 -0.786 0.433 -0.900 0.387
x[T.1] -0.0574 0.280 -0.205 0.837 -0.608 0.493
x[T.2] -0.1556 0.277 -0.562 0.575 -0.701 0.390
x[T.3] 0.0182 0.273 0.067 0.947 -0.519 0.555
x[T.4] -0.0114 0.271 -0.042 0.967 -0.545 0.523
x[T.5] 0.0067 0.272 0.025 0.980 -0.529 0.542
x[T.6] -0.0321 0.269 -0.119 0.905 -0.562 0.498
x[T.7] 0.0262 0.271 0.097 0.923 -0.507 0.559
x[T.8] -0.0542 0.270 -0.200 0.841 -0.586 0.478
x[T.9] -0.0529 0.272 -0.195 0.846 -0.588 0.482
c1 0.0625 0.039 1.615 0.107 -0.014 0.139
c2 -0.0016 0.007 -0.219 0.827 -0.016 0.013
c3 0.2052 0.356 0.576 0.565 -0.496 0.906
c4 0.0986 0.397 0.249 0.804 -0.682 0.880
==============================================================================
Omnibus: 2.789 Durbin-Watson: 1.865
Prob(Omnibus): 0.248 Jarque-Bera (JB): 3.018
Skew: -0.000 Prob(JB): 0.221
Kurtosis: 3.505 Cond. No. 525.
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
为什么我有多个 x 参数?只有当 x 是我的数据集中的特定特征时,我才会出现这种情况。有什么办法可以解决这个问题,或者这是某种预期的行为,这是什么意思?具体来说,[T.0], ... [T.9] 有什么意义吗?
我正在使用 statsmodels 来满足上述功能。
# Returns a string y ~ trait + c1 + ... + cn
f = math_expr([trait] + covariates, y)
lm = ols(formula=f, data=df).fit()
您的数据似乎没有被解释为数字,也许您的数据中有一个缺失值的占位符(例如“?”),这意味着整列将被分配给字符串类型。您需要将列转换为数值,例如,在导入数据框后粘贴这段代码:
df[column_name] = pd.to_numeric(df[column_name], errors='coerce')
第二个参数会将任何错误值(例如“?”)更改为数字 NaN。
我正在执行线性回归以拟合 y=x+c1+c2+c3+c4+...+cn(c1..cn 是协变量)。
输出汇总结果后发生了一些奇怪的事情,我不确定为什么会这样:
OLS Regression Results
==============================================================================
Dep. Variable: pgrs R-squared: 0.038
Model: OLS Adj. R-squared: -0.012
Method: Least Squares F-statistic: 0.7565
Date: Wed, 16 Aug 2017 Prob (F-statistic): 0.716
Time: 11:12:02 Log-Likelihood: -18.623
No. Observations: 284 AIC: 67.25
Df Residuals: 269 BIC: 122.0
Df Model: 14
Covariance Type: nonrobust
================================================================================
coef std err t P>|t| [0.025 0.975]
--------------------------------------------------------------------------------
Intercept 0.5331 0.272 1.957 0.051 -0.003 1.069
x[T.0] -0.2568 0.327 -0.786 0.433 -0.900 0.387
x[T.1] -0.0574 0.280 -0.205 0.837 -0.608 0.493
x[T.2] -0.1556 0.277 -0.562 0.575 -0.701 0.390
x[T.3] 0.0182 0.273 0.067 0.947 -0.519 0.555
x[T.4] -0.0114 0.271 -0.042 0.967 -0.545 0.523
x[T.5] 0.0067 0.272 0.025 0.980 -0.529 0.542
x[T.6] -0.0321 0.269 -0.119 0.905 -0.562 0.498
x[T.7] 0.0262 0.271 0.097 0.923 -0.507 0.559
x[T.8] -0.0542 0.270 -0.200 0.841 -0.586 0.478
x[T.9] -0.0529 0.272 -0.195 0.846 -0.588 0.482
c1 0.0625 0.039 1.615 0.107 -0.014 0.139
c2 -0.0016 0.007 -0.219 0.827 -0.016 0.013
c3 0.2052 0.356 0.576 0.565 -0.496 0.906
c4 0.0986 0.397 0.249 0.804 -0.682 0.880
==============================================================================
Omnibus: 2.789 Durbin-Watson: 1.865
Prob(Omnibus): 0.248 Jarque-Bera (JB): 3.018
Skew: -0.000 Prob(JB): 0.221
Kurtosis: 3.505 Cond. No. 525.
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
为什么我有多个 x 参数?只有当 x 是我的数据集中的特定特征时,我才会出现这种情况。有什么办法可以解决这个问题,或者这是某种预期的行为,这是什么意思?具体来说,[T.0], ... [T.9] 有什么意义吗?
我正在使用 statsmodels 来满足上述功能。
# Returns a string y ~ trait + c1 + ... + cn
f = math_expr([trait] + covariates, y)
lm = ols(formula=f, data=df).fit()
您的数据似乎没有被解释为数字,也许您的数据中有一个缺失值的占位符(例如“?”),这意味着整列将被分配给字符串类型。您需要将列转换为数值,例如,在导入数据框后粘贴这段代码:
df[column_name] = pd.to_numeric(df[column_name], errors='coerce')
第二个参数会将任何错误值(例如“?”)更改为数字 NaN。