[R] Help with predict.lm

Mike White mikewhite.diu at tiscali.co.uk
Tue Apr 19 16:18:26 CEST 2005


Andy
Thanks, the link was very helpful.  I havn't checked the code for the calib
function but it appears to work with my data.
[NB the return function generates a warning message with later verions of R
and needs to be amended to return a list]

In the last line of my code, calibration.lm should have been lm.calibration,
but it still does not work with predict.lm
I presume the solution of reversing the variables as in the linear model to
force predict.lm to work is an invalid statistical method as the regression
line will be slightly different, i.e.

    predict(lm(conc ~ abs), new.abs) # gives slightly different results than
the calib function

Thanks to all who replied,
Mike White


----- Original Message -----
From: "Liaw, Andy" <andy_liaw at merck.com>
To: "'Mike White'" <mikewhite.diu at tiscali.co.uk>; <R-help at stat.math.ethz.ch>
Sent: Tuesday, April 19, 2005 1:53 PM
Subject: RE: [R] Help with predict.lm


> Will this help?
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/1202.html
>
> [Found by RSiteSearch("calibration") in R-2.1.0.]
>
> Andy
>
> > From: Mike White
> >
> > Hi
> > I have measured the UV absorbance (abs) of 10 solutions of a
> > substance at
> > known concentrations (conc) and have used a linear model to plot a
> > calibration graph with confidence limits.  I now want to predict the
> > concentration of solutions with UV absorbance results given
> > in the  new.abs
> > data.frame, however predict.lm only appears to work for new
> > "conc" variables
> > not new "abs" variables.
> >
> > I have search the help files and did find a similar problem
> > in June 2000,
> > but unfortunately no solution was offered.
> > Any help and how to use predict.lm with the new "abs" data to
> > predict "conc"
> > with confidence limits would be appreciated.
> >
> >     conc<-seq(100, 280, 20) #  mg/l
> >     abs<-c(1.064, 1.177, 1.303, 1.414, 1.534, 1.642, 1.744,
> > 1.852, 1.936,
> > 2.046) # absorbance units
> >     lm.calibration<-lm(abs ~ conc)
> >     pred.w.plim <- predict(lm.calibration,  interval="prediction")
> >     pred.w.clim <- predict(lm.calibration,  interval="confidence")
> >     matplot(conc, cbind(pred.w.clim, pred.w.plim[,-1]),
> >              lty=c(1,2,2,3,3), type="l", ylab="abs", xlab=
> > "conc mg/l")
> >     points(conc, abs, pch=21, col="blue")
> >
> >     new.abs<-data.frame(abs=c(1.251, 1.324, 1.452))
> >
> >     predict(calibration.lm, new.abs) # does not work
> >
> >
> > Thanks
> > Mike White
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
> >
>
>
>
> --------------------------------------------------------------------------
----
> Notice:  This e-mail message, together with any attachment...{{dropped}}




More information about the R-help mailing list