怀特检讨与R
当前位置:以往代写 > 其他教程 >怀特检讨与R
2019-06-14

怀特检讨与R

怀特检讨与R


##要领1:
## packages and data
library(“AER”)
data(“CigarettesB”)
## regression
cig_lm2 < – lm(packs ~ price + income, data = CigarettesB)
## auxiliary regression
aux <- residuals(cig_lm2)^2
aux_lm <- lm(aux ~ income * price + I(income^2) + I(price^2),
data = CigarettesB)
## test statistic
nrow(CigarettesB) * summary(aux_lm)$r.squared
pchisq( nrow(CigarettesB) * summary(aux_lm)$r.squared,df=5,lower.tail=F)
[1] 0.007896581
#要领2
## White test
library(lmtest)
bptest(cig_lm2, ~ income * price + I(income^2) + I(price^2),
data = CigarettesB)
studentized Breusch-Pagan test

data: cig_lm2
BP = 15.6564, df = 5, p-value = 0.007897

    关键字:

在线提交作业