[R] Solving an equation in R (and using a loop)
dwinsemius at comcast.net
Fri Oct 16 00:31:22 CEST 2009
On Oct 15, 2009, at 5:18 PM, leohearn wrote:
> So, I have a dataset and I'm trying to solve for a parameter in an
> using the dataset. Before applying more sophisticated statistical
> techniques, I want to tell R to solve it out for each observation. I
> know I
> have to use a loop for it (and I have done that before, but am a bit
> but before I do that, I'm trying to get R to solve it for just one
> observation, to make sure that I have that part right before
> applying to the
> rest. However, when I do it, I get 0 for an answer, which is a valid
> but a trivial one. What am I doing wrong? (tips for the loop would
> also be
> appreciated, but this is my main concern right now.)
> Here's my code:
What is this function supposed to represent?
> r is the unknown. I've plugged in a couple numbers from my data for
> b, x1,
> and x2 such as:
> and gotten 0 both times.
Apparently you do understand that at zero that function would evaluate
to 1-1- (1/2)*(1-1+1-1) for any value of the parameters.
If you plot that function over the domain specified, you should see
why there are no other solutions. Even with the first set of
parameters f(1) is
 2.269996e-05 # which is close but not equal to zero
Sometimes the trivial answer is the _only_ answer.
> Thanks in advance for your help.
David Winsemius, MD
West Hartford, CT
More information about the R-help