【问题标题】:Length of NULL cannot be changed error when creating a regression table using stargazer使用 stargazer 创建回归表时无法更改 NULL 长度错误
【发布时间】:2020-04-12 19:24:11
【问题描述】:

我一直在尝试使用 R Markdown 中的 Stargazer 包创建回归表,但我不断收到错误消息:NULL 的长度无法更改。

这是我的回归表代码:

Model_4 <- lm(formula = demsat ~ education + province + age + sex_r + ethnic + emp_status + sat_govt + ptfeel_cons, data = CES2015 )

probit.model <- glm(demsat ~ education + province + age + sex_r + ethnic + emp_status + sat_govt + ptfeel_cons, data = CES2015)

stargazer(Model_1, probit.model, title = "Table of Regression Model 1 to 4", style = "default", type = "latex")

这是它给我的输出,后面是错误消息:

length of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changedlength of NULL cannot be changed
% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Sun, Apr 12, 2020 - 15:54:24
\begin{table}[!htbp] \centering 
  \caption{Table of Regression Model 1 to 4} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lcc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\ 
\cline{2-3} 
\\[-1.8ex] & \multicolumn{2}{c}{demsat} \\ 
\\[-1.8ex] & \textit{OLS} & \textit{normal} \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 education & $-$0.014$^{***}$ & $-$0.014$^{***}$ \\ 
  & (0.003) & (0.003) \\ 
  & & \\ 
 province & $-$0.002 & $-$0.002 \\ 
  & (0.002) & (0.002) \\ 
  & & \\ 
 age & 0.00002 & 0.00002 \\ 
  & (0.00002) & (0.00002) \\ 
  & & \\ 
 sex\_r & 0.003 & 0.003 \\ 
  & (0.013) & (0.013) \\ 
  & & \\ 
 ethnic & 0.004$^{***}$ & 0.004$^{***}$ \\ 
  & (0.001) & (0.001) \\ 
  & & \\ 
 emp\_status & 0.006$^{**}$ & 0.006$^{**}$ \\ 
  & (0.003) & (0.003) \\ 
  & & \\ 
 sat\_govt & 0.250$^{***}$ & 0.250$^{***}$ \\ 
  & (0.020) & (0.020) \\ 
  & & \\ 
 ptfeel\_cons & $-$0.012$^{***}$ & $-$0.012$^{***}$ \\ 
  & (0.001) & (0.001) \\ 
  & & \\ 
 Constant & 2.945$^{***}$ & 2.945$^{***}$ \\ 
  & (0.167) & (0.167) \\ 
  & & \\ 
\hline \\[-1.8ex] 
Observations & 3,911 & 3,911 \\ 
R$^{2}$ & 0.200 &  \\ 
Adjusted R$^{2}$ & 0.199 &  \\ 
Log Likelihood &  & $-$7,464.311 \\ 
Akaike Inf. Crit. &  & 14,946.620 \\ 
Residual Std. Error & 1.633 (df = 3902) &  \\ 
F Statistic & 122.238$^{***}$ (df = 8; 3902) &  \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

这个错误是什么意思?我怎样才能让我的回归表出现?

谢谢。

【问题讨论】:

  • 我已将其更新为实际代码
  • 您已经向我们展示了创建Model_4 的代码,但您将Model_1 传递给stargazer()

标签: r-markdown linear-regression stargazer


【解决方案1】:

Stargazer 可以生成三种格式类型的表格:文本、html 和 Latex。默认为 Latex,这是您生成的输出格式。

Latex 广泛用于科学出版领域,并且非常适合在 PDF 中生成表格。在 R Markdown 中,您需要在代码块头中使用 knitr 块选项 results = 'asis' 开始代码块。这告诉 R Markdown 根本不要尝试重新格式化输出,以便可以将乳胶表代码解释为“asis”。简而言之,你的块头应该包括这个:

{r results = 'asis'}

【讨论】:

    猜你喜欢
    • 2020-10-04
    • 2021-01-10
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 2017-01-25
    相关资源
    最近更新 更多