R: 使用 coefplot() 时出错 ("operator is invalid for atomic vectors")

R: Error in using coefplot() ("operator is invalid for atomic vectors")

我从 systemfit() 得到了结果,并尝试可视化每个方程的系数。 我使用了 coefplot() 并且为了避免使用“$”,我写了 coefplot(summary(fitsur)[["eq"]][1])
但是,我仍然收到错误“$ operator is invalid for atomic vectors”。
你能帮我避免这个错误吗?

fitsur <- systemfit(list(EQ1 = rp1, EQ2 = rp2, EQ3 = rp3, EQ4 = rp6), data=data)
> summary(fitsur)[["eq"]][1]
[[1]]

OLS estimates for 'EQ1' (equation 1)

                  Estimate   Std. Error  t value  Pr(>|t|)   
(Intercept)   -2.081244665  0.820103650 -2.53778 0.0114454 * 
ID110         0.110331812  0.068478736  1.61118 0.1077442   
ID130         0.022217695  0.024279274  0.91509 0.3605675   
FPP01         -0.022953616  0.032193881 -0.71298 0.4761763   
DEP04          0.005921742  0.002822725  2.09788 0.0363958 * 
Inc_Consensus  2.004021829  0.932511596  2.14906 0.0320889 * 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.483239 on 522 degrees of freedom
Number of observations: 535 Degrees of Freedom: 522 
SSR: 1148.399037 MSE: 2.199998 Root MSE: 1.483239 
Multiple R-Squared: 0.069067 Adjusted R-Squared: 0.047666 

> coefplot(summary(fitsur)[["eq"]][1])
 Error: $ operator is invalid for atomic vectors

在我看来 coefplot(fitsur$eq[[1]]) 可能会解决您的问题。

这是可重现的例子:

library(systemfit)
library(coefplot)

# this paragraph was borrowed from the systemfit manual
data( "Kmenta" )
eqDemand <- consump ~ price + income
eqSupply <- consump ~ price + farmPrice + trend
system <- list( demand = eqDemand, supply = eqSupply )
## OLS estimation
fitols <- systemfit( system, data=Kmenta )

names(fitsur) #
# [1] "eq"           "call"         "coefficients" "coefCov"      "residCovEst" 
# [6] "residCov"     "method"       "rank"         "df.residual"  "iter"        
# [11] "control"      "panelLike"   

str(fitsur$eq,list.len=2)
# List of 2
# $ :List of 14
# ..$ eqnNo          : int 1
# ..$ eqnLabel       : chr "demand"
# .. [list output truncated]
# ..- attr(*, "class")= chr "systemfit.equation"
# $ :List of 14
# ..$ eqnNo          : int 2
# ..$ eqnLabel       : chr "supply"
# .. [list output truncated]
# ..- attr(*, "class")= chr "systemfit.equation"

coefplot(fitsur$eq[[1]])
# Hit <Return> to see next plot: 
# ...shows the plot...