Re: [R] Fucntion scope question. General non-linear solution help.

2008-08-17 Thread Prof Brian Ripley
Looks like you want to solve pbinom(k-1, N, p) = 0.5 for p. That is easy: use uniroot. testit <- function(k, N) { fn <- function(p, k, N) pbinom(k-1, N, p) - 0.5 uniroot(fn, c(0,1), k=k, N=N) } testit(6, 10) On Sun, 17 Aug 2008, [EMAIL PROTECTED] wrote: I would like to solve the equa

[R] Fucntion scope question. General non-linear solution help.

2008-08-17 Thread rkevinburton
I would like to solve the equation is is the sum from k = i to N of choose(N,k) * MR ^ k * (1 - MR) ^ (N - k) - 0.50 = 0 I want to solve for MR. This seems like a non-linear equation to me. But I am having a hard time writing the function that implements the above. I could use 'for(...) as a br