Question

I want to extract the Pr(>|t|) column after using either ivreg from the "AER" package or tsls from the "sem" package. Both give a list of terms which is similar and does not seem to provide what I am looking for.

ivregest <- ivreg(mdetect~bednet | treat1+treat2, data=simdata)
> names(ivregest)
 [1] "coefficients"  "residuals"     "fitted.values" "weights"      
 [5] "offset"        "n"             "nobs"          "rank"         
 [9] "df.residual"   "cov.unscaled"  "sigma"         "call"         
 [13] "formula"       "terms"         "levels"        "contrasts"    
 [17] "model"         "y"

tslsest <-  tsls(mdetect~bednet , ~ treat1+treat2, data=simdata)
> names(tslsest)
[1] "n"             "p"             "coefficients"  "V"            
[5] "s"             "residuals"     "response"      "model.matrix" 
[9] "instruments"   "weights"       "response.name" "formula"

The p though promising looking only provides a count of the number of parameters being estimated in the second stage regression. Yet if I use the summary command on either of the these objects it will return a p value.

So I would really like two questions answered: 1. Where can I find that p-value? 2. How can I find all of the hidden attributes of objects so that if I am looking for the F-stat next time or whatever I know where to look? names() does not seem to be sufficient.

Thank you very much for any help you can provide!

Était-ce utile?

La solution

First, some model taken from the help file of function ivreg.

library(AER)
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)

## model 
fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + 
            tdiff + I(tax/cpi),
            data = CigarettesSW, subset = year == "1995")

p-values, t-values and so are calculated only when you call summary() function on your model. At this time actually function summary.ivreg() is called. So if you need to get only p-values you should save result of summary() as some object. This object (list) contains several parts and coefficients are stored in matrix named coefficients.

sum.res<-summary(fm)
names(sum.res)
 [1] "call"          "terms"         "residuals"     ""              "coefficients"  "sigma"        
 [7] "df"            "r.squared"     "adj.r.squared" "waldtest"      "vcov"   

To get all coefficients:

sum.res$coefficients
               Estimate Std. Error   t value     Pr(>|t|)
(Intercept)   9.8949555  1.0585599  9.347563 4.120910e-12
log(rprice)  -1.2774241  0.2631986 -4.853461 1.496034e-05
log(rincome)  0.2804048  0.2385654  1.175379 2.460247e-01

p-values are stored in 4. column of this matrix:

sum.res$coefficients[,4]
 (Intercept)  log(rprice) log(rincome) 
4.120910e-12 1.496034e-05 2.460247e-01 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top