Presenting Zelig Logistic Regression in Knitr with Stargazer or Other Package
Stargazer appears to take most Zelig model objects except logistic regression:
m1 <- zelig(voted ~ . - weight_full - by,
weights = mydata$weight_full,
data=mydata,
model="logit",
cite = FALSE)
I receive the following warning from the above code:
# Error in envRefInferField(x, what, getClass(class(x)), selfEnv)
# ‘result’ is not a valid field or method name for reference class “Zelig-logit”
Anyone have any alternatives for presenting such a model in a regression output table using Knitr to produce a .tex/.Rnw file?
r latex knitr
add a comment |
Stargazer appears to take most Zelig model objects except logistic regression:
m1 <- zelig(voted ~ . - weight_full - by,
weights = mydata$weight_full,
data=mydata,
model="logit",
cite = FALSE)
I receive the following warning from the above code:
# Error in envRefInferField(x, what, getClass(class(x)), selfEnv)
# ‘result’ is not a valid field or method name for reference class “Zelig-logit”
Anyone have any alternatives for presenting such a model in a regression output table using Knitr to produce a .tex/.Rnw file?
r latex knitr
Can you provide a reproducible example of this?
– CL.
Feb 14 '16 at 10:09
The title of this question doesn't match the actual question. There is nothing about stargazer in the example...
– Ista
Mar 1 '16 at 16:22
add a comment |
Stargazer appears to take most Zelig model objects except logistic regression:
m1 <- zelig(voted ~ . - weight_full - by,
weights = mydata$weight_full,
data=mydata,
model="logit",
cite = FALSE)
I receive the following warning from the above code:
# Error in envRefInferField(x, what, getClass(class(x)), selfEnv)
# ‘result’ is not a valid field or method name for reference class “Zelig-logit”
Anyone have any alternatives for presenting such a model in a regression output table using Knitr to produce a .tex/.Rnw file?
r latex knitr
Stargazer appears to take most Zelig model objects except logistic regression:
m1 <- zelig(voted ~ . - weight_full - by,
weights = mydata$weight_full,
data=mydata,
model="logit",
cite = FALSE)
I receive the following warning from the above code:
# Error in envRefInferField(x, what, getClass(class(x)), selfEnv)
# ‘result’ is not a valid field or method name for reference class “Zelig-logit”
Anyone have any alternatives for presenting such a model in a regression output table using Knitr to produce a .tex/.Rnw file?
r latex knitr
r latex knitr
asked Feb 9 '16 at 22:13
user3614648user3614648
556720
556720
Can you provide a reproducible example of this?
– CL.
Feb 14 '16 at 10:09
The title of this question doesn't match the actual question. There is nothing about stargazer in the example...
– Ista
Mar 1 '16 at 16:22
add a comment |
Can you provide a reproducible example of this?
– CL.
Feb 14 '16 at 10:09
The title of this question doesn't match the actual question. There is nothing about stargazer in the example...
– Ista
Mar 1 '16 at 16:22
Can you provide a reproducible example of this?
– CL.
Feb 14 '16 at 10:09
Can you provide a reproducible example of this?
– CL.
Feb 14 '16 at 10:09
The title of this question doesn't match the actual question. There is nothing about stargazer in the example...
– Ista
Mar 1 '16 at 16:22
The title of this question doesn't match the actual question. There is nothing about stargazer in the example...
– Ista
Mar 1 '16 at 16:22
add a comment |
3 Answers
3
active
oldest
votes
The Zelig package now includes a convenience function that makes it easy to extract fitted model objects:
stargazer(from_zelig_model(m1))
should produce the desired result.
add a comment |
This might be coming too late, but a solution is to re-estimate the model with glm() from base R. The following code worked for me, on a logistic regression estimated with the new reference classes syntax for Zelig.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
model1 <- zlogit$new()
model1$zelig(admit ~ gpa,
data=mydata)
library(stargazer)
stargazer(glm(model1$zelig.out$z.out[[1]], family=binomial(link = "logit")))
The same strategy would work when estimating a linear regression with Zelig.
add a comment |
Building on Constantin's helpful answer, I created a simple function unzelig to take a glm zelig object and return a conventional glm object:
# extract data + model + family zelig object, return glm object
unzelig <- function(zelig_model) {
z_out <- zelig_model$zelig.out$z.out[[1]]
z_family <- z_out[["family"]][["family"]]
# when zelig(model = 'ls') assign family <- "gaussian"
if(is.null(z_family)) {z_family <- "gaussian"}
glm(z_out,
family = z_family)
}
# simple example
z1 <- zelig(mpg ~ cyl, model = 'ls', data = mtcars, cite = FALSE)
z2 <- zelig(I(mpg > 15) ~ cyl, model = 'logit', data = mtcars, cite = FALSE)
z3 <- zelig(as.integer(mpg) ~ cyl, model = 'poisson', data = mtcars, cite = FALSE)
g1 <- unzelig(z1)
g2 <- unzelig(z2)
g3 <- unzelig(z3)
stargazer(g1, g2, g3, type = 'text')
# error check
g1 <- glm(mpg ~ cyl, data = mtcars)
g2 <- glm(I(mpg > 15) ~ cyl, family = binomial, data = mtcars)
g3 <- glm(as.integer(mpg) ~ cyl, family = poisson, data = mtcars)
stargazer(g1, g2, g3, type = 'text')
Also, there's an in-development function to convert some non-Zelig objects to Zelig-friendly objects with a command to_zelig. This would allow estimating a model with standard R functions like lm or glm, using stargazer or another package to generate a table and then converting the object to use Zelig functions like setx and sim. See more, here:
http://docs.zeligproject.org/reference/to_zelig.html
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35303249%2fpresenting-zelig-logistic-regression-in-knitr-with-stargazer-or-other-package%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Zelig package now includes a convenience function that makes it easy to extract fitted model objects:
stargazer(from_zelig_model(m1))
should produce the desired result.
add a comment |
The Zelig package now includes a convenience function that makes it easy to extract fitted model objects:
stargazer(from_zelig_model(m1))
should produce the desired result.
add a comment |
The Zelig package now includes a convenience function that makes it easy to extract fitted model objects:
stargazer(from_zelig_model(m1))
should produce the desired result.
The Zelig package now includes a convenience function that makes it easy to extract fitted model objects:
stargazer(from_zelig_model(m1))
should produce the desired result.
answered Nov 23 '18 at 1:28
IstaIsta
7,85112526
7,85112526
add a comment |
add a comment |
This might be coming too late, but a solution is to re-estimate the model with glm() from base R. The following code worked for me, on a logistic regression estimated with the new reference classes syntax for Zelig.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
model1 <- zlogit$new()
model1$zelig(admit ~ gpa,
data=mydata)
library(stargazer)
stargazer(glm(model1$zelig.out$z.out[[1]], family=binomial(link = "logit")))
The same strategy would work when estimating a linear regression with Zelig.
add a comment |
This might be coming too late, but a solution is to re-estimate the model with glm() from base R. The following code worked for me, on a logistic regression estimated with the new reference classes syntax for Zelig.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
model1 <- zlogit$new()
model1$zelig(admit ~ gpa,
data=mydata)
library(stargazer)
stargazer(glm(model1$zelig.out$z.out[[1]], family=binomial(link = "logit")))
The same strategy would work when estimating a linear regression with Zelig.
add a comment |
This might be coming too late, but a solution is to re-estimate the model with glm() from base R. The following code worked for me, on a logistic regression estimated with the new reference classes syntax for Zelig.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
model1 <- zlogit$new()
model1$zelig(admit ~ gpa,
data=mydata)
library(stargazer)
stargazer(glm(model1$zelig.out$z.out[[1]], family=binomial(link = "logit")))
The same strategy would work when estimating a linear regression with Zelig.
This might be coming too late, but a solution is to re-estimate the model with glm() from base R. The following code worked for me, on a logistic regression estimated with the new reference classes syntax for Zelig.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
model1 <- zlogit$new()
model1$zelig(admit ~ gpa,
data=mydata)
library(stargazer)
stargazer(glm(model1$zelig.out$z.out[[1]], family=binomial(link = "logit")))
The same strategy would work when estimating a linear regression with Zelig.
answered Feb 21 '17 at 13:44
Constantin Manuel BosancianuConstantin Manuel Bosancianu
794
794
add a comment |
add a comment |
Building on Constantin's helpful answer, I created a simple function unzelig to take a glm zelig object and return a conventional glm object:
# extract data + model + family zelig object, return glm object
unzelig <- function(zelig_model) {
z_out <- zelig_model$zelig.out$z.out[[1]]
z_family <- z_out[["family"]][["family"]]
# when zelig(model = 'ls') assign family <- "gaussian"
if(is.null(z_family)) {z_family <- "gaussian"}
glm(z_out,
family = z_family)
}
# simple example
z1 <- zelig(mpg ~ cyl, model = 'ls', data = mtcars, cite = FALSE)
z2 <- zelig(I(mpg > 15) ~ cyl, model = 'logit', data = mtcars, cite = FALSE)
z3 <- zelig(as.integer(mpg) ~ cyl, model = 'poisson', data = mtcars, cite = FALSE)
g1 <- unzelig(z1)
g2 <- unzelig(z2)
g3 <- unzelig(z3)
stargazer(g1, g2, g3, type = 'text')
# error check
g1 <- glm(mpg ~ cyl, data = mtcars)
g2 <- glm(I(mpg > 15) ~ cyl, family = binomial, data = mtcars)
g3 <- glm(as.integer(mpg) ~ cyl, family = poisson, data = mtcars)
stargazer(g1, g2, g3, type = 'text')
Also, there's an in-development function to convert some non-Zelig objects to Zelig-friendly objects with a command to_zelig. This would allow estimating a model with standard R functions like lm or glm, using stargazer or another package to generate a table and then converting the object to use Zelig functions like setx and sim. See more, here:
http://docs.zeligproject.org/reference/to_zelig.html
add a comment |
Building on Constantin's helpful answer, I created a simple function unzelig to take a glm zelig object and return a conventional glm object:
# extract data + model + family zelig object, return glm object
unzelig <- function(zelig_model) {
z_out <- zelig_model$zelig.out$z.out[[1]]
z_family <- z_out[["family"]][["family"]]
# when zelig(model = 'ls') assign family <- "gaussian"
if(is.null(z_family)) {z_family <- "gaussian"}
glm(z_out,
family = z_family)
}
# simple example
z1 <- zelig(mpg ~ cyl, model = 'ls', data = mtcars, cite = FALSE)
z2 <- zelig(I(mpg > 15) ~ cyl, model = 'logit', data = mtcars, cite = FALSE)
z3 <- zelig(as.integer(mpg) ~ cyl, model = 'poisson', data = mtcars, cite = FALSE)
g1 <- unzelig(z1)
g2 <- unzelig(z2)
g3 <- unzelig(z3)
stargazer(g1, g2, g3, type = 'text')
# error check
g1 <- glm(mpg ~ cyl, data = mtcars)
g2 <- glm(I(mpg > 15) ~ cyl, family = binomial, data = mtcars)
g3 <- glm(as.integer(mpg) ~ cyl, family = poisson, data = mtcars)
stargazer(g1, g2, g3, type = 'text')
Also, there's an in-development function to convert some non-Zelig objects to Zelig-friendly objects with a command to_zelig. This would allow estimating a model with standard R functions like lm or glm, using stargazer or another package to generate a table and then converting the object to use Zelig functions like setx and sim. See more, here:
http://docs.zeligproject.org/reference/to_zelig.html
add a comment |
Building on Constantin's helpful answer, I created a simple function unzelig to take a glm zelig object and return a conventional glm object:
# extract data + model + family zelig object, return glm object
unzelig <- function(zelig_model) {
z_out <- zelig_model$zelig.out$z.out[[1]]
z_family <- z_out[["family"]][["family"]]
# when zelig(model = 'ls') assign family <- "gaussian"
if(is.null(z_family)) {z_family <- "gaussian"}
glm(z_out,
family = z_family)
}
# simple example
z1 <- zelig(mpg ~ cyl, model = 'ls', data = mtcars, cite = FALSE)
z2 <- zelig(I(mpg > 15) ~ cyl, model = 'logit', data = mtcars, cite = FALSE)
z3 <- zelig(as.integer(mpg) ~ cyl, model = 'poisson', data = mtcars, cite = FALSE)
g1 <- unzelig(z1)
g2 <- unzelig(z2)
g3 <- unzelig(z3)
stargazer(g1, g2, g3, type = 'text')
# error check
g1 <- glm(mpg ~ cyl, data = mtcars)
g2 <- glm(I(mpg > 15) ~ cyl, family = binomial, data = mtcars)
g3 <- glm(as.integer(mpg) ~ cyl, family = poisson, data = mtcars)
stargazer(g1, g2, g3, type = 'text')
Also, there's an in-development function to convert some non-Zelig objects to Zelig-friendly objects with a command to_zelig. This would allow estimating a model with standard R functions like lm or glm, using stargazer or another package to generate a table and then converting the object to use Zelig functions like setx and sim. See more, here:
http://docs.zeligproject.org/reference/to_zelig.html
Building on Constantin's helpful answer, I created a simple function unzelig to take a glm zelig object and return a conventional glm object:
# extract data + model + family zelig object, return glm object
unzelig <- function(zelig_model) {
z_out <- zelig_model$zelig.out$z.out[[1]]
z_family <- z_out[["family"]][["family"]]
# when zelig(model = 'ls') assign family <- "gaussian"
if(is.null(z_family)) {z_family <- "gaussian"}
glm(z_out,
family = z_family)
}
# simple example
z1 <- zelig(mpg ~ cyl, model = 'ls', data = mtcars, cite = FALSE)
z2 <- zelig(I(mpg > 15) ~ cyl, model = 'logit', data = mtcars, cite = FALSE)
z3 <- zelig(as.integer(mpg) ~ cyl, model = 'poisson', data = mtcars, cite = FALSE)
g1 <- unzelig(z1)
g2 <- unzelig(z2)
g3 <- unzelig(z3)
stargazer(g1, g2, g3, type = 'text')
# error check
g1 <- glm(mpg ~ cyl, data = mtcars)
g2 <- glm(I(mpg > 15) ~ cyl, family = binomial, data = mtcars)
g3 <- glm(as.integer(mpg) ~ cyl, family = poisson, data = mtcars)
stargazer(g1, g2, g3, type = 'text')
Also, there's an in-development function to convert some non-Zelig objects to Zelig-friendly objects with a command to_zelig. This would allow estimating a model with standard R functions like lm or glm, using stargazer or another package to generate a table and then converting the object to use Zelig functions like setx and sim. See more, here:
http://docs.zeligproject.org/reference/to_zelig.html
edited Nov 25 '18 at 17:39
answered Aug 15 '18 at 23:22
Omar WasowOmar Wasow
35848
35848
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35303249%2fpresenting-zelig-logistic-regression-in-knitr-with-stargazer-or-other-package%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you provide a reproducible example of this?
– CL.
Feb 14 '16 at 10:09
The title of this question doesn't match the actual question. There is nothing about stargazer in the example...
– Ista
Mar 1 '16 at 16:22