# NOT RUN {
# create year factor variable
Mirex$fyear <- factor(Mirex$year)
Mirex$cyear <- as.character(Mirex$year)
Mirex$cspecies <- as.character(Mirex$species)
## One-way ANOVA
aov1 <- lm(mirex~fyear,data=Mirex)
residPlot(aov1)
## Two-Way ANOVA
aov2 <- lm(mirex~species*fyear,data=Mirex)
residPlot(aov2)
## Simple linear regression
slr1 <- lm(mirex~weight,data=Mirex)
residPlot(slr1)
residPlot(slr1,loess=TRUE,main="MODEL")
## Indicator variable regression with only one factor
ivr1 <- lm(mirex~weight*fyear,data=Mirex)
residPlot(ivr1)
residPlot(ivr1,inclHist=FALSE,pch=19)
residPlot(ivr1,inclHist=FALSE,pch=19,col="black")
residPlot(ivr1,legend=FALSE,loess=TRUE)
## Indicator variable regression (assuming same slope)
ivr2 <- lm(mirex~weight+fyear,data=Mirex)
residPlot(ivr2,legend=FALSE,loess=TRUE)
## Indicator variable regression with two factors
## Reduce number of years for visual simplicity
Mirex2 <- filterD(Mirex,fyear %in% c(1977,1992))
ivr3 <- lm(mirex~weight*fyear*species,data=Mirex2)
residPlot(ivr3)
residPlot(ivr3,loess=TRUE,legend=FALSE)
## IVR w/ factors in different order (notice use of colors and symbols)
ivr4 <- lm(mirex~weight*species*fyear,data=Mirex2)
residPlot(ivr4)
## Nonlinear regression ... from first example in nls()
DNase1 <- subset(DNase,Run==1)
fm1DNase1 <- nls(density~SSlogis(log(conc),Asym,xmid,scal),DNase1)
residPlot(fm1DNase1)
residPlot(fm1DNase1,resid.type="standardized")
## Examples showing outlier detection
x <- c(runif(100))
y <- c(7,runif(98),-5)
lma <- lm(y~x)
residPlot(lma)
residPlot(lma,resid.type="studentized")
# }
Run the code above in your browser using DataLab