I have a dataset of successes, probabilities, and sample sizes that I am running binomial tests on.
Here is a sample of the data (note that the actual dataset has me run >100 binomial tests):
km n_1 prey_pred p0_prey_pred
<fct> <dbl> <int> <dbl>
80 93 12 0.119
81 1541 103 0.0793
83 316 5 0.0364
84 721 44 0.0796
89 866 58 0.131
I normally run this (example for first row):
n=93
p0=0.119
successes=12
binom.test(obs.successes, n, p0, "two.sided")
> Exact binomial test
data: 12 and 93
number of successes = 12, number of trials = 93, p-value = 0.74822
alternative hypothesis: true probability of success is not equal to 0.119
95 percent confidence interval:
0.068487201 0.214548325
sample estimates:
probability of success
0.12903226
Is there a way to systematically have it run multiple binomial tests on each row of data, and then storing all the output (p-value, confidence intervals, probability of success) as separate columns?
I've tried the solution proposed here, but I am clearly m
Using
apply.Edit
If you have multiple column sets, in wide format (and for some reason want to stay there)
you may do:
One could code this more nested, but I recommend to keep things easy so later others understand better what's going on, and probably including oneself.
Data: