[R] problem plotting curve through data
Douglas Bates
bates at stat.wisc.edu
Wed Nov 26 00:39:02 CET 2003
Christian Reilly <heron at stanford.edu> writes:
> I'm having trouble plotting a curve (basically a dose-response
> function) through a set of data.
>
> I have created a dataframe (df) of Stimulus Intensities (xstim) and
> Normalized Responses (yresp), and I've used nls() to calculate a nonlinear
> regression, like so:
>
>
> --------------------
> > f <- yresp ~ xstim^n / (xstim^n + B^n)
> > starts <- list(n=.6, B=11)
> > myfit <- nls(formula=f, data=df, start = starts)
> >myfit
>
> Nonlinear regression model
> model: yresp ~ xstim^n/(xstim^n + B^n)
> data: df
> n B
> 0.8476233 5.7943791
> residual sum-of-squares: 0.03913122
> >
> -----------
>
> Which seems great, but I'd like to be able to plot this curve through my
> data to see how the fit looks.
>
> when I try:
>
> ------------
> > plot(f,data=df)
> Error in terms.formula(formula, data = data) :
> invalid power in formula
> ----------
>
> or
>
> ----------
> > n <- 0.87
> > B <- 5.7
> > plot(f,data=df)
> Error in terms.formula(formula, data = data) :
> invalid power in formula
> ------------
Use predict.nls to get the fitted response curve. See
?predict.nls
and especially the example, which you can run with
example(predict.nls)
More information about the R-help
mailing list