Question

# R-Studio Write a generic R function of white test. It takes a fit of linear model...

R-Studio

Write a generic R function of white test. It takes a fit of linear model and outputs the value of white statistics, degree of freedom, and p-value for the hypothesis testing of constant-variance assumption. It should be similar to bptest as in lmtest package.

#### Homework Answers

Answer #1
```> mdl = lm(final ~ midterm, data = stat500)
> bptest(mdl)

studentized Breusch-Pagan test

data:  mdl
BP = 0.86813, df = 1, p-value = 0.3515

> bptest(mdl, studentize = FALSE)

Breusch-Pagan test

data:  mdl
BP = 0.67017, df = 1, p-value = 0.413

> ncvTest(mdl)
Non-constant Variance Score Test
Variance formula: ~ fitted.values
Chisquare = 0.6701721    Df = 1     p = 0.4129916
>
> n = nrow(stat500)
> e = residuals(mdl)
> bpmdl = lm(e^2 ~ midterm, data = stat500)
> lambda = (n - 1) / n * var(e^2) / (2 * ((n - 1) / n * var(e))^2)
> Studentized_bp = n * summary(bpmdl)\$r.squared
> Original_bp = Studentized_bp * lambda
>
> Studentized_bp
[1] 0.8681335
> Original_bp
[1] 0.6701721```

ANSWERED

PLEASE RATE ME POSITIVE

THANKS

Know the answer?
Your Answer:

#### Post as a guest

Your Name:

What's your source?

#### Earn Coins

Coins can be redeemed for fabulous gifts.

##### Not the answer you're looking for?
Ask your own homework help question