Odds ratios instead of logits in stargazer() LaTeX output

牧云@^-^@ 提交于 2019-11-29 02:44:47

问题


When using stargazer to create a LaTeX table on a logistic regression object the standard behaviour is to output logit-values of each model. Is it possible to get exp(logit) instead? That is, can i get the Odds-ratios instead?

In the stargazer documentation the following mentions the "Coef"-argument, but I dont understand if this can enable the exp(logits).

Coef: a list of numerical vectors that will replace the default coefficient values for each model. Element names will be used to match coefficients to individual covariates, and should therefore match covariate names. A NULL vector indicates that, for a given model, the default set of coefficients should be used. By contrast, an NA vector means that all of the model’s coefficients should be left blank.


回答1:


As per symbiotic comment in 2014, more recent versions of ''stargazer'' have the options ''apply.*'' for ''coef'' ''se'' ''t'' ''p'' and ''ci'' allowing the direct transformation of these statistics.

apply.coef a function that will be applied to the coefficients.
apply.se a function that will be applied to the standard errors.
apply.t a function that will be applied to the test statistics.
apply.p a function that will be applied to the p-values.
apply.ci a function that will be applied to the lower and upper bounds of the confidence intervals.

Meaning you can directly use...

stargazer(model, 
          apply.coef = exp,
          apply.se   = exp)

EDIT : I have noticed however that simply exponentiating the CIs does not give what you would expect.

EDIT : You can obtain the correct CIs using the method described here.




回答2:


stargazer allows you to substitute a lot of things, dependent variable labels, covariate labels and so forth. To substitute those you need to supply a vector of variable labels, this is done to have publishable row names, instead of variable names from R by default.

So in order to have odds ratios, you need to supply a vector of odds ratios to stargazer. How do you obtain that vector? Very easily, actually. Let's say that your model is called model, then your code is:

coef.vector <- exp(model$coef)
stargazer(model,coef=list(coef.vector))

If you have multiple models in your table, then the list should be expanded, e.g. coef=list(coef.vector1,coef.vector2,...), where all vectors in the list would be derived from similar exponentiation as above.




回答3:


So, the issue is that you want to display the (non-log) odds ratio, but keep the test statistics based on the underlying linear model. By default, when you use one of the "apply" methods, such as apply.coef = exp, stargazer will recalculate the t statistics and p values. We don't want that. Also, the standard errors are in the log basis, but we can't just exponentiate them. My preferred approach is to:

  1. exponentiate the coefs in stargazer
  2. turn off the auto p and auto t
  3. report (untransformed) t-statistics in the table instead of standard errors

In code, this is:

stargazer(model, apply.coef=exp, t.auto=F, p.auto=F, report = "vct*")


来源:https://stackoverflow.com/questions/16236560/odds-ratios-instead-of-logits-in-stargazer-latex-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!