# NOT RUN {
# create year as a factor variable
Mirex$fyear <- factor(Mirex$year)
# reduce number of years for visual simplicity for iVRs
Mirex2 <- filterD(Mirex,fyear %in% c(1977,1992))
## One-way ANOVA
aov1 <- lm(mirex~fyear,data=Mirex)
fitPlot(aov1)
## Two-way ANOVA
aov2 <- lm(mirex~fyear*species,data=Mirex)
# interaction plots and a color change
fitPlot(aov2,legend="bottomleft")
fitPlot(aov2,change.order=TRUE)
# main effects plots
fitPlot(aov2,which="species")
fitPlot(aov2,which="fyear")
## Simple linear regression (showing color change and confidence and prediction bands)
slr1 <- lm(mirex~weight,data=Mirex)
fitPlot(slr1)
fitPlot(slr1,interval="both")
## Indicator variable regression with one factor (also showing confidence bands)
ivr1 <- lm(mirex~weight*fyear,data=Mirex2)
fitPlot(ivr1,legend="topleft")
fitPlot(ivr1,legend="topleft",interval="confidence")
## Indicator variable regression with one factor (assuming parallel lines)
ivr2 <- lm(mirex~weight+species,data=Mirex2)
fitPlot(ivr2,legend="topleft")
## Indicator variable regression with two factors
ivr3 <- lm(mirex~weight*fyear*species,data=Mirex2)
fitPlot(ivr3,ylim=c(0,0.8),legend="topleft")
## Polynomial regression
poly1 <- lm(mirex~weight+I(weight^2),data=Mirex)
fitPlot(poly1,interval="both")
## Non-linear model example
lr.sv <- list(B1=6,B2=7.2,B3=-1.5)
nl1 <- nls(cells~B1/(1+exp(B2+B3*days)),start=lr.sv,data=Ecoli)
fitPlot(nl1,Ecoli,cex.main=0.7,lwd=2)
## Logistic regression example
## NASA space shuttle o-ring failures -- from graphics package
d <- data.frame(fail=factor(c(2,2,2,2,1,1,1,1,1,1,2,1,2,1,1,1,1,2,1,1,1,1,1),
levels = 1:2, labels = c("no","yes")),
temperature <- c(53,57,58,63,66,67,67,67,68,69,70,70,70,70,
72,73,75,75,76,76,78,79,81))
glm1 <- glm(fail~temperature,data=d,family="binomial")
fitPlot(glm1)
fitPlot(glm1,yaxis1.ticks=c(0,1),yaxis1.lbls=c(0,1))
# }
Run the code above in your browser using DataLab