DivineSAAM@aol.com
2003-May-22  01:45 UTC
[R] Plot observed vs. fitted values (weighted nls)
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))
*Unfortunately, this did not work.
My goal was to use
plot(x,y)
lines(smoothx,smoothy)
Got--Error in xy.coords(x, y) : x and y lengths differ--
ANY SUGGESTIONS? PLEASE:-)
I noticed that
> smoothy<-predict(cs.wt,list(x=smoothx))
> smoothy
[1] -0.15787479  0.38479197 -0.43312824  0.29216236 -0.09731213
is not a correct prediction of the response based on the results. 
The following was obtained using S-PLUS (which I really do not want to be using)
> predict(cs.wt)
[1] 640.2268 390.9596 205.7743 136.1417 114.0573
Kindest Regards and Many Thanks in Advance
Oscar A. Linares
The Geriatrics Center
University of Michigan, Ann Arbor
Thomas W Blackwell
2003-May-22  13:00 UTC
[R] Plot observed vs. fitted values (weighted nls)
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 -