Plot Numeric (e.g. Residuals) vs 2 Factors Using Boxplots
p.res.2fact.RdPlots a numeric “residual like” variable against two factor covariates, using boxplots.
Arguments
- x,y
two factors or numeric vectors giving the levels of factors.
- z
numeric vector of same length as
xandy, typically residuals.- restricted
positive value which truncates the size. The corresponding symbols are marked by stars.
- notch
logical indicating if the boxplots should be notched, see
boxplot(*,notch).- xlab,ylab
axis labels, see
plot.default, per default the actual argument expressions.- main
main title passed to
plot, defaulting to the deparsedzargument.
Details
if values are restricted, this make use of the auxiliar
function u.boxplot.x.
Author
Lorenz Gygax logyg@wild.unizh.ch and Martin Maechler, Jan.95;
starting from p.res.2x().
Examples
I <- 8; J <- 3; K <- 20
xx <- factor(rep(rep(1:I, rep(K,I)),J))
yy <- factor(rep(1:J, rep(I*K,J)))
zz <- rt(I*J*K, df=5) #-- Student t with 5 d.f.
p.res.2fact(xx,yy,zz, restr= 4, main= "i.i.d. t <- 5 random |.| <= 4")
#> ..Cut z= 10.75 -6.52 at xx = 5 7 , yy = 3
#> ..Cut z= 5.31 4.01 at xx = 1 5 , yy = 2
#> ..Cut z= -4.39 -4.48 at xx = 2 8 , yy = 1
#> 6 restricted observation(s)
mtext("p.res.2fact(xx,yy,zz, restr= 4, ..)",
line=1, adj=1, outer=TRUE, cex=1)
## Real data
data(warpbreaks)
(fm1 <- lm(breaks ~ wool*tension, data = warpbreaks))
#>
#> Call:
#> lm(formula = breaks ~ wool * tension, data = warpbreaks)
#>
#> Coefficients:
#> (Intercept) woolB tensionM tensionH woolB:tensionM
#> 44.6 -16.3 -20.6 -20.0 21.1
#> woolB:tensionH
#> 10.6
#>
## call via formula method of p.res.2x():
p.res.2x(~ ., fm1) # is shorter than, but equivalent to
## p.res.2x(~ wool + tension, fm1) ## or the direct
## with(warpbreaks, p.res.2fact(wool, tension, residuals(fm1)))
##
## whereas this is "transposed":
p.res.2x(~ tension+wool, fm1)