Stargazer:仅省略星星以保持不变
Stargazer: omit stars for constant only
有时在报告回归结果时为常数项包含具有统计显着性的星号是很俗气的。是否可以配置 stargazer
为回归量保留星号,而不是为常数项保留星号?
fit <- lm(rating ~ complaints, data=attitude)
stargazer(fit)
您也可以使用 broom
包将拟合结果转换为数据框,然后为您满意的内容加星:
library("broom")
mod <- lm(mpg ~ wt + qsec, data = mtcars)
DF <- tidy(mod)
DF$stars <- c("", "***", "***") # inspect and add manually, or automate
并且 xtable
包可用于将其格式化为 LaTeX 或其他格式。
基本上,答案是使用 stargazer
的 p
参数。从那里,我只需要编写一个(系列)函数,它采用回归拟合列表并返回 p 值向量列表。然后我手动将截距的 p 值更改为 1,很快,截距上没有粘性星。此外,它无需手动 LaTeX 编辑即可重现!
commarobust <- function(fit){
require(sandwich)
require(lmtest)
coeftest(fit,vcovHC(fit, type="HC2"))
}
getrobustps <- function(fit){
robustfit <- commarobust(fit)
ps <- robustfit[,4]
ps["(Intercept)"] <- 1
return(ps)
}
makerobustpslist <- function(fitlist){
return(lapply(fitlist, FUN=getrobustps) )
}
然后在观星者电话中:
stargazer(fit_1, fit_2, fit_3, fit_4, fit_5,
p=makerobustpslist(list(fit_1, fit_2, fit_3, fit_4, fit_5)))
很有魅力。
有时在报告回归结果时为常数项包含具有统计显着性的星号是很俗气的。是否可以配置 stargazer
为回归量保留星号,而不是为常数项保留星号?
fit <- lm(rating ~ complaints, data=attitude)
stargazer(fit)
您也可以使用 broom
包将拟合结果转换为数据框,然后为您满意的内容加星:
library("broom")
mod <- lm(mpg ~ wt + qsec, data = mtcars)
DF <- tidy(mod)
DF$stars <- c("", "***", "***") # inspect and add manually, or automate
并且 xtable
包可用于将其格式化为 LaTeX 或其他格式。
基本上,答案是使用 stargazer
的 p
参数。从那里,我只需要编写一个(系列)函数,它采用回归拟合列表并返回 p 值向量列表。然后我手动将截距的 p 值更改为 1,很快,截距上没有粘性星。此外,它无需手动 LaTeX 编辑即可重现!
commarobust <- function(fit){
require(sandwich)
require(lmtest)
coeftest(fit,vcovHC(fit, type="HC2"))
}
getrobustps <- function(fit){
robustfit <- commarobust(fit)
ps <- robustfit[,4]
ps["(Intercept)"] <- 1
return(ps)
}
makerobustpslist <- function(fitlist){
return(lapply(fitlist, FUN=getrobustps) )
}
然后在观星者电话中:
stargazer(fit_1, fit_2, fit_3, fit_4, fit_5,
p=makerobustpslist(list(fit_1, fit_2, fit_3, fit_4, fit_5)))
很有魅力。