Hi, I am trying to test for heteroskedascity in an OLS model, but I am not able to run the white.test() if the model has dummy variables built from factors. Any suggestions?
Please find a reproducible code below: myswiss <- swiss myswiss$fert <- ifelse( myswiss$Fertility>70, "High","Low") myswiss$fert <- factor(myswiss$fert) str(myswiss) mod1 <- lm(Infant.Mortality ~ fert, data=myswiss) library(bstats) bptest(mod1) white.test(mod1) myswiss$fertlow <- ifelse( myswiss$Fertility>70, 0,1) mod2 <- lm(Infant.Mortality ~ fertlow, data=myswiss) library(bstats) bptest(mod2) white.test(mod2) Results: > bptest(mod2) studentized Breusch-Pagan test for homoscedasticity data: mod2 BP = 2e-04, df = 1, p-value = 0.989 > white.test(mod2) White test for constant variance data: White = 2e-04, df = 1, p-value = 0.989 > bptest(mod1) studentized Breusch-Pagan test for homoscedasticity data: mod1 BP = 2e-04, df = 1, p-value = 0.989 > white.test(mod1) Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels In addition: Warning message: In Ops.factor(fert, fert) : * not meaningful for factors > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.