小编pab*_*cal的帖子

R预测包VS Stata边距

我正在从Stata切换到R,当我使用预测来计算边际pred并且Stata命令边缘的结果将变量的值固定为x时,我发现结果不一致.这是一个例子:

library(dplyr)
library(prediction)

d <- data.frame(x1 = factor(c(1,1,1,2,2,2), levels = c(1, 2)),
            x2 = factor(c(1,2,3,1,2,3), levels = c(1, 2, 3)),
            x3 = factor(c(1,2,1,2,1,2), levels = c(1, 2)),
            y = c(3.1, 2.8, 2.5, 4.3, 4.0, 3.5))

m2 <- lm(y ~ x1 + x2 + x3, d)
summary(m2)

marg2a <- prediction(m2, at = list(x2 = "1"))
marg2b <- prediction(m2, at = list(x1 = "1"))

marg2a %>%
  select(x1, fitted) %>%
  group_by(x1) %>%
  summarise(error = mean(fitted))

marg2b %>%
  select(x2, fitted) …
Run Code Online (Sandbox Code Playgroud)

r prediction lm stata

4
推荐指数
1
解决办法
553
查看次数

标签 统计

lm ×1

prediction ×1

r ×1

stata ×1