File:P-value vs SN.gif

Summary

Description
English: If one wants to decide if there is a signal hidden in the noise, the p-value will drop sharply around S/N=1, and then keep decreasing exponentially. In this example p=0.05 happens just before the curve tails to zero.
Date
Source https://twitter.com/j_bertolotti/status/1183715504185397248
Author Jacopo Bertolotti
Permission
(Reusing this file)
https://twitter.com/j_bertolotti/status/1030470604418428929

Mathematica 11.0 code

n = 5 10^3;
noise = RandomVariate[NormalDistribution[0, 1], {n}];
signal = Table[E^(-((x - n/2)^2/(2 (n/100)^2))), {x, 1, n}];
pvssn = Reap[For[a = 0, a <= 5, a = a + 0.05,
     data = a signal + noise;
     \[Chi]2 = Total[data^2];
     p = NIntegrate[PDF[ChiSquareDistribution[n], x], {x, \[Chi]2, \[Infinity]}];
     Sow[{a, p}];
     ];][[2, 1]]
p1 = Table[
   GraphicsRow[{
     ListPlot[pvssn[[j, 1]]*signal + noise, PlotRange -> All, Joined -> True, PlotStyle -> {Thick, Black}, LabelStyle -> {Black, Bold}, Axes -> False]
     ,
     ListPlot[pvssn[[1 ;; j]], Joined -> True, PlotStyle -> {Thick, Black}, LabelStyle -> {Black, Bold}, AxesLabel -> {"S/N", "p-value"}, PlotRange -> {{0, 5}, {0, 1}}]
     }, ImageSize -> Large, PlotLabel -> Style[StringForm["\!\(\*SubscriptBox[\(H\), \(0\)]\): the data is just Gaussian random noise.\nNull hypothesis rejected with p=``", ScientificForm[pvssn[[j, 2]], 3] ]], 
    LabelStyle -> {Black, Bold}]
   , {j, 1, Dimensions[pvssn][[1]], 1}];
ListAnimate[p1]

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Category:CC-Zero#P-value%20vs%20SN.gifCategory:Self-published work
Category:Animated GIF files Category:P-value Category:White noise Category:Hypothesis testing Category:Images with Mathematica source code
Category:Animated GIF files Category:CC-Zero Category:Hypothesis testing Category:Images with Mathematica source code Category:P-value Category:Self-published work Category:White noise