splm 包:尝试使用 spgm() 在单回归 SEM 上使用仪器时出错

如何解决splm 包:尝试使用 spgm() 在单回归 SEM 上使用仪器时出错

当我尝试使用 spgm() 估计一个 SEM 模型时,只有一个回归量(它也是内生的,必须进行检测),该模型给出以下错误Error in as.matrix(Z) %*% as.matrix(betaGLS) : non-conformable arguments

可重现的示例如下:

library(splm)
library(plm)

sessionInfo()
## R version 4.0.5 (2021-03-31)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19042)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=galician_Spain.1252  LC_CTYPE=galician_Spain.1252    LC_MONETARY=galician_Spain.1252 LC_NUMERIC=C                   
## [5] LC_TIME=galician_Spain.1252    
## 
## attached base packages:
## [1] stats     graphics  Grdevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] xtable_1.8-4     kableExtra_1.3.4 nortest_1.0-4    knitr_1.31       giscoR_0.2.2     stargazer_5.2.2  broom_0.7.5      spatialreg_1.1-5
##  [9] Matrix_1.3-2     plotly_4.9.3     rgdal_1.5-23     splm_1.5-2       plm_2.4-1        spdep_1.1-5      spData_0.3.8     sp_1.4-5        
## [17] sf_0.9-7         readODS_1.7.0    forcats_0.5.1    stringr_1.4.0    dplyr_1.0.5      purrr_0.3.4      readr_1.4.0      tidyr_1.1.3     
## [25] tibble_3.0.6     ggplot2_3.3.3    tidyverse_1.3.0  texreg_1.37.5   
## 
## loaded via a namespace (and not attached):
##  [1] colorspace_2.0-0   deldir_0.2-10      pryr_0.1.4         ellipsis_0.3.1     class_7.3-18       fs_1.5.0           rstudioapi_0.13   
##  [8] fansi_0.4.2        lubridate_1.7.10   xml2_1.3.2         codetools_0.2-18   splines_4.0.5      ibdreg_0.3.1       spam_2.6-0        
## [15] Formula_1.2-4      jsonlite_1.7.2     dbplyr_2.1.0       compiler_4.0.5     httr_1.4.2         backports_1.2.1    assertthat_0.2.1  
## [22] lazyeval_0.2.2     cli_2.3.1          htmltools_0.5.1.1  tools_4.0.5        dotCall64_1.0-1    coda_0.19-4        gtable_0.3.0      
## [29] glue_1.4.2         gmodels_2.18.1     Rcpp_1.0.6         cellranger_1.1.0   raster_3.4-5       vctrs_0.3.6        svglite_2.0.0     
## [36] gdata_2.18.0       nlme_3.1-152       lmtest_0.9-38      xfun_0.22          rbibutils_2.0      rvest_1.0.0        lifecycle_1.0.0   
## [43] gtools_3.8.2       LearnBayes_2.15.1  MASS_7.3-53.1      zoo_1.8-8          scales_1.1.1       miscTools_0.6-26   hms_1.0.0         
## [50] parallel_4.0.5     sandwich_3.0-0     expm_0.999-6       bdsmatrix_1.3-4    stringi_1.5.3      highr_0.8          e1071_1.7-4       
## [57] boot_1.3-27        systemfonts_1.0.1  Rdpack_2.1.1       rlang_0.4.10       pkgconfig_2.0.3    evaluate_0.14      lattice_0.20-41   
## [64] htmlwidgets_1.5.3  tidyselect_1.1.0   magrittr_2.0.1     R6_2.5.0           generics_0.1.0     DBI_1.1.1          pillar_1.5.1      
## [71] haven_2.3.1        withr_2.4.1        units_0.7-0        modelr_0.1.8       Crayon_1.4.1       KernSmooth_2.23-18 utf8_1.1.4        
## [78] rmarkdown_2.7      maxLik_1.4-6       grid_4.0.5         readxl_1.3.1       data.table_1.14.0  webshot_0.5.2      reprex_1.0.0      
## [85] digest_0.6.27      classInt_0.4-3     munsell_0.5.0      viridisLite_0.3.0
data(Produc) 
data(usaww)

head(Produc[c("gsp","pcap","pc","hwy")])
##     gsp     pcap       pc     hwy
## 1 28418 15032.67 35793.80 7325.80
## 2 29375 15501.94 37299.91 7525.94
## 3 31303 15972.41 38670.30 7765.42
## 4 33430 16406.26 40084.01 7907.66
## 5 33749 16762.67 42057.31 8025.52
## 6 33604 17316.26 43971.71 8158.23
GM_SEM_ins <- spgm(log(gsp) ~  log(pc),data=Produc,endog = ~ log(pc),instruments = ~log(hwy),lag = FALSE,spatial.error = TRUE,method = "w2sls",listw = usaww)
## Warning in if (model == "fixed" & !isTRUE(attr(terms(formula),"intercept"))) formula <- as.formula(paste(attr(terms(formula),: the condition has
## length > 1 and only the first element will be used

在这里我们可以看到我提到的错误

## Error in as.matrix(Z) %*% as.matrix(betaGLS): non-conformable arguments

我试图估计相同的方程,但没有在公式中指定内生变量,但只出现了 rho 估计值,旁边没有任何标准误差:

GM_SEM_ins_2 <- spgm(log(gsp) ~  1,: the condition has
## length > 1 and only the first element will be used
summary(GM_SEM_ins_2)
## Spatial panel fixed effects GM model
##  
## 
## Call:
## spgm(formula = log(gsp) ~ 1,data = Produc,listw = usaww,##     spatial.error = TRUE,endog = ~log(pc),##     method = "w2sls")
## 
## Residuals:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.327   1.012   1.232   1.233   1.480   2.012 
## 
## Estimated spatial coefficient,variance components and theta:
## [1] 0.56111 # This is supposed to be the rho coefficient
## 
## Coefficients:
##         Estimate Std. Error t-value  Pr(>|t|)    
## log(pc) 0.878445   0.031545  27.847 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

对出了什么问题有什么建议吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?