[R] mosaicplot(formula, data)--- bugged?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Jan 30 17:57:59 CET 2002
On Wed, 30 Jan 2002, Michael Friendly wrote:
> I have been tinkering with mosaicplot() and friends as a way
> of learning R. As part of this, I've written a pair.table()
> method for mosaic matrices, and would like to extend mosaicplot
> to work with loglin and logln (MASS) objects. I'm using
> R 1.4.0 on Win 98.
>
> I've been trying to figure out the formula interface, and think
> there's a bug, but not sure how to find it, yet alone fix it.
As documented it should not have interaction terms:
For the formula method, if `data' is an object inheriting from
classes `"table"' or `"ftable"', or an array with more than 2
dimensions, it is taken as a contingency table, and hence all
entries should be nonnegative. In this case, the left-hand side
of `formula' should be empty, and the variables on the right-hand
side should be taken from the names of the dimnames attribute of
the contingency table. A marginal table of these variables is
computed, and a mosaic of this table is produced.
I am really not sure what you expected Hair * Eye + Sex to give you.
As a log-linear model the meaning is clear, but mosaicplot is working with
data and not a model *unless* you ask for an extended mosaicplot
by specifying `shade'. The way two modes are described on one help page
may be misleading. For data the model is really Hair * Eye * Sex
and arguments `margin' and `type' are not relevant (AFAIK).
What one could do is to extend the notation so that instead of
mosaicplot(HairEyeColor, shade = TRUE, margin = list(c(1,2), 3))
the model could be specified by a formula (rather than by margins).
> It seems to only work with independence models:
>
> > data(HairEyeColor)
> > mosaicplot(~ Hair + Eye + Sex, data=HairEyeColor)
> > mosaicplot(~ Hair * Eye + Sex, data=HairEyeColor)
> Error in aperm(a, perm, resize) : `perm' is of wrong length
>
> here's a traceback:
>
> > debug(mosaicplot)
> > mosaicplot(~Hair + Eye + Sex + Hair:Eye, data=HairEyeColor)
> debugging in: mosaicplot(~Hair + Eye + Sex + Hair:Eye, data =
> HairEyeColor)
> debug: UseMethod("mosaicplot")
> Browse[1]>
> Error in aperm(a, perm, resize) : `perm' is of wrong length
> > traceback()
> 5: aperm(X, c(s.call, s.ans))
> 4: apply(x, margin, sum)
> 3: margin.table(data, match(varnames, names(dimnames(data))))
> 2: mosaicplot.formula(~Hair + Eye + Sex + Hair:Eye, data = HairEyeColor)
> 1: mosaicplot(~Hair + Eye + Sex + Hair:Eye, data = HairEyeColor)
> >
>
> but this works correctly:
>
> > library(MASS)
> > lm1 <- loglm(~Hair*Eye + Sex, HairEyeColor)
> > lm1
> Call:
> loglm(formula = ~Hair * Eye + Sex, data = HairEyeColor)
>
> Statistics:
> X^2 df P(> X^2)
> Likelihood Ratio 29.34982 15 0.01449443
> Pearson 28.99286 15 0.01611871
> >
>
> Can anyone help?
>
> --
> Michael Friendly friendly at yorku.ca
> York University http://www.math.yorku.ca/SCS/friendly.html
> Psychology Department
> 4700 Keele Street Tel: (416) 736-5115 x66249
> Toronto, Ontario, M3J 1P3 Fax: (416) 736-5814
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list