[R] Plot observed vs. fitted values (weighted nls)

Thomas W Blackwell tblackw at umich.edu
Thu May 22 15:00:05 CEST 2003



On Wed, 21 May 2003 DivineSAAM at aol.com wrote:

> Dear WizaRds,
>
> Given the experimental data,
>
> csdata<-data.frame(
> time=c(0,1,3,9,20),
> conc=c(638.697,395.69,199.00,141.58,112.16)
> )
>
> weighted nls is applied,
>
> wt.MM<- function(resp, time,A1,a1,A2,a2)
> {
>     pred <- A1*exp(-a1*time)+A2*exp(-a2*time)
>     (resp - pred) / sqrt(pred)
> }
> #
> cs.wt <- nls( ~ wt.MM(conc, time,A1,a1,A2,a2), data=csdata,
>               start=list(A1=700,a1=1,A2=100,a2=0.1),
>              trace = TRUE)
>
> x<-csdata$time
> y<-csdata$conc
>
> Now, I want a plot of the observed vs. fitted values. I used
> # 1. 'seq' to generate series of values for x-axis
> # 2. 'predict' to calculate the fitted values
> # 3. 'lines' to overlay the smooth curve of the fitted values
>
> smoothx<-seq(0,20,0.1)
>
> smoothy<-predict(cs.wt,list(x=smoothx))

predict()  is looking for a variable called "time".
Try  predict(cs.wt, data.frame(time=seq(0,20,0.1)))

>
> *Unfortunately, this did not work.
>
> My goal was to use
>
> plot(x,y)
> lines(smoothx,smoothy)
>
> Oscar A. Linares
> The Geriatrics Center
> University of Michigan, Ann Arbor
>

-  tom blackwell  -  u michigan medical school  -  ann arbor  -




More information about the R-help mailing list