[R-SIG-Finance] TSLS: R^2 extraction and autocorrelation and heterokedasticity tests
spencerg
spencer.graves at prodsyse.com
Fri May 15 05:50:00 CEST 2009
Dear Achim: Thanks for the clarification. sg
Achim Zeileis wrote:
> On Thu, 14 May 2009, spencerg wrote:
>
>> What code did you use to produce "output"?
>
> He probably has used tsls() from "sem". ivreg() in "AER" also provides
> two-stage least squares but along with a few more methods, such as
> terms(), model.matrix() etc.
>
> This will be sufficient to call bptest() etc. from "lmtest" without
> error. However, this might be misleading. Internally, many "lmtest"
> functions re-fit the linear model and it depends on the test function
> and how the ivreg model was fitted whether what happens. Some
> functions internally re-fit the right model, others might re-fit the
> usual OLS model. I have never thought about using the "lmtest" tests
> with "ivreg" objects, I'll try to incorporate that in future updates.
>
> In the meantime, I recommend that you re-fit the second stage of the
> 2SLS "by hand" and then call the lmtest functionality. That way you
> can be sure that the second stage model is really used. In pseudo-code:
> fm_2sls <- ivreg(y ~ x1 + x2 | z1 + z2 + z3, data = mydata)
> fm_aux <- lm(model.response(model.frame(fm_2sls)) ~
> model.matrix(fm_2sls)[,-1])
> bptest(fm_aux)
>
> etc.
> Z
>
>>
>> Have you tried "str(output)" and "names(output)"?
>>
>>
>> If this is not enough to help you answer your question, you might try
>> rephrasing your question using commented, minimal, self-contained,
>> reproducible code, as suggested in the posting guide
>> "http://www.R-project.org/posting-guide.html".
>>
>>
>> Spencer Graves
>>
>>
>> josé maria Rodriguez wrote:
>>> Hi,
>>>
>>> I'm actually I?m performing a TSLS linear multiple regression on
>>> annually
>>> data which go from 1971 to 1997. After performing the TSLS
>>> regression, I
>>> tried to extract the R squared value using ?output$r.squared?
>>> function and
>>> to perform autocorrelation (Durbin Watson and Breush Godfrey) and
>>> heterokedasticity tests (Breush-pagan and Goldfeld Quandt) but I have
>>> errors messages. More specifically, this is function that I write to
>>> R and
>>> below its response :
>>> for R^2 :
>>>
>>>> output$r.squared
>>>>
>>> NULL
>>> for heterokedasticity tests :
>>>
>>>> bptest(reg1)
>>>>
>>> Error in terms.default(formula) : no terms component
>>> and for autocorrelation test, when I try :
>>> durbin.watson(reg1$residuals, max.lag=10)
>>> [1] 1.509 2.520 2.247 2.001 1.743 1.092 1.392 1.439 1.468 1.035
>>> this give me only the durbin watson value and not the probabilities
>>> (p-value)
>>> When performing these tests on lm object I have no problem. So my
>>> question
>>> is how to extract R^2 from a tsls regression (object) and how to
>>> perform
>>> autocorrelation and heterokedasticity tests on tsls regression. I
>>> looked at
>>> the sem package but I found no answer to my questions. So please is
>>> there
>>> any person who can help me.
>>>
>>> Think you in advance
>>>
>>> [[alternative HTML version deleted]]
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> _______________________________________________
>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only.
>>> -- If you want to post, subscribe first.
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>>
More information about the R-SIG-Finance
mailing list