Source: https://www.stat.berkeley.edu/~statcur/Workshop2/Presentations/functions.pdf