On Thu, 18 Sep 2008, Deepayan Sarkar wrote:

On 9/18/08, David Scott <[EMAIL PROTECTED]> 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


Thanks very much Deepayan, that is exactly what I was after. Very nice.

David
_________________________________________________________________
David Scott     Department of Statistics, Tamaki Campus
                The University of Auckland, PB 92019
                Auckland 1142,    NEW ZEALAND
Phone: +64 9 373 7599 ext 86830         Fax: +64 9 373 7000
Email:  [EMAIL PROTECTED]

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to