Source: https://astrostatistics.psu.edu/su10/lectures/BrazilTSA.pdf