[R] Regression Testing
Mojo
mojo at sispyrc.com
Thu Jan 20 21:44:06 CET 2011
On 1/20/2011 3:37 PM, David Winsemius wrote:
>
> On Jan 20, 2011, at 2:08 PM, Mojo wrote:
>
>> I'm new to R and some what new to the world of stats. I got
>> frustrated with excel and found R. Enough of that already.
>>
>> I'm trying to test and correct for Heteroskedasticity
>>
>> I have data in a csv file that I load and store in a dataframe.
>>
>> > ds <- read.csv("book2.csv")
>> > df <- data.frame(ds)
>>
>> I then preform a OLS regression:
>>
>> > lmfit <- lm(df$y~df$x)
>>
>> To test for Heteroskedasticity, I run the BPtest:
>>
>> > bptest(lmfit)
>>
>> studentized Breusch-Pagan test
>>
>> data: lmfit
>> BP = 11.6768, df = 1, p-value = 0.0006329
>>
>> From the above, if I'm interpreting this correctly, there is
>> Heteroskedasticity present. To correct for this, I need to calculate
>> robust error terms. From my reading on this list, it seems like I
>> need to vcovHC.
>>
>> > vcovHC(lmfit)
>> (Intercept) df$x
>> (Intercept) 1.057460e-03 -4.961118e-05
>> df$x -4.961118e-05 2.378465e-06
>>
>> I'm having a little bit of a hard time following the help pages. So
>> is the first column the intercepts and the second column new standard
>> errors?
>
> No, It's a variance-covariance matrix, so all of the elements are
> variance estimates. To get what you are expecting ... the SE's of the
> coefficients (which are the diagonal elements of a var-covar matrix,
> .... you would wrap sqrt(diag(.)) around that object.
>
Perfect. Thank you very much!
Mojo
More information about the R-help
mailing list