【问题标题】:urca R Package: How to create latex output for Johansen results?urca R 包:如何为 Johansen 结果创建乳胶输出?
【发布时间】:2017-05-15 21:09:41
【问题描述】:

我正在使用 GNU R 的包 urca 使用 Johansen 方法进行一些协整分析。虽然实际分析工作得很好,但我无法将协整模型的结果放入 LaTeX 表中以正确记录结果。

如何将 urca 包中估计的 VECM 导出到 LaTeX 表中?

什么有效:当我在 URCA 返回的 VECM 上运行 summary 时获得的信息基本上返回了我想要在表中拥有的信息。但是,手动提取它是一件痛苦的事情 - 我无法在 cajorls 中找到标准错误。

查看我的问题的代码

test <- data.frame( a = cumsum(runif(500)) + runif(500))
test$b <- test$a + runif(500);
summary(cajorls(ca.jo(test))$rlm)
# i want the info displayed on screen here to go to a latex table

屏幕上的示例输出:包括标准错误和 p 值 -

> summary(cajorls(ca.jo(test))$rlm)
Response a.d :

Call:
lm(formula = a.d ~ ect1 + constant + a.dl1 + b.dl1 - 1, data = data.mat)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.26742 -0.29212 -0.00504  0.29866  1.29933 

Coefficients:
         Estimate Std. Error t value Pr(>|t|)    
ect1     -0.01465    0.10661  -0.137    0.891    
constant  0.65066    0.06231  10.443  < 2e-16 ***
a.dl1    -0.37889    0.08852  -4.280 2.24e-05 ***
b.dl1     0.05575    0.07497   0.744    0.457    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.4806 on 494 degrees of freedom
Multiple R-squared:  0.545, Adjusted R-squared:  0.5413 
F-statistic: 147.9 on 4 and 494 DF,  p-value: < 2.2e-16

将 VECM 导出为乳胶表的理想解决方案

我的理想解决方案是允许我使用现有的包,如 stargazer,并在输出中添加自定义统计信息(例如自相关)。

解决方案可能需要安装外部包或包含自定义代码。

【问题讨论】:

  • summary(cajorls(ca.jo(test))$rlm)summary.lm 类的对象列表,每个系列一个;它们应该包含您正在寻找的所有统计数据(特别是系数及其标准误差在coefficients 之下)。您可以使用这些信息来构建您想要的任何表,我不确定哪些包在这里最有用。
  • @ChrisHaug 非常感谢这个指针,我将在下面发布我的完整解决方案。

标签: r


【解决方案1】:

cajorls 方法返回summary.lm 对象的列表,正如上面的评论中所指出的。它不返回lm 对象,这使得创建表变得困难;例如,stargazer 很难适应处理摘要对象。然而,另一个 CRAN 包 - 称为 texreg 1 - 可以相对轻松地完成工作。

这需要两个步骤:

扩展texreg 以处理summary.lm 对象

在撰写本文时,texreg 本身无法与摘要对象一起使用;相反,它需要lm 对象(如stargazer)——尽管几乎所有信息都是从摘要对象中获取的。值得庆幸的是,解决这个限制非常容易。只需复制并粘贴相关 Github 问题中的代码:Workaround: How to render summary.lm objects using texreg

渲染表格

 > mysum <- summary(cajorls(ca.jo(test))$rlm)
 > screenreg(list(mysum[[1]], mysum[[2]]))

 =================================
            Model 1     Model 2   
 ---------------------------------
 ect1         0.14        1.18 ***
             (0.10)      (0.12)   
 constant     0.74 ***    1.27 ***
             (0.06)      (0.07)   
 a.dl1       -0.35 ***    0.66 ***
             (0.08)      (0.09)   
 b.dl1       -0.01       -1.04 ***
             (0.07)      (0.08)   
 ---------------------------------
 R^2          0.56        0.56    
 Adj. R^2     0.55        0.55    
 Num. obs.  498         498       
 RMSE         0.47        0.54    
 =================================
 *** p < 0.001, ** p < 0.01, * p < 0.05

奖励:将 VECM 的自定义测试统计添加到 texreg 乳胶表

texreg 允许我们简单地将拟合优度度量添加到“提取的”模型摘要中。优点:快速简单。缺点:没有重要意义的星星。

作为一个例子,让我们为残差的正态性添加夏皮罗检验的 p 值:

 mm <- lapply(mysum, function(mod) {
   tr <- extract(mod)
   tr@gof <- c(tr@gof, shapiro.test(mod$residuals)$p.value);
   tr@gof.names <- c(tr@gof.names, "Shapiro Test")
   tr@gof.decimal <- c(tr@gof.decimal, TRUE);
   return(tr)
 })
 screenreg(mm);

【讨论】:

  • 感谢美丽的解决方案。 “Model 1”、“Model 2”应该分别是“a.d”和“b.d”吗?如果是这样,我该如何修改列的名称?
  • 你需要给screenreg/texreg添加一个参数,就像custom.model.names = c("a.d","b.d")!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多