从 Zelig sim() 对象中提取一阶差分均值的函数调用是什么?

What is the function call to extract the mean of first differences from a Zelig sim() object?

我正在尝试从我 运行 与 Zelig 的有序概率模型中提取一阶差分的平均值。如果我只是调用 sim() 函数创建的对象的名称,我会打印出 DV 所取每个值的平均值。我试图在 Rmarkdown 中引用这些值,所以我想以编程方式调用它们,而不是仅仅从打印输出中复制。

因此在下面的示例中,我希望能够为每个值 1:4 调用 "fd" 的平均值。

感谢您的帮助!

编辑:添加可重现的示例。

    library(zeligverse)
    library(dplyr)
    data(sanction)

    simulation_out <- zelig(factor(cost) ~ mil+coop, model="oprobit",data=sanction) %>% setx(z.out, coop = 1) %>%  setx1(z.out, coop = 4) %>% sim() 
    summary(simulation_out)

好的。看起来您可以使用

提取该信息
colMeans(simulation_out$sim.out$x1$fd[[1]])

我通过追踪 sumamry() 的作用发现了这一点。我运行

class(simulation_out)

看到我们有一个 S4 对象,然后尝试用

找到泛型方法的特定函数
selectMethod("summary", "Zelig-oprobit")

这表明它对自身调用 $summzarize。看看那个函数

 simulation_out$summarize

我们看到它从它的环境中调用了一个 show() 函数。我们可以通过

获得该功能
get("show", environment(simulation_out$summarize))

fd 信息似乎来自运行 print(stat(.self$sim.out$x1$fd, .self$num)) 的行 pstat(.self$sim.out$x1, "sim x1")。此 stat() 函数调用 statmat() 函数来计算均值和分位数。这里我们只使用 colMean 来为我们完成工作。