An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130820/ca056850/attachment.pl>
how to code y~x/(x+a) in lm() function
7 messages · David L Carlson, Rolf Turner, Ye Lin +2 more
(1) It is not acceptable to use "wanna" in written English. You should say
"I want to fit a model ....".
(2) The model you have fitted is *not* equivalent to the model you first
state.
If you write "y ~ x/(a+x)" you are tacitly implying that
y = x/(a+x) + E
where the "errors" E are i.i.d. with mean 0.
If this is the case then it will *not* be the case that
1/y = 1 + a/x + E
with the E values being i.i.d. with mean 0.
If the model "y ~ x/(a+x)" is really what you want to fit, then you should
be using non-linear methods, e.g. by applying the function nls().
cheers,
Rolf Turner
On 21/08/13 09:39, Ye Lin wrote:
Hey All, I wanna to fit a model y~x/(a+x) to my data, here is the code I use now: lm((1/y-1)~I(1/x)+0, data=b) and it will return the coefficient which is value of a however, if I use the code above, I am not able to draw a curve the presents this equation. How can I do this?
?curve set.seed(42) x <- 1:15 y <- x/(1+x)+rnorm(15, 0, .02) plot(y~x) lm.out <- lm((1/y-1)~I(1/x)+0) curve(x/(coef(lm.out)+x), 1, 15, add=TRUE) ------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ye Lin Sent: Tuesday, August 20, 2013 4:40 PM To: R help Subject: [R] how to code y~x/(x+a) in lm() function Hey All, I wanna to fit a model y~x/(a+x) to my data, here is the code I use now: lm((1/y-1)~I(1/x)+0, data=b) and it will return the coefficient which is value of a however, if I use the code above, I am not able to draw a curve the presents this equation. How can I do this? Thanks for your help! ______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130821/45bab6f8/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130820/00f66c3f/attachment.pl>
Rolf:
Thanks for this.
It nicely illustrates what to me is a fundamental problem: For many
scientists, it is not math ("stats") that is the stumbling block, but
rather the failure to understand how variability ("noise") affects the
experimental/observational process. One does tend to get more
philosophical in old age, I suppose...
My personal experience is that this problem is widespread, but mine is
a highly biased sample, of course. Nevertheless, it is hard to fault
those who stumble: Nothing in the usual basic science education
process discusses the issue (coherently, anyway); and certainly
standard applied statistics courses that I know of gloss over it. Nor
do I think the concepts are easy to grasp (a measurement is a sample
of size one from a population of measurements that one could get) --
at least I did not find them so.
No reply necessary, whether you agree or disagree. You just afforded
me a nice opportunity to vent.
Best,
Bert
On Tue, Aug 20, 2013 at 3:59 PM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
On 21/08/13 11:23, Ye Lin wrote:
T hanks for your insights Rolf! The model I want to fit is y=x/a+x with no intercept, so I transformed it to 1/y=1+a/x as they are the same.
For crying out loud, they are ***NOT*** the same. The equations y =
x/(a+x) and
1/y = 1 + a/x are indeed algebraically identical, but if an "error" or
"noise" term is added
to each then then the nature of the error term is vastly different. It
is the error or
noise term that is of central concern in a statistical context.
cheers,
Rolf
but i will look up nls() and see how to fit the model without
transformation.
On Tue, Aug 20, 2013 at 2:45 PM, Rolf Turner <rolf.turner at xtra.co.nz
<mailto:rolf.turner at xtra.co.nz>> wrote:
(1) It is not acceptable to use "wanna" in written English. You
should say
"I want to fit a model ....".
(2) The model you have fitted is *not* equivalent to the model you
first state.
If you write "y ~ x/(a+x)" you are tacitly implying that
y = x/(a+x) + E
where the "errors" E are i.i.d. with mean 0.
If this is the case then it will *not* be the case that
1/y = 1 + a/x + E
with the E values being i.i.d. with mean 0.
If the model "y ~ x/(a+x)" is really what you want to fit, then
you should
be using non-linear methods, e.g. by applying the function nls().
cheers,
Rolf Turner
On 21/08/13 09:39, Ye Lin wrote:
Hey All,
I wanna to fit a model y~x/(a+x) to my data, here is the code
I use now:
lm((1/y-1)~I(1/x)+0, data=b)
and it will return the coefficient which is value of a
however, if I use the code above, I am not able to draw a
curve the
presents this equation. How can I do this?
[[alternative HTML version deleted]]
______________________________________________ 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Rolf Turner <rolf.turner <at> xtra.co.nz> writes:
On 21/08/13 11:23, Ye Lin wrote:
T hanks for your insights Rolf! The model I want to fit is y=x/a+x with no intercept, so I transformed it to 1/y=1+a/x as they are the same.
For crying out loud, they are ***NOT*** the same. The equations y =
x/(a+x) and
1/y = 1 + a/x are indeed algebraically identical, but if an "error" or
"noise" term is added
to each then then the nature of the error term is vastly different. It
is the error or
noise term that is of central concern in a statistical context.
cheers,
Rolf
For what it's worth this model can also be fitted (without messing up the error structure) via glm(1/y~x,family=gaussian(link="inverse")) Although you may not get the parameters in exactly the form you want.