[R] Small p from binomial probability function.
Stefan Evert
stefanML at collocations.de
Thu Oct 10 10:37:31 CEST 2013
Sounds like you want a 95% binomial confidence interval:
binom.test(N, P)
will compute this for you, and you can get the bounds directly with
binom.test(N, P)$conf.int
Actually, binom.test computes a two-sided confidence interval, which corresponds roughly to 2.5 and 97.5 percentages in your approach. It doesn't give you the 50% point either, but I don't think that's a meaningful quantity with a two-sided test.
Hope this helps,
Stefan
On 9 Oct 2013, at 15:53, Benjamin Ward (ENV) <B.Ward at uea.ac.uk> wrote:
> I got given some code that uses the R function pbionom:
>
> p <- mut * t
> sumprobs <- pbinom( N, B, p ) * 1000
>
> Which gives the output of a probability as a percentage like 5, 50, 95.
>
> What the code currently does is find me the values of t I need, by using the above two code lines in a loop, each iteration it increaces t by one and runs the two lines. When sumprobs equals 5, it records the value t, then again when sumprobs is equal to 50, and again when sumprobs is equal to 95 - giving me three t values. This is not an efficient way of doing this if t is large. Is it possible to rearrange pbinom so it gives me the small p (made of mut*t) as the result of plugging in the sumprobs instead, and is there an R function that already does this?
>
> Since pbinom is the binomial probability equation I suppose the question is - in more mathematical terminology - can I change this code so that instead of calculating the Probability of N successes given the number of trials and the probability of a single success, can I instead calculate the probability of a single success using the probability of N successes and number of trials, and the number of successes? Can R do this for me. So instead I plug in 5, 50, and 95, and then get the small p out?
More information about the R-help
mailing list