Can someone please tell if this approach to Bootstrapping Longitudinal/Repeated Measures data is statistically valid?
It works if the bias of the coin is assumed to be the same among the different students.
In that case the results from each student are like a repetition of the sampling/experiment and multiple samples from a population give insight into the statistical variation in the sampling distribution.
This variation can be expressed by using bootstrapping (a direct calculation would be easier, it is not clear whether this question is actually about the bootstrapping, and instead more about considering the students as independent samples that are an indication of the sampling distribution).
Sidenote 1: in your code you use expressions like h_given_h
, which is not very clear la guagelanguage. The frequency of HH, which you analyse, is different from the frequency of H given H, which you use in your wordings.
Example: Consider the case where the bias is fully correlated "There is a coin where if it lands head then the probability of the next flip being heads is 1 (and if tails then the next flip being tails is also 1)", then the frequencies of HH and TT will be around 0.5 (depending on the first flip being H or T), but H given H will be one, and not 0.5.
Sidenote 2: The method works, but is not very powerful. With the same example above, you have students with either only TT or only HH. You could have a very clear table like
1 HH 343
2 HT 0
3 TH 0
4 TT 479
But if these results are from only a few students (consider the extreme case of only 2 students, one flipped 343 HH's and the other flipped 479 TT's), then your bootstrapping will generate very large confidence intervals.
The confidence intervals express the frequencies of HH and TT, and that includes the first flip. So while you have 343 and 479 results, many different measurements, you treat the variability here as only the 2 students first flips.