[R] a question on plotting nonlinear regression
markseeto at gmail.com
Mon Jul 25 00:25:29 CEST 2011
Mark Seeto wrote:
> garciap wrote:
>> Hi to all the people,
>> I'm having a trouble when trying to plot a quadratic function. I have the
>> 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.
> 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.
Sorry, that should have been
plot(Survival~PI,data=cubs, ylab="Survival", xlab="PI")
View this message in context: http://r.789695.n4.nabble.com/a-question-on-plotting-nonlinear-regression-tp3690828p3691169.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help