Message-ID: <eb555e660809180700t27e0354er422d57b5f902c8af@mail.gmail.com>
Date: 2008-09-18T14:00:15Z
From: Deepayan Sarkar
Subject: Plotting curves in lattice panels
In-Reply-To: <alpine.LRH.1.00.0809190011110.27850@stat12.stat.auckland.ac.nz>
On 9/18/08, David Scott <d.scott at auckland.ac.nz> wrote:
>
> I have a data set concerning ferritin levels in blood. There are three
> relevant columns for this question, ferritin (continuous), score (ordered,
> from 0 to 8) and gender. There is a good linear relationship between
> log(ferritin) and score for each gender.
>
> I can create a lattice plot on the log scale showing the data and the
> fitted line:
> xyplot(log(ferritin) ~ total|gender, data = blood,
> panel = function(x, y, ...){
> panel.xyplot(x, y)
> panel.abline(lm(y ~ x), type = 'l', ...)
> }
> )
>
> I would like to be able to plot the data and the fitted line on the
> original scale however. I can't see how to do that.
Something like this should work:
xyplot(ferritin ~ total|gender, data = blood,
panel = function(x, y, ...){
panel.xyplot(x, y)
fm <- lm(log(y) ~ x)
panel.curve(exp(predict(fm, newdata = list(x = x))))
})
-Deepayan