2

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)
ModalBro
  • 544
  • 5
  • 25

1 Answers1

2

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.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Awesome! That works perfectly! Hopefully the next version of Zelig can have a more intuitive method of getting these values... – ModalBro Dec 14 '17 at 19:24
  • I'm not claiming this is the only way. There may be a better way I just don't know about. I don't use the Zelig package myself.But I do know how to look through code to see how these values are being printed out. It may not be pretty but it works. – MrFlick Dec 14 '17 at 19:26