user51966
user51966

Reputation: 1057

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

I got the results from systemfit(), and tried to visualize the coefficients for each equation. I used coefplot() and to avoid using "$", I wrote coefplot(summary(fitsur)[["eq"]][1]).
However, I still got the error "$ operator is invalid for atomic vectors".
Could you help me to avoid this error?

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

Upvotes: 2

Views: 1005

Answers (1)

Marat Talipov
Marat Talipov

Reputation: 13304

It seems to me that coefplot(fitsur$eq[[1]]) might solve your problem.

Here is the reproducible example:

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...

Upvotes: 2

Related Questions