[R] plotting the result of a nonlinear regression

lauramorgana at bluewin.ch lauramorgana at bluewin.ch
Thu Feb 12 12:43:25 CET 2009


Thank you for the suggestion of using predict!
If someone is interested here is the loop I used:

seq(0,max(subset(dati, Fiume=="Laveggio")$Portata), length=100)->seqQ

for(i in 1:35)
{
  jpeg(paste("result",i,".jpg"))
  plot(subset(dati,Fiume=="Laveggio")$PTG.P~subset(dati,Fiume=="Laveggio")$Portata, 
       main=print(formList[[i]]), sub=print(summary(resultList[[i]])$sigma))
  lines(seqQ, predict(resultList[[i]], list(Portata = seqQ)))
  dev.off()
  }

----Messaggio originale----
Da: ssefick at gmail.com
Data: 10.02.2009 18.15
A: <lauramorgana at bluewin.ch>
Copia: <r-help at r-project.org>
Oggetto: Re: [R] plotting the result of a nonlinear regression

?predict

On Tue, Feb 10, 2009 at 11:06 AM, lauramorgana at bluewin.ch
<lauramorgana at bluewin.ch> wrote:
> Hello,
> to plot the result of a singular non linear regression (using nls) I usually use the function plotfit, for 
example:
>
> r.PTG.V<-nls(PTG.P~ fz1(Portata, a,b), data=dati, start=list(a=10, b=10), nls.control(maxiter=200), 
algorithm='port',
> trace=TRUE, na.action=na.omit, lower=list(a=0, b=10), upper=list(a=100, b=100))
> plotfit(r.PTG.V)
>
> I tried to use the function plotfit on the result of the following for loop but I got an error message:
> for (i in 1:length(formList))
> {
>    resultList[[i]] <- nls(formList[[i]], data=subset(dati, Fiume=="Laveggio"), start=startList7[[i]],
>    nls.control(maxiter=1000, warnOnly=TRUE), algorithm='port', na.action=na.omit,lower=lowerList7[[i]],
>    upper=upperList7[[i]])
> }
> plotfit(resultList[[1]]
>
> "Error in diff(as.numeric(y[ord])) :
>  (list) object cannot be coerced to type 'double'"
>
> Could somebody tell me what this error means? how can I fix this problem?
> Any suggestion appreciated!!
> Thanks,
> Laura
>
> ______________________________________________
> R-help at 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.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

								-K. Mullis




More information about the R-help mailing list