forked from IQSS/prefresher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_limits.Rmd
408 lines (231 loc) · 18 KB
/
03_limits.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# Limits {#limits-precalc}
```{r, include = FALSE}
library(ggplot2)
library(tibble)
library(scales)
library(glue)
library(patchwork)
```
Solving limits, i.e. finding out the value of functions as its input moves closer to some value, is important for the social scientist's mathematical toolkit for two related tasks. The first is for the study of calculus, which will be in turn useful to show where certain functions are maximized or minimized. The second is for the study of statistical inference, which is the study of inferring things about things you cannot see by using things you can see.
## Example: The Central Limit Theorem {-}
Perhaps the most important theorem in statistics is the Central Limit Theorem,
```{theorem, clt-lim, name = "Central Limit Theorem (i.i.d. case)"}
For any series of independent and identically distributed random variables $X_1, X_2, \cdots$, we know the distribution of its sum even if we do not know the distribution of $X$. The distribution of the sum is a Normal distribution.
\[\frac{\bar{X}_n - \mu}{\sigma / \sqrt{n}} \xrightarrow{d} \text{Normal}(0, 1),\]
where $\mu$ is the mean of $X$ and $\sigma$ is the standard deviation of $X$. The arrow is read as "converges in distribution to". $\text{Normal}(0, 1)$ indicates a Normal Distribution with mean 0 and variance 1.
That is, the limit of the distribution of the lefthand side is the distribution of the righthand side.
```
The sign of a limit is the arrow "$\rightarrow$". Although we have not yet covered probability (in Section \@ref(probability-theory)) so we have not described what distributions and random variables are, it is worth foreshadowing the Central Limit Theorem. The Central Limit Theorem is powerful because it gives us a _guarantee_ of what would happen if $n \rightarrow \infty$, which in this case means we collected more data.
## Example: The Law of Large Numbers {-}
A finding that perhaps rivals the Central Limit Theorem is the Law of Large Numbers:
```{theorem, lln-lim, name = "(Weak) Law of Large Numbers"}
For any draw of identically distributed independent variables with mean $\mu$, the sample average after $n$ draws, $\bar{X}_n$, converges in probability to the true mean as $n \rightarrow \infty$:
\[\lim\limits_{n\to \infty} P(|\bar{X}_n - \mu | > \varepsilon) = 0\]
A shorthand of which is \(\bar{X}_n \xrightarrow{p} \mu\), where the arrow is read as "converges in probability to".
```
Intuitively, the more data, the more accurate is your guess. For example, the Figure \@ref(fig:llnsim) shows how the sample average from many coin tosses converges to the true value : 0.5.
```{r, llnsim, fig.cap="As the number of coin tosses goes to infinity, the average probabiity of heads converges to 0.5", echo= FALSE}
set.seed(02138)
n <- 1e3
Xs <- rbinom(n = n, size = 1, prob = 0.5)
means <- cumsum(Xs) / 1:n
ggplot(tibble(n = 1:n, estimate = means), aes(x = n, y = estimate))
geom_line()
scale_x_continuous(labels = comma, limit = c(0, n*1.1), breaks = seq(0, n, length.out = 5))
scale_y_continuous(limits = c(0, 1))
annotate(geom = "text", x = 1.1*n, y = means[n], label = glue("Estimate at\nn = {comma(n)}", ":\n", means[n]), size = 2.8)
annotate(geom = "point", x = n, y = means[n])
labs(x = "n, or the number of times of a coin-flip experiment",
y = "Estimate of the Probability of Heads after n trials")
```
## Sequences
We need a couple of steps until we get to limit theorems in probability. First we will introduce a "sequence", then we will think about the limit of a sequence, then we will think about the limit of a _function_.
A **sequence** \[\{x_n\}=\{x_1, x_2, x_3, \ldots, x_n\}\] is an ordered set of real numbers, where $x_1$ is the first term in the sequence and $y_n$ is the $n$th term. Generally, a sequence is infinite, that is it extends to $n=\infty$. We can also write the sequence as \[\{x_n\}^\infty_{n=1}\]
where the subscript and superscript are read together as "from 1 to infinity."
```{example, seqbehav, name = "Sequences"}
How do these sequences behave?
1. $\{A_n\}=\left\{ 2-\frac{1}{n^2} \right\}$
2. $\{B_n\}=\left\{\frac{n^2 1}{n} \right\}$
3. $\{C_n\}=\left\{(-1)^n \left(1-\frac{1}{n}\right) \right\}$
```
We find the sequence by simply "plugging in" the integers into each $n$. The important thing is to get a sense of how these numbers are going to change. Example 1's numbers seem to come closer and closer to 2, but will it ever surpass 2? Example 2's numbers are also increasing each time, but will it hit a limit? What is the pattern in Example 3? Graphing helps you make this point more clearly. See the sequence of $n = 1, ...20$ for each of the three examples in Figure \@ref(fig:seqabc).
```{r, seqabc, fig.cap = "Behavior of Some Sequences", echo = FALSE}
seq <- 1:20
df <- tibble(n = seq, A = 2 - 1/(seq^2), B = (seq^2 1)/(seq), C = (-1)^seq * (1 - 1/seq))
g0 <- ggplot(df, aes(x = n, y = A)) geom_point()
gA <- g0 labs(y = expression(A[n]))
gB <- g0 aes(y = B) labs(y = expression(B[n]))
gC <- g0 aes(y = C) labs(y = expression(C[n]))
gA gB gC plot_layout(nrow = 1)
```
## The Limit of a Sequence
The notion of "converging to a limit" is the behavior of the points in Example \@ref(exm:seqbehav). In some sense, that's the counterfactual we want to know. What happens as $n\rightarrow \infty$?
1. Sequences like 1 above that converge to a limit.
2. Sequences like 2 above that increase without bound.
3. Sequences like 3 above that neither converge nor increase without bound --- alternating over the number line.
```{definition}
The sequence $\{y_n\}$ has the limit $L$, which we write as \[\lim\limits_{n \to \infty} y_n =L\], if for any $\epsilon>0$ there is an integer $N$ (which depends on $\epsilon$) with the property that $|y_n -L|<\epsilon$ for each $n>N$. $\{y_n\}$ is said to converge to $L$. If the above does not hold, then $\{y_n\}$ diverges.
```
We can also express the behavior of a sequence as bounded or not:
1. Bounded: if $|y_n|\le K$ for all $n$
2. Monotonically Increasing: $y_{n 1}>y_n$ for all $n$
3. Monotonically Decreasing: $y_{n 1}<y_n$ for all $n$
A limit is *unique*: If $\{y_n\}$ converges, then the limit $L$ is unique.
If a sequence converges, then the sum of such sequences also converges. Let $\lim\limits_{n \to \infty} y_n = y$ and $\lim\limits_{n \to \infty} z_n =z$. Then
1. $\lim\limits_{n \to \infty} [k y_n \ell z_n]= k y \ell z$
1. $\lim\limits_{n \to \infty} y_n z_n = yz$
1. $\lim\limits_{n \to \infty} \frac{y_n}{z_n} = \frac{y}{z}$, provided $z\neq 0$
This looks reasonable enough. The harder question, obviously is when the parts of the fraction _don't_ converge. If $\lim_{n\to\infty} y_n = \infty$ and $\lim_{n\to\infty} z_n = \infty$, What is $\lim_{n\to\infty} y_n - z_n$? What is $\lim_{n\to\infty} \frac{y_n}{z_n}$?
It is nice for a sequence to converge in limit. We want to know if complex-looking sequences converge or not. The name of the game here is to break that complex sequence up into sums of simple fractions where $n$ only appears in the denominator: $\frac{1}{n}, \frac{1}{n^2}$, and so on. Each of these will converge to 0, because the denominator gets larger and larger. Then, because of the properties above, we can then find the final sequence.
```{example, name = "Simplifying a Fraction into Sums"}
Find the limit of
\[\lim_{n\to \infty} \frac{n 3}{n},\]
```
```{solution}
At first glance, $n 3$ and $n$ both grow to $\infty$, so it looks like we need to divide infinity by infinity. However, we can express this fraction as a sum, then the limits apply separately:
\[\lim_{n\to \infty} \frac{n 3}{n} = \lim_{n\to \infty} \left(1 \frac{3}{n}\right) = \underbrace{\lim_{n\to \infty}1}_{1} \underbrace{\lim_{n\to \infty}\left(\frac{3}{n}\right)}_{0}\]
so, the limit is actually 1.
```
After some practice, the key to intuition is whether one part of the fraction grows "faster" than another. If the denominator grows faster to infinity than the numerator, then the fraction will converge to 0, even if the numerator will also increase to infinity. In a sense, limits show how not all infinities are the same.
```{exercise, limseq2}
Find the following limits of sequences, then explain in English the intuition for why that is the case.
1. \(\lim\limits_{n\to\infty} \frac{2n}{n^2 1}\)
2. \(\lim\limits_{n\to\infty} (n^3 - 100n^2)\)
```
## Limits of a Function {#limitsfun}
We've now covered functions and just covered limits of sequences, so now is the time to combine the two.
A function $f$ is a compact representation of some behavior we care about. Like for sequences, we often want to know if $f(x)$ approaches some number $L$ as its independent variable $x$ moves to some number $c$ (which is usually 0 or $\pm\infty$). If it does, we say that the limit of $f(x)$, as $x$ approaches $c$, is $L$: $\lim\limits_{x \to c} f(x)=L$. Unlike a sequence, $x$ is a continuous number, and we can move in decreasing order as well as increasing.
For a limit $L$ to exist, the function $f(x)$ must approach $L$ from both the left (increasing) and the right (decreasing).
```{definition, name = "Limit of a function"}
Let $f(x)$ be defined at each point in some open interval containing the point $c$. Then $L$ equals $\lim\limits_{x \to c} f(x)$ if for any (small positive) number $\epsilon$, there exists a corresponding number $\delta>0$ such that if $0<|x-c|<\delta$, then $|f(x)-L|<\epsilon$.
```
A neat, if subtle result is that $f(x)$ does not necessarily have to be defined at $c$ for $\lim\limits_{x \to c}$ to exist.
Properties: Let $f$ and $g$ be functions with $\lim\limits_{x \to c} f(x)=k$ and $\lim\limits_{x \to c} g(x)=\ell$.
1. $\lim\limits_{x \to c}[f(x) g(x)]=\lim\limits_{x \to c} f(x) \lim\limits_{x \to c} g(x)$
2. $\lim\limits_{x \to c} kf(x) = k\lim\limits_{x \to c} f(x)$
3. $\lim\limits_{x \to c} f(x) g(x) = \left[\lim\limits_{x \to c} f(x)\right]\cdot \left[\lim\limits_{x \to c} g(x)\right]$
4. $\lim\limits_{x \to c} \frac{f(x)}{g(x)} = \frac{\lim\limits_{x \to c} f(x)}{\lim\limits_{x \to c} g(x)}$, provided $\lim\limits_{x \to c} g(x)\ne 0$.
Simple limits of functions can be solved as we did limits of sequences. Just be careful which part of the function is changing.
```{example, limfun1, name ="Limits of Functions"}
Find the limit of the following functions.
1. \(\lim_{x \to c} k\)
1. \(\lim_{x \to c} x\)
1. \(\lim_{x\to 2} (2x-3)\)
1. \(\lim_{x \to c} x^n\)
```
Limits can get more complex in roughly two ways. First, the functions may become large polynomials with many moving pieces. Second,the functions may become discontinuous.
The function can be thought of as a more general or "smooth" version of sequences. For example,
```{exercise, limfunmax, name = "Limits of a Fraction of Functions"}
Find the limit of
\[\lim_{x\to\infty} \frac{(x^4 3x−99)(2−x^5)}{(18x^7 9x^6 −3x^2 −1)(x 1)}\]
```
Now, the functions will become a bit more complex:
```{exercise, discontlim}
Solve the following limits of functions
1. $\lim\limits_{x\to 0} |x|$
2. $\lim\limits_{x\to 0} \left(1 \frac{1}{x^2}\right)$
```
So there are a few more alternatives about what a limit of a function could be:
1. Right-hand limit: The value approached by $f(x)$ when you move from right to left.
2. Left-hand limit: The value approached by $f(x)$ when you move from left to right.
3. Infinity: The value approached by $f(x)$ as x grows infinitely large. Sometimes this may be a number; sometimes it might be $\infty$ or $-\infty$.
4. Negative infinity: The value approached by $f(x)$ as x grows infinitely negative. Sometimes this may be a number; sometimes it might be $\infty$ or $-\infty$.
The distinction between left and right becomes important when the function is not determined for some values of $x$. What are those cases in the examples below?
```{r, echo=FALSE,fig.cap="Functions which are not defined in some areas", warning = FALSE}
range1 <- tibble::tibble(x = c(-2, 16))
range2 <- tibble::tibble(x = c(-2, 2))
fx1 <- ggplot(range1, aes(x = x))
stat_function(fun = function(x) sqrt(x), size = 0.5)
labs(x = expression(x), y = expression(f(x)), title = expression(f(x)==sqrt(x)))
expand_limits(y = max(range1$x))
fx2 <-
ggplot(range2, aes(x = x))
stat_function(fun = function(x) ifelse(x == 0, NA, 1/x), size = 0.5)
labs(x = expression(x), y = expression(f(x)), title = expression(f(x)==frac(1,x)))
fx1 fx2 plot_layout(nrow = 1)
```
## Continuity
To repeat a finding from the limits of functions: $f(x)$ does not necessarily have to be defined at $c$ for $\lim\limits_{x \to c}$ to exist. Functions that have breaks in their lines are called discontinuous. Functions that have no breaks are called continuous. Continuity is a concept that is more fundamental to, but related to that of "differentiability", which we will cover next in calculus.
```{definition, name = "Continuity"}
Suppose that the domain of the function $f$ includes an open interval containing the point $c$. Then $f$ is continuous at $c$ if $\lim\limits_{x \to c} f(x)$ exists and if $\lim\limits_{x \to c} f(x)=f(c)$. Further, $f$ is continuous on an open interval $(a,b)$ if it is continuous at each point in the interval.
```
To prove that a function is continuous for all points is beyond this practical introduction to math, but the general intuition can be grasped by graphing.
```{example, contdiscont, name = "Continuous and Discontinuous Functions"}
For each function, determine if it is continuous or discontinuous.
1. $f(x) = \sqrt{x}$
2. $f(x) = e^x$
3. $f(x) = 1 \frac{1}{x^2}$
4. $f(x) = \text{floor}(x)$.
The floor is the smaller of the two integers bounding a number. So $\text{floor}(x = 2.999) = 2$, $\text{floor}(x = 2.0001) = 2$, and $\text{floor}(x = 2) = 2.$
```
```{solution}
In Figure \@ref(fig:fig-contdiscont), we can see that the first two functions are continuous, and the next two are discontinuous. $f(x) = 1 \frac{1}{x^2}$ is discontinuous at $x= 0$, and $f(x) = \text{floor}(x)$ is discontinuous at each whole number.
```
```{r, fig-contdiscont, echo=FALSE,fig.cap="Continuous and Discontinuous Functions", warning = FALSE}
range1 <- tibble(x = c(0, 10))
range2 <- tibble(x = c(-2, 2))
range3 <- tibble(x = c(-4, 4))
range4 <- tibble(x = c(0, 5))
fx1 <- ggplot(range1, aes(x = x))
stat_function(fun = function(x) sqrt(x), size = 0.5)
labs(y = expression(f(x)), title = expression(f(x)==sqrt(x)))
fx2 <- ggplot(range2, aes(x = x))
stat_function(fun = function(x) exp(x), size = 0.5)
labs(y = expression(f(x)), title = expression(f(x)==e^x))
fx3 <- ggplot(range3, aes(x = x))
stat_function(fun = function(x) ifelse(x == 0, NA, 1 1/(x^2)), size = 0.5)
labs(y = expression(f(x)), title = expression(f(x)==1 frac(1,x^2)))
fx4 <- ggplot(range4, aes(x = x))
stat_function(fun = function(x) ifelse(1 - (x %% 1) < 9e-2, NA, floor(x)), size = 0.5)
geom_point(data = tibble(x = 0:5, y = 0:5), aes(y = y), pch = 19)
geom_point(data = tibble(x = 1:5, y = (1:5) - 1), aes(y = y), pch = 21, fill = "white")
labs(y = expression(f(x)), title = expression(f(x)==plain("floor(x)")))
fx1 fx2 fx3 fx4 plot_layout(ncol = 2)
```
Some properties of continuous functions:
1. If $f$ and $g$ are continuous at point $c$, then $f g$, $f-g$, $f \cdot g$, $|f|$, and $\alpha f$ are continuous at point $c$ also. $f/g$ is continuous, provided $g(c)\ne 0$.
2. Boundedness: If $f$ is continuous on the closed bounded interval $[a,b]$, then there is a number $K$ such that $|f(x)|\le K$ for each $x$ in $[a,b]$.
3. Max/Min: If $f$ is continuous on the closed bounded interval $[a,b]$, then $f$ has a maximum and a minimum on $[a,b]$. They may be located at the end points.
```{exercise, discontdraw, name = "Limit when Denominator converges to 0"}
Let \[f(x) = \frac{x^2 2x}{x}.\]
1. Graph the function. Is it defined everywhere?
2. What is the functions limit at $x \rightarrow 0$?
```
## Answers to Examples {-}
Example \@ref(exm:seqbehav)
```{solution}
1. $\{A_n\}=\left\{ 2-\frac{1}{n^2} \right\} = \left\{1, \frac{7}{4}, \frac{17}{9}, \frac{31}{16}, \frac{49}{25}, \ldots\right\} = 2$
2. $\{B_n\}=\left\{\frac{n^2 1}{n} \right\} = \left\{2, \frac{5}{2}, \frac{10}{3}, \frac{17}{4}..., \right\}$
3. $\{C_n\}=\left\{(-1)^n \left(1-\frac{1}{n}\right) \right\} = \left\{0, \frac{1}{2}, -\frac{2}{3}, \frac{3}{4}, -\frac{4}{5}\right\}$
```
Exercise \@ref(exr:limseq2)
```{r}
```
Example \@ref(exm:limfun1)
```{solution}
1. $k$
2. $c$
3. \(\lim_{x\to 2} (2x-3) = 2\lim\limits_{x\to 2} x - 3\lim\limits_{x\to 2} 1 = 1\)
4. \(\lim_{x \to c} x^n = \lim\limits_{x \to c} x \cdots[\lim\limits_{x \to c} x] = c\cdots c =c^n\)
```
Exercise \@ref(exr:limfunmax)
```{solution}
Although this function seems large, the thing our eyes should focus on is where the highest order polynomial remains. That will grow the fastest, so if the highest order term is on the denominator, the fraction will converge to 0, if it is on the numerator it will converge to negative infinity. Previewing the multiplication by hand, we can see that the $-x^9$ on the numerator will be the largest power. So the answer will be $-\infty$. We can also confirm this by writing out fractions:
\begin{align*}
& \lim_{x\to\infty}\frac{\left(1 \frac{3}{x^3} - \frac{99}{4x^4}\right)\left(-\frac{2}{x^5} 1\right)}{\left(1 \frac{9}{18x} - \frac{3}{18x^5} - \frac{1}{18x^7} \right)\left(1 \frac{1}{x}\right)} \\
&\times \frac{x^4}{1} \times -\frac{x^5}{1} \times \frac{1}{18x^7}\times \frac{1}{x}\\
=& 1 \times \lim_{-x\to\infty} \frac{x}{18}
\end{align*}
```
Exercise \@ref(exr:discontdraw)
```{solution}
See Figure \@ref(fig:fig-hole-0).
Divide each part by $x$, and we get $x \frac{2}{x}$ on the numerator, $1$ on the denominator. So, without worrying about a function being not defined, we can say $\lim_{x\to 0}f(x) = 0$.
```
```{r, fig-hole-0, fig.cap = "A function undedefined at x = 0", echo=FALSE}
range0 <- tibble(x = c(-4, 2))
ggplot(range0, aes(x = x))
stat_function(fun = function(x) ifelse(x == 0, NA, (x^2 2*x)/(x)), size = 0.5)
labs(y = expression(f(x)), title = expression(f(x)==frac(x^2 2*x, x^2)))
geom_point(data = tibble(x = 0, y = 2), aes(y = y), pch = 21, fill = "white")
```