class: center, middle, inverse, title-slide # Integral Calculus --- # The Problem To compute a p-value, we need to know the area of the shaded part of the probability distribution function. <img src="10-integrals_files/figure-html/unnamed-chunk-1-1.png" width="400px" style="display: block; margin: auto;" /> Formally: `$$\int_{\hat{\tau}}^\infty \mathcal{N}\left(0, \frac{\sigma^2}{n}\right)$$` --- # The Area Under a Curve Rectangles are easy. `\(A = bh\)` <img src="10-integrals_files/figure-html/rectangular area-1.png" width="600" style="display: block; margin: auto;" /> --- # The Area Under a Curve Curves are harder. We didn't learn this in geometry! <img src="10-integrals_files/figure-html/plot curve-1.png" width="600" style="display: block; margin: auto;" /> --- # The Area Under a Curve - With derivatives, we approximated a hard problem (the slope of a curve) using an easy problem (the slope of a line) by zooming in close enough. -- - With integrals, we'll use a similar trick. -- - We approximate a hard problem (the area under a curve) using an easy problem (the area of a bunch of rectangles) by making the rectangles *really* thin. --- # Riemann Sum `\(f(x) = x^3 - 2x^2 + 2\)`. Find area under curve from `\(x=0\)` to `\(x=3\)`. -- <img src="10-integrals_files/figure-html/reimann sum 1-1.png" width="600" style="display: block; margin: auto;" /> --- # Riemann Sum `\(f(x) = x^3 - 2x^2 + 2\)`. Find area under curve from `\(x=0\)` to `\(x=3\)`. <img src="10-integrals_files/figure-html/reimann sum 3-1.png" width="600" style="display: block; margin: auto;" /> --- # Riemann Sum `\(f(x) = x^3 - 2x^2 + 2\)`. Find area under curve from `\(x=0\)` to `\(x=3\)`. <img src="10-integrals_files/figure-html/reimann sum 4-1.png" width="600" style="display: block; margin: auto;" /> --- # Riemann Sum `\(f(x) = x^3 - 2x^2 + 2\)`. Find area under curve from `\(x=0\)` to `\(x=3\)`. <img src="10-integrals_files/figure-html/reimann sum 5-1.png" width="600" style="display: block; margin: auto;" /> --- # Riemann Sum `\(f(x) = x^3 - 2x^2 + 2\)`. Find area under curve from `\(x=0\)` to `\(x=3\)`. <img src="10-integrals_files/figure-html/reimann sum 6-1.png" width="600" style="display: block; margin: auto;" /> --- ## Integral Notation $$\lim_{h \to 0} \sum f(x) \cdot h = \int f(x)dx $$ -- `\(dx\)` is an "infinitesimal" (infinitely small value). So `\(\int f(x)dx\)` is the area of an infinite number of infinitely skinny rectangles. -- If we want the area under a curve between `\(a\)` and `\(b\)`, we denote it like so: `$$\int_a^b f(x)dx$$` --- ## There has to be an easier way! What we want is a function `\(F(x)\)`; let's call it the **area function**. - `\(F(a)\)` gives the area under `\(f(x)\)` between `\(-\infty\)` and `\(a\)`. - `\(F(b) - F(a)\)` gives the area under `\(f(x)\)` between `\(a\)` and `\(b\)`. -- - As `\(h\)` approaches zero, our skinny rectangles become a better and better approximation of the area function... `$$f(x) \cdot h = \lim_{h \to 0} F(x+h) - F(x)$$` -- Divide by `\(h\)` on both sides: `$$f(x) = \lim_{h \to 0} \frac{F(x+h) - F(x)}{h}$$` -- Hey. We've seen that before! -- `\(f(x) = F'(x)\)`. In other words, `\(F(x)\)` is the *antiderivative* of `\(f(x)\)`. --- # The Fundamental Theorem of Calculus `$$\int_a^b f(x)dx = F(b) - F(a)$$` -- Computing the area under the curve and taking the antiderivative are equivalent operations! --- # Try It! If `\(f(x) = x\)`, find the area under the curve between `\(x=0\)` and `\(x=4\)`. <img src="10-integrals_files/figure-html/plot triangle-1.png" width="600" style="display: block; margin: auto;" /> -- **Hint**: It's a triangle, so the answer should be 8. --- # The Area Under a Curve If `\(f(x) = x\)`, find the area under the curve between `\(x=0\)` and `\(x=4\)`. Use the Fundamental Theorem of Calculus: `$$\int_0^4 f(x)dx = F(4) - F(0)$$` -- `\(F(x) = \frac{1}{2}x^2 + C\)` -- `\(F(4) - F(0) = \frac{1}{2}\cdot4^2 = 8\)` --- ## Now a Nonlinear Example... If `\(f(x) = x^3 - 2x^2 + 2\)`, find the area under the curve between `\(x=0\)` and `\(x=3\)`. -- `$$\int_0^3 f(x)dx = F(3) - F(0)$$` -- `\(F(x) = \frac{1}{4}x^4 - \frac{2}{3}x^3 + 2x + C\)` -- `\(F(3) - F(0) = \frac{1}{4}3^4 - \frac{2}{3}3^3 + 2(3) - [\frac{1}{4}0^4 - \frac{2}{3}0^3 + 2(0)]\)` -- `\(= 8.25\)` --- ## Now a Nonlinear Example... That's the same answer that we got from the skinny rectangles! <img src="10-integrals_files/figure-html/reimann sum 7-1.png" width="600" style="display: block; margin: auto;" />