  Reliable experimental demonstrations of violations of local realism are
highly desirable for fundamental tests of quantum mechanics. One can quantify
the violation witnessed by an experiment in terms of a statistical p-value,
which can be defined as the maximum probability according to local realism of a
violation at least as high as that witnessed. Thus, high violation corresponds
to small p-value. We propose a prediction-based-ratio (PBR) analysis protocol
whose p-values are valid even if the prepared quantum state varies arbitrarily
and local realistic models can depend on previous measurement settings and
outcomes. It is therefore not subject to the memory loophole [J. Barrett et
al., Phys. Rev. A 66, 042111 (2002)]. If the prepared state does not vary in
time, the p-values are asymptotically optimal. For comparison, we consider
protocols derived from the number of standard deviations of violation of a Bell
inequality and from martingale theory [R. Gill, arXiv:quant-ph/0110137]. We
find that the p-values of the former can be too small and are therefore not
statistically valid, while those derived from the latter are sub-optimal. PBR
p-values do not require a predetermined Bell inequality and can be used to
compare results from different tests of local realism independent of
experimental details.
