我正在使用spdep运行一个使用杜宾滞后模型的空间回归。这种类型的模型返回每个回归系数的直接、间接和总影响及其显着性水平。
有没有像texreg这样的R库,可以很好地组织德宾滞后模型的输出,并提供关于直接、间接和总体影响的信息?
可重现的例子:
library(spdep)
example(columbus)
listw <- nb2listw(col.gal.nb)
# spatial regression - Durbin Model
mobj <- lagsarlm(CRIME ~ INC + HOVAL, columbus, listw, type="mixed")
summary(mobj)
# Calculate direct and indirect impacts
W <- as(listw, "CsparseMatrix")
trMatc <- trW(W, type="mult")
trMC <- trW(W, type="MC")
imp <- impacts(mobj, tr=trMC, R=100)
sums <- summary(imp, zstats=T)
# Return Effects
data.frame(sums$res)
# Return p-values
data.frame(sums$pzmat)发布于 2017-08-31 11:46:10
我不确定是否有一个现有的函数可以为这种类型的模型对象创建一个漂亮的查看表,但是(通过一些努力)你可以自己创建一个。
下面是一个包含您的代码和三个附加代码块的rmarkdown文档。第一个组合了系数和p值数据。接下来的两个为latex表生成两个不同的选项。
我使用sums$res和sums$pzmat表示表值,使用tidyverse函数组合系数估计值和p值并编辑列名,使用kable和kableExtra包生成latex输出。
rmarkdown文档
---
title: "Coefficient Table for Durbin Lag Model"
author: "eipi10"
date: "8/30/2017"
output: pdf_document
---
```{r setup, include=FALSE}回声(knitr::opts_chunk$set= FALSE,message=FALSE,warning=FALSE)
库(Spdep)
库(Texreg)
示例(Columbus)
listw <- nb2listw(col.gal.nb)
```{r}空间回归- Durbin模型
mobj <- lagsarlm(犯罪~ INC + HOVAL,哥伦布,listw,type=“混合”)
#摘要(Mobj)
计算直接和间接影响
W <- as(listw,"CsparseMatrix")
trMatc <- trW(W,type="mult")
trMC <- trW(W,type="MC")
imp <-影响(mobj、tr=trMC、R=100)
sums <- summary(imp,zstats=T)
返回效果
data.frame(sums$res)
返回p值
data.frame(sums$pzmat)
```{r extractTableData}库(Knitr)
库(KableExtra)
库(Dplyr)
库(Tidyr)
库(字符串)
提取系数和p值
tab =bind_rows(sum$res) %>% t %>% as.data.frame %>%
setNames(.,names( %>% $res[1]))%>%
变异(Coef_Type=str_to_title(行名(.),
Value_Type="Estimate") %>% bind_rows(sums$pzmat %>% t %>% as.data.frame %>%
mutate(Coef_Type=rownames(.), Value_Type="p-value")) %>% gather(key,value,Inc.,HOVAL)
```{r table1}将表格整形为所需的输出格式
tab1 =选项卡%>%
联合(coef,key,Value_Type) %>%
扩展(coef,value) %>%
mutate_if(is.numeric,mutate_if,3)
将列名称更改为我们希望在输出表中看到的名称
名称(Tab1)= c("",gsub("._(.)","\1",names(tab1)-1))
输出latex表,包括用于标记系数名称的额外标题行
kable(tab1,booktabs=TRUE,format="latex") %>%
add_header_above(setNames(c("",2,2),c("",sort(rowname(sum$pzmat) %>%
Kable_styling(position=“中心”)
\vspace{1cm}
```{r table2}将表格整形为所需的输出格式
tab2 =选项卡%>%
联合(coef,Coef_Type,Value_Type) %>%
扩展(coef,value) %>%
mutate_if(is.numeric,mutate_if,3)
将列名称更改为我们希望在输出表中看到的名称
名称(Tab2)=c(“系数”,gsub("._(.)","\1",names(tab2)-1))
输出latex表,包括用于标记系数名称的额外标题行
kable(tab2,booktabs=TRUE,format="latex") %>%
add_header_above(setNames( c(“",rep(2,3)),c(”",colname(sum$pzmat) %>%
Kable_styling(position=“中心”)
PDF输出文档

https://stackoverflow.com/questions/45971419
复制相似问题