Assume we have two coins replicates, which are produced in the same pipeline. To test whether the coins replicates are both biased in one direction (e.g. the probability of head > 0.5), we did flip experiments on the two replicates separately. My question is how got the p-value based on the observations. The following R code is the two approaches I've tried. But I'm not confident they are right.
exp1 = 9 #total number of flips for coin 1. head1 = 7 #number of heads exp2 = 8 head2 = 6
First approach: sum the two experiments together. But it ignores the variance of two coins.
binom.test(head1 + head2, exp1 + exp2) #p-value = 0.04904
Second approach: try to calculate the joint probability of two experiments.
#Generate the probability distribution of each experiment dy = dbinom(x = 0:exp1, exp1,prob = 0.5) dy2 = dbinom(x = 0:exp2, exp2, prob = 0.5) observed_prob =dy[head1 + 1] * dy2_pvalue[head2 + 1] #Calculate the joint probability of all the events given the number of trials joint_density = as.matrix(data.frame(dy)) %*% as.matrix(t(data.frame(dy2)) ) #p-value = probability sum of the events with lower probability than the observed sum(joint_density[joint_density < observed_prob ]) #0.23
I'm surprised that the p-value of second approach is so different from approach 1. Am I wrong?
Edit after post
The goal is to find the pipeline which produces biased coins. So I think my hypothesis is:
H0: p1=p2=0.5 (p1 is the probability of head in coin 1)
H1.1: p1<0.5,p2<0.5 or p1>0.5,p2>0.5
Because two replicates are supposed to be consistent, so I prefer H1 to be:
H1.2: p1=p2<0.5 or p1=p2>0.5.
What should I do in case of H1.2 considering the variance of two replicates?
Note The number of flips of each coin can be very different(e.g. 30 flips for coin 1 and 3 flips for coin 2). So approach 1 would be heavily dominated by coin 1. This is why I want to try approach 2.