[英]How can I use TexReg (1.36.4) for a “relogit” model estimated using Zelig (v. 5.0-13)?
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). 我知道
Zelig
是一个包装器...但是,它仍然提供了不错的模拟功能(我自己无法做到)。
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. 我知道
$getvcov()
和$getcoef()
函数。 But I wonder how I could make a straightforward table using texreg
. 但是我不知道如何使用
texreg
创建一个简单的表。 Any advice will be greatly appreciated. 任何建议将不胜感激。 Thanks!
谢谢!
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. texreg
使用称为extract
的通用函数从模型对象中extract
相关数据,然后处理所得的texreg
对象以创建回归表。 In order to extend the range of models texreg
is applicable to, you can write your own methods for the extract
function. 为了扩展
texreg
适用的模型范围,您可以编写自己的extract
函数方法。
Zelig-relogit
objects apparently store a glm
object with the relevant data somewhere inside the object and attach a different class name to it. Zelig-relogit
对象显然将glm
对象及其相关数据存储在对象内部某处,并为其附加了不同的类名。 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. 因此,创建该子对象的副本,修复其类名并将现有的
extract.glm
方法应用于该对象以提取数据应该相对简单。 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. 此代码为
extract
函数创建一个Zelig-relogit
方法。 You can use it by typing something like screenreg(relogit)
, where relogit
is the name of your Zelig-relogit
object. 您可以通过输入诸如
screenreg(relogit)
之类的名称来使用它,其中relogit
是Zelig-relogit
对象的名称。 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. 更一般而言,如果要使任何
Zelig
模型与texreg
一起texreg
,则应查看model$zelig.out$z.out[[1]]
来找到相关信息。 I will include the Zelig-relogit
extract
method in the next texreg
release. 我将在下一个
texreg
版本中包括Zelig-relogit
extract
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.