如何在模型列表上调用stargazer?

时间:2023-01-12 19:33:51

I just ran a series of models in a nice, flexible way that enforced data-code separation. I had a nice list of formulas and models in my configuration section which I lapply'd over to get a list of model objects. Now I want to display them in stargazer, but it doesn't take a list object. How do I do this without having to type out each list element?

我只是以一种很好的,灵活的方式运行了一系列模型,强制执行数据代码分离。我在配置部分有一个很好的公式和模型列表,我为了得到一个模型对象列表而给出了它。现在我想在stargazer中显示它们,但它不需要列表对象。如何在不输入每个列表元素的情况下执行此操作?

Reproducible example:

require(stargazer)
l <- list()
l$lm1 <- lm(rating ~ complaints + privileges + learning + raises + critical,
data=attitude)
l$lm2 <- lm(rating ~ complaints + privileges + learning, data=attitude)
## create an indicator dependent variable, and run a probit model
attitude$high.rating <- (attitude$rating > 70)
l$prbt <- glm(high.rating ~ learning + critical + advance, data=attitude,
family = binomial(link = "probit"))
stargazer( l[[1]], l[[2]], l[[3]], title="Results", align=TRUE, type="text")

2 个解决方案

#1


6  

Please make sure you are using an up-to-date version of the package. Starting with version 4.5.3 (available on CRAN since Nov 2013), stargazer has been able to accept lists of object in exactly the way you would expect:

请确保您使用的是最新版本的软件包。从版本4.5.3开始(自2013年11月起在CRAN上可用),stargazer能够以您期望的方式接受对象列表:

stargazer(l, title="Results", align=TRUE, type="text")

stargazer(l,title =“Results”,align = TRUE,type =“text”)

#2


4  

Use do.call:

do.call( stargazer, l ) 

However, this precludes passing in arguments in the usual way:

但是,这排除了以通常方式传递参数:

> do.call( stargazer, l, type="text" )
Error in do.call(stargazer, l, type = "text") : 
  unused argument (type = "text")

Therefore, you have to add the named arguments to the list:

因此,您必须将命名参数添加到列表中:

l$type <- "text"
l$align <- TRUE
l$title <- "Results"
do.call( stargazer, l )

Another way to do this is to curry the stargazer function:

另一种方法是调整观星者的功能:

require(functional)
sgCurried <- Curry( stargazer, type="text" ) # all arguments to stargazer go in here
do.call( sgCurried, l )

#1


6  

Please make sure you are using an up-to-date version of the package. Starting with version 4.5.3 (available on CRAN since Nov 2013), stargazer has been able to accept lists of object in exactly the way you would expect:

请确保您使用的是最新版本的软件包。从版本4.5.3开始(自2013年11月起在CRAN上可用),stargazer能够以您期望的方式接受对象列表:

stargazer(l, title="Results", align=TRUE, type="text")

stargazer(l,title =“Results”,align = TRUE,type =“text”)

#2


4  

Use do.call:

do.call( stargazer, l ) 

However, this precludes passing in arguments in the usual way:

但是,这排除了以通常方式传递参数:

> do.call( stargazer, l, type="text" )
Error in do.call(stargazer, l, type = "text") : 
  unused argument (type = "text")

Therefore, you have to add the named arguments to the list:

因此,您必须将命名参数添加到列表中:

l$type <- "text"
l$align <- TRUE
l$title <- "Results"
do.call( stargazer, l )

Another way to do this is to curry the stargazer function:

另一种方法是调整观星者的功能:

require(functional)
sgCurried <- Curry( stargazer, type="text" ) # all arguments to stargazer go in here
do.call( sgCurried, l )