【发布时间】:2019-02-05 11:41:29
【问题描述】:
在python中求一个拟合模型的协方差矩阵(相当于python中的vcov()(R函数))
lmfit <- lm(formula = Y ~ X, data=Data_df)
lmpred <- predict(lmfit, newdata=Data_df, se.fit=TRUE, interval = "prediction")
std_er <- sqrt(((X0) %*% vcov(lmfit)) %*% t(X0))
试图在 python 中转换上述代码。为此,我需要找到拟合模型的协方差矩阵,即 vcov。 我将无法使用 np.cov() 作为我试图找到模型的协方差矩阵。
我已经使用了 statsmodels.regression.linear_model.OLSResults.cov_params(),但我没有得到与 R 中相同的值。
【问题讨论】:
-
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读the Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。不清楚你在这里问什么。
-
对于这样的问题,拥有 a) 一些数据、b) R 代码和 c) Python 代码来重现您所做的事情并查看您的预期结果会很有帮助是。
标签: python r linear-regression statsmodels