r - Stata 与预测的标准差和 R 与预测的标准差有什么区别?

标签 r statistics stata

据我所知,StataR具有“预测”功能。我正在尝试使用 R 复制在 Stata 中执行的结果,结果涉及计算预测值的标准偏差。 R 中是否有一个功能,也许使用它的“预测”功能,可以让我这样做?我似乎无法完美地复制结果。如果有帮助,Stata 代码会执行以下操作:

reg Y X1 X2 if condition
predict resid, r
predict stdf, stdf

stdf 参数的定义是:

stdf calculates the standard error of the forecast, which is the standard error of the point prediction for 1 observation. It is commonly referred to as the standard error of the future or forecast value. By construction, the standard errors produced by stdf are always larger than those produced by stdp; see Methods and formulas in [R] predict

我一直在写的 R 代码是:

fit <- lm(Y ~ X1 + X2, data=df)
new.df <- data.frame(...) # This is a new data frame with my new data period I want to predict in
predict(fit, new.df, se.fit = TRUE)

但是,当我将标准误差转换为标准偏差时,它们与 Stata 输出不匹配。

提前致谢!

最佳答案

在我看来你需要:

 predict(fit, new.df, se.fit = TRUE, interval="prediction")

“标准误差”适用于均值估计值的置信限度,而预测误差可能很容易描述为预测值的“标准偏差”。

> dfrm <- data.frame(a=rnorm(30), drop=FALSE)
> dfrm$y <- 4+dfrm$a*5+0.5*rnorm(30)
> plot( dfrm$a, predict(mod) )
> plot( dfrm$a, predict(mod, newdata=dfrm) )
> points( rep(seq(-2,2,by=0.1),2),   # need two copies for upper and lower
          c(predict(mod, newdata=list(a=seq(-2,2,by=0.1)), 
                         interval="prediction")[, c("lwr","upr")]), 
          col="red")
> points(dfrm$a, dfrm$y, col="blue" )

enter image description here

关于r - Stata 与预测的标准差和 R 与预测的标准差有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32320046/

相关文章:

sas - 除 R 以外的其他统计软件包中的 Markdown

sql - 无法使用 sqldf 对 R 中的函数使用rank()

r - 使用以倒数第二个值作为 .init 参数的累加函数

R Shiny : How to add data tables to dynamically created tabs

MySQL 在另一个表中存储表的校验和

latex - 使用 frmttable 以日期格式显示汇总统计信息

r - 使用合并创建空白行

numpy - 加速矩阵求逆

python - Python 中的统计累加器

excel - 将矩阵从 Stata 12 导出到 Excel 或 MATLAB