2

I know that Zelig is a wrapper... But still, it provides nice simulation capabilities (which I wouldn't be able to do on my own).

Lets say I have this data,

set.seed(123)
x1 = rnorm(5)         
x2 = rnorm(5)
z = 1 + 2*x1 + 3*x2
pr = 1/(1+exp(-z))
y = rbinom(5,1,pr)

df = data.frame(y=y,x1=x1,x2=x2)

Now, we estimate the model,

library(Zelig)    
relogit <- zelig(y ~ x1 + x2, model = "relogit", data = df)

And now, we (try to) make the table

library(texreg)
texreg(relogit)

... only to get this error.

Error in (function (classes, fdef, stable):
unable to find an inherited method for function ‘extract’ for 
signature ‘"Zelig-relogit"’

I am aware of the $getvcov() and $getcoef() functions. But I wonder how I could make a straightforward table using texreg. Any advice will be greatly appreciated. Thanks!

1 Answers1

4

texreg uses a generic function called extract to pull the relevant data from a model object and then processes the resulting texreg object to create a regression table. In order to extend the range of models texreg is applicable to, you can write your own methods for the extract function.

Zelig-relogit objects apparently store a glm object with the relevant data somewhere inside the object and attach a different class name to it. So it should be relatively straightforward to create a copy of this sub-object, fix its class name, and apply the existing extract.glm method to this object to extract the data. More specifically:

# extension for Zelig-relogit objects (Zelig package >= 5.0)
extract.Zeligrelogit <- function(model, include.aic = TRUE, include.bic = TRUE, 
    include.loglik = TRUE, include.deviance = TRUE, include.nobs = TRUE, ...) {
  g <- model$zelig.out$z.out[[1]]
  class(g) <- "glm"
  e <- extract(g, include.aic = include.aic, include.bic = include.bic, 
      include.loglik = include.loglik, include.deviance = include.deviance, 
      include.nobs = include.nobs, ...)
  return(e)
}

setMethod("extract", signature = className("Zelig-relogit", "Zelig"), 
    definition = extract.Zeligrelogit)

This code creates a Zelig-relogit method for the extract function. You can use it by typing something like screenreg(relogit), where relogit is the name of your Zelig-relogit object. The result should look like this:

==================================
                Model 1           
----------------------------------
(Intercept)     -9446502571.59 ***
                     (62615.78)   
x1              19409089045.70 ***
                    (141084.20)   
x2                856836055.47 ***
                     (98175.65)   
----------------------------------
AIC                       6.00    
BIC                       4.83    
Log Likelihood           -0.00    
Deviance                  0.00    
Num. obs.                 5       
==================================
*** p < 0.001, ** p < 0.01, * p < 0.05

More generally, if you want to make any Zelig model work with texreg, you should look at model$zelig.out$z.out[[1]] to find the relevant information. I will include the Zelig-relogit extract method in the next texreg release.

Philip Leifeld
  • 2,253
  • 15
  • 24