[R] problem plotting curve through data
Christian Reilly
heron at stanford.edu
Wed Nov 26 00:09:37 CET 2003
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
------------
If anyone can give me any tips on this "Error in terms.formula" message,
or how functions are plotted over data, I'd be much obliged. I've only
been at about a R, some no explanations or suggestions are too simplistic.
Even an example of a plot of a logistic growth function of the form
R = S^n / ( S^n + S50^n)
where R is response, S is stimulus intensity and S50 is the intensity that
produces a 50% response
would be tremendously helpful
Cheers,
and many thanks,
Christian
-----------------------------------------------------------------------
Christian Reilly http://www.stanford.edu/~heron
Hopkins Marine Station
Pacific Grove, CA 93950
heron at stanford.edu
More information about the R-help
mailing list