6

R 的 stargazer 包有两个参数 covariate.labels 和 column.labels,用于自定义表格文本。

我想在这些论点中使用希腊语或数学表达式。我尝试了乳胶文本的标准语法,并尝试了标准 R 表达式,如下所示:

covariate.labels = c($\beta_{0}$, $\beta_{1}$)
covariate.labels = c(expression(beta[0]), expression(beta[1]))

我还尝试了上述的变体,但我还没有实现基本的数学符号注释。任何帮助表示赞赏。

4

2 回答 2

10

covariate.labels需要是一个字符向量。请记住,您需要在 R 字符串中使用另一个反斜杠来转义反斜杠。

stargazer(mtcars[,1:2],covariate.labels=c("$\\beta_{0}$", "$\\beta_{1}$"))

% Table created by stargazer v.4.5.3 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Wed, Feb 05, 2014 - 16:21:19
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
\hline \\[-1.8ex] 
$\beta_{0}$ & 32 & 20.091 & 6.027 & 10.400 & 33.900 \\ 
$\beta_{1}$ & 32 & 6.188 & 1.786 & 4 & 8 \\ 
\hline \\[-1.8ex] 
\normalsize 
\end{tabular} 
\end{table} 
于 2014-02-05T16:19:19.467 回答
1

如果您正在这样做type = "html",但可以使用 html 标签来修改表格元素。这对我有用:

model <- lm(mpg ~ cyl, mtcars)

stargazer(model,
         covariate.labels = c("<p>&beta;<sub>0</sub></p>",
                              "<p>&beta;<sub>1</sub></p>"))

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: mar., ago. 15, 2017 - 09:55:31 a. m.
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & mpg \\ 
\hline \\[-1.8ex] 
 <p>&beta;<sub>0</sub></p> & $-$2.876$^{***}$ \\ 
  & (0.322) \\ 
  & \\ 
 <p>&beta;<sub>1</sub></p> & 37.885$^{***}$ \\ 
  & (2.074) \\ 
  & \\ 
 \hline \\[-1.8ex] 
 Observations & 32 \\ 
R$^{2}$ & 0.726 \\ 
Adjusted R$^{2}$ & 0.717 \\ 
Residual Std. Error & 3.206 (df = 30) \\ 
F Statistic & 79.561$^{***}$ (df = 1; 30) \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

最终看起来像这样

于 2017-08-15T17:05:36.493 回答