Hi to all the people, I'm having a trouble when trying to plot a quadratic function. I have the code: regression<-nls(Survival~beta1+beta2*PI+beta3*PI^2, data=cubs, start=list(beta1 = 1, beta2 = 1, beta3 = 1)) plot(Survival~PI,data=cubs, ylab="Survival", xlab="PI") lines(cubs$PI, fitted(regression)) but the plotted line is not the quadratic one, rather it appears a number of lines whose meaning I do not know. It seems to be an stupid trouble, but I tried a number of alternatives and nothing works. Regards, pablo -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-plotting-nonlinear-regression-tp3690828p3690828.html Sent from the R help mailing list archive at Nabble.com.
garciap wrote:> > Hi to all the people, > > I'm having a trouble when trying to plot a quadratic function. I have the > code: > > regression<-nls(Survival~beta1+beta2*PI+beta3*PI^2, data=cubs, > start=list(beta1 = 1, beta2 = 1, beta3 = 1)) > plot(Survival~PI,data=cubs, ylab="Survival", xlab="PI") > lines(cubs$PI, fitted(regression)) > > but the plotted line is not the quadratic one, rather it appears a number > of lines whose meaning I do not know. It seems to be an stupid trouble, > but I tried a number of alternatives and nothing works. > > Regards, > > pablo >The problem could be that cubs$PI is not sorted. You could try plot(Survival~PI,data=cubs, ylab="Survival", xlab="PI") lines(sort(PI), fitted(regression)[order(cubs$PI)]) Also, you could use linear regression with lm instead of using nls. Regards, Mark -- View this message in context: http://r.789695.n4.nabble.com/a-question-on-plotting-nonlinear-regression-tp3690828p3691143.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- Determining Starting Values for Model Parameters in Nonlinear Regression
- Determining Starting Values for Model Parameters in Nonlinear Regression
- Question on CAR appendix on NLS
- Determining Starting Values for Model Parameters in Nonlinear Regression
- parfm unable to fit models when hazard rate is small