[R] Superimposing y-variables in Lattice formulas
Deepayan Sarkar
deepayan.sarkar at gmail.com
Mon Nov 17 04:10:34 CET 2008
On 11/16/08, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> Deepayan,
>
> Thanks again for your explanations. I must admit I am still
> struggling with some of these concepts (though I have in fact read
> more than just help pages!), and I would be delighted to find a
> holistic introduction to the concepts of formulae and of the lattice
> system -- in fact I have ordered your book, which I imagine does
> present a holistic introduction, and look forward to studying it.
> Still, as both R and Lattice are free software, I'd have hoped to find
> good documentation on-line.
I'm not sure I would have expected that; documentation of Free
Software is typically terse, and not "good" by the definition you are
probably using. You should not assume that altruism is the only (or
even a typical) motive of Free Software developers.
Having said that, try looking at
http://www.bioconductor.org/workshops/2008/BioC2008/labs/lattice/
for a holistic intro to lattice (in addition to the resources
mentioned in help(Lattice)).
> On Sat, Nov 15, 2008 at 2:54 PM, Deepayan Sarkar
>
> <deepayan.sarkar at gmail.com> wrote:
>
> > a help page is intended to describe the capabilities of the function/object it is documenting, not the capabilities that are missing, even though those who have preconceived ideas of how certain things should behave often think that it is somehow the responsibility of the help page to anticipate all such misunderstandings.
>
>
> According to the documentation, formulae are built using a variety of
> operators, including ~, |, +, *, :, I, etc. I'd have thought that a
> function that takes a formula object as an argument would handle all
> those operators in some reasonably consistent way,
You would have thought wrong. If you explain what piece of the
documentation gave you that idea, I'm sure someone will clarify it.
> just as in a CAS
> like Mathematica, one expects differentiation, integration, and series
> expansion to work consistently on all formulae constructed with
> standard operators such as +, *, ^, Sin, etc. Instead, what I find is
> that the behavior is simply undocumented on the help page in many
> cases. For example:
>
> xyplot(conc*2~time*2,Indometh)
>
> seems to (perfectly sensibly) plot 2*conc vs. 2*time -- though that
> case is not mentioned in the help page -- whereas
>
> xyplot(conc+2~time+2,Indometh)
>
> does something completely different and which as far as I can tell I
> can't predict from the Help page.
The relevant help page says:
A special case is when the left and/or right sides of the
formula (before the conditioning variables) contain a '+'
sign, e.g., 'y1+y2 ~ x | a*b'. This formula would be taken to
mean that the user wants to plot both 'y1~x | a*b' and 'y2~x
| a*b', but with the 'y1~x' and 'y2~x' superposed in each
panel (this is slightly more complicated in 'barchart'). The
two parts would be distinguished by different graphical
parameters. This is essentially what the 'groups' argument
would produce, if 'y1' and 'y2' were concatenated to produce
a longer vector, with the 'groups' argument being an
indicator of which rows come from which variable. In fact,
this is exactly what is done internally using the 'reshape'
function. This feature cannot be used in conjunction with the
'groups' argument.
To interpret 'y1 + y2' as a sum, one can either set
'allow.multiple=FALSE' or use 'I(y1+y2)'.
I'm not sure what is unclear.
> Similarly, I have no clue what is going on with:
>
> xyplot(5+conc~time,Indometh) -- plots x=0 y=5
> in red in addition to the regular plot
> xyplot(conc~time:Subject,Indometh) -- values stacked at x ~ .25
> xyplot(conc~log(time):Subject,Indometh) -- values stacked at x
> ~ -1.7, -.4, and .6
> xyplot(conc~time+5:Subject,Indometh) -- ???
> z<-1:5; xyplot( z ~ z + 1 ) -- red at
> 1/1,4/4,4/5,5/5; blue at 1/2,2/2,2/3,3/3,3/4
>
> (some of) which give cryptic warnings (not errors) and produce some
> sort of display.
I'm not sure what to say here, other than to repeat my earlier point
that the purpose of documentation is to say what works, and not to
anticipate all possible misuses.
-Deepayan
> The wording of the help page isn't very clear, either. It says that
> the formula is "generally" (meaning "usually"? or meaning "in
> general"?) of a certain form and then goes on to describe various
> other cases, with no conditioning variables, with algebraic
> expressions instead of variables, with + instead of * (without saying
> what the difference, if any, is), with plus signs on the left, with
> the I operator, etc.
>
> Thanks for your work on Lattice -- I look forward to mastering its
> powerful features....
>
>
> -s
>
More information about the R-help
mailing list