我尝试使用自己的数据复制文档中的示例:
>>> import numpy as np
>>> import statsmodels.api as sm
>>> data = sm.datasets.longley.load()
>>> data.exog = sm.add_constant(data.exog)
>>> ols_resid = sm.OLS(data.endog, data.exog).fit().resid
>>> res_fit = sm.OLS(ols_resid[1:], ols_resid[:-1]).fit()
>>> rho = res_fit.params
>>> from scipy.linalg import toeplitz
>>> order = toeplitz(np.arange(16))
>>> sigma = rho**order
>>> gls_model = sm.GLS(data.endog, data.exog, sigma=sigma)
>>> gls_results = gls_model.fit()
>>> print(gls_results.summary())
我的数据:
type(exog)
numpy.ndarray
type(endog)
numpy.ndarray
exog.shape
(58, 3)
endog.shape
(58, )
endog[0:5]
array([1. , 1.01541323, 1.15995317, 1.08084594, 1.25125068])
exog[0:5,:]
array([[1.0, 1.0, 1.0],
[1.0, 1.0230000000000243, 1.0465290000000498],
[1.0, 1.085402999999738, 1.1780996724084314],
[1.0, 1.1331607319999735, 1.2840532445467157],
[1.0, 1.1988840544557957, 1.4373229760283672]], dtype=object)
ols_resid = sm.OLS(endog, exog).fit().resid
TypeError: No loop matching the specified signature and casting
was found for ufunc svd_n_s
我不明白该错误信息。我认为,我正在忠实地复制文档中的示例。
您的建议将不胜感激。
答案 0 :(得分:0)
exog的设计矩阵具有dtype=object
,其数字运算未定义。
您需要将exog转换为float,例如
exog = exog.astype(np.float64)