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

187 Views Asked by At

I am trying to extract the mean value of the first differences from an ordered probit model I ran with Zelig. If I just call the name of the object created by the sim() function, I get a print-out of the mean values for each value the DV takes. I'm trying to reference these values in Rmarkdown, so I'd like to call them programatically rather than just copy from the printout.

So in the example below, I'd like to be able to call the mean values for "fd" for each value 1:4.

Thanks for any help you might have!

EDIT: Adding reproducible example.

    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)
1

There are 1 best solutions below

2
On BEST ANSWER

OK. It looks like you can extract that information with

colMeans(simulation_out$sim.out$x1$fd[[1]])

I found that by tracking down what sumamry() does. I ran

class(simulation_out)

to see we have an S4 object and then tried to find the specific function for the generic method with

selectMethod("summary", "Zelig-oprobit")

which shows it calls $summzarize on itself. And looking at that function

 simulation_out$summarize

we see that it calls a show() function from it's environment. We can get that function with

get("show", environment(simulation_out$summarize))

The fd information seems to come from the line pstat(.self$sim.out$x1, "sim x1") which runs print(stat(.self$sim.out$x1$fd, .self$num)). This stat() function calls a statmat() function which calculates the mean and quantiles. here we just use colMean to do the work for us.