Learning Quote of the Day

"For me, I am driven by two main philosophies: know more today about the world than I knew yesterday and lessen the suffering of others. You'd be surprised how far that gets you."

― Neil deGrasse Tyson

Retrieval practice (5 minutes)

  • Write down your name at the top of the page
  • Write down as many of the key terms as you can think of from Chapter 5
  • On the back of the piece of paper, write down as many of the key terms as you can think of from Sections 6.1 and 6.2 (your reading assignment for today). Here is a hint to get you going: "sample."

Today: Switching Gears

  • We've covered "Tidy", "Transform", and "Visualize"
  • Start with "Model"

Drawing

Key Definitions

Let's ask our favorite search engine:

  • Define inference
  • Define statistical inference

Key Definitions

  • The population is the (usually) large pool of observational units that we are interested in.
  • A sample is a smaller collection of observational units that is selected from the population.
  • Sampling refers to the process of selecting observations from a population. There are both random and non-random ways this can be done.
  • A sample is said be a representative sample if the characteristics of observational units selected are a good approximation of the characteristics from the original population.
  • Bias corresponds to a favoring of one group in a population over another group.

Key Definitions

  • Generalizability refers to the largest group in which it makes sense to make inferences about from the sample collected. This is directly related to how the sample was selected.
  • A parameter is a calculation based on one or more variables measured in the population. Parameters are almost always denoted symbolically using Greek letters such as \(\mu\), \(\pi\), \(\sigma\), \(\rho\), and \(\beta\).
  • A statistic is a calculated based on one or more variables measured in the sample. Parameters are usually denoted by lower case Arabic letters with other symbols added sometimes. These include \(\bar{x}\), \(\hat{p}\), \(s\), \(r\), and \(b\).

The Paradigm for the Rest of the Class

Drawing

For each of the following 3 scenarios,

  • Identify the population of interest and the population parameter
  • Identify the sample used and the statistic
  • Comment on the representativeness/generalizability of the results of the sample to the population.
  1. You want to know the average income of Pacific University graduates in the last 10 years. So you get the records of 10 randomly chosen Pacific graduates. They all answer and you take the average.
  2. Imagine it's 1993 i.e. almost all households have landlines. You want to know the average number of people in each household in Forest Grove. You randomly pick out 500 numbers from the phone book & conduct a phone survey.
  3. You want to know the prevalence of illegal downloading of TV shows among Pacific University students. You get the emails of 100 randomly chosen Pacific University students and ask them "How many times did you download a pirated TV show last week?"

Recall

  • Random sampling: where we select the sample from the population in an unbiased fashion
  • Bias: A sample is biased if some observational units have a higher probability of being included in the sample.
  • Keywords: random and probability

Probability

Probability in History

In 79 AD a volcanic eruption in the Roman city of Pompeii covered the entire city in hot ash, perfectly preserving many items…

Drawing

Probability in History

… including a Pompeii exhibit in Montreal:

Drawing

Two Approaches to Probability

There are two approaches to studying probability:

Mathematically Simulations
Drawing Drawing
  • Note: The "random simulation" in question is not limited to coin flips.

Two Approaches to Probability

  • The mathematical approach to studying probability requires more mathematical background: set theory, discrete math, calculus, and later on measure theory.
  • The simulation approach does not.
  • Instead we require a computer's random number generator to generate simulations. Why?

Simulations via Computer

Doing this repeatedly by hand is tiring:

DrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawing DrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawing DrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawing DrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawing DrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawingDrawing

Analogy for Random Simulation

  • Analogy for rest of course: POWERBALL
  • Drawing
  • We can model any random simulation by tinkering with the following attributes of Powerball:

Attributes of Powerball

  • Atrributes of the Lottery Machine:
    • How many balls do you have?
    • What are written on the balls?
    • Do the balls have equal probability of being picked?
  • Attributes of the Drawing:
    • How are you drawing the balls?
    • How many balls do you draw?
    • What are you recording about each drawn ball?
    • What do you do with drawn balls?
  • Number of Lotteries:
    • How many times do you repeat the lottery?

Tools

All hail the mosaic package, which you will need to install on the RStudio Beta Server via install.packages("mosaic"). Load as usual: library(mosaic)

The following 4 functions will give us (most of) the random simulation tools we need:

  1. rflip(): Flip a coin
  2. shuffle(): Shuffle a set of values (akin to cards)
  3. do(): Do the same thing many, many, many times
  4. resample(): the swiss army knife of functions

R Example

# Load packages, including mosaic package
library(dplyr); library(ggplot2); library(mosaic)

# Flip a coin once. Try this multiple times:
rflip()
## 
## Flipping 1 coin [ Prob(Heads) = 0.5 ] ...
## 
## H
## 
## Number of Heads: 1 [Proportion Heads: 1]

R Example

# Flip a coin 10 times. Try this multiple times:
rflip(10)
## 
## Flipping 10 coins [ Prob(Heads) = 0.5 ] ...
## 
## H H T T T H H T H T
## 
## Number of Heads: 5 [Proportion Heads: 0.5]

R Example

# Flip a coin 10 times, but do this 5 times. Try this multiple times
do(5) * rflip(10)
##    n heads tails prop
## 1 10     2     8  0.2
## 2 10     3     7  0.3
## 3 10     2     8  0.2
## 4 10     5     5  0.5
## 5 10     4     6  0.4

R Example

# Flip a coin 10 times, but do this 500 times
do(500) * rflip(10)
##      n heads tails prop
## 1   10     6     4  0.6
## 2   10     3     7  0.3
## 3   10     6     4  0.6
## 4   10     8     2  0.8
## 5   10     4     6  0.4
## 6   10     6     4  0.6
## 7   10     7     3  0.7
## 8   10     4     6  0.4
## 9   10     5     5  0.5
## 10  10     7     3  0.7
## 11  10     7     3  0.7
## 12  10     6     4  0.6
## 13  10     6     4  0.6
## 14  10     6     4  0.6
## 15  10     5     5  0.5
## 16  10     8     2  0.8
## 17  10     5     5  0.5
## 18  10     3     7  0.3
## 19  10     3     7  0.3
## 20  10     5     5  0.5
## 21  10     6     4  0.6
## 22  10     3     7  0.3
## 23  10     5     5  0.5
## 24  10     8     2  0.8
## 25  10     6     4  0.6
## 26  10     4     6  0.4
## 27  10     8     2  0.8
## 28  10     6     4  0.6
## 29  10     4     6  0.4
## 30  10     4     6  0.4
## 31  10     6     4  0.6
## 32  10     3     7  0.3
## 33  10     2     8  0.2
## 34  10     3     7  0.3
## 35  10     5     5  0.5
## 36  10     5     5  0.5
## 37  10     3     7  0.3
## 38  10     7     3  0.7
## 39  10     4     6  0.4
## 40  10     8     2  0.8
## 41  10     7     3  0.7
## 42  10     6     4  0.6
## 43  10     6     4  0.6
## 44  10     5     5  0.5
## 45  10     8     2  0.8
## 46  10     5     5  0.5
## 47  10     5     5  0.5
## 48  10     4     6  0.4
## 49  10     5     5  0.5
## 50  10     5     5  0.5
## 51  10     7     3  0.7
## 52  10     5     5  0.5
## 53  10     4     6  0.4
## 54  10     3     7  0.3
## 55  10     5     5  0.5
## 56  10     2     8  0.2
## 57  10     3     7  0.3
## 58  10     6     4  0.6
## 59  10     9     1  0.9
## 60  10     8     2  0.8
## 61  10     7     3  0.7
## 62  10     4     6  0.4
## 63  10     5     5  0.5
## 64  10     5     5  0.5
## 65  10     4     6  0.4
## 66  10     5     5  0.5
## 67  10     6     4  0.6
## 68  10     5     5  0.5
## 69  10     6     4  0.6
## 70  10     3     7  0.3
## 71  10     7     3  0.7
## 72  10     5     5  0.5
## 73  10     7     3  0.7
## 74  10     7     3  0.7
## 75  10     6     4  0.6
## 76  10     2     8  0.2
## 77  10     4     6  0.4
## 78  10     3     7  0.3
## 79  10     8     2  0.8
## 80  10     5     5  0.5
## 81  10     4     6  0.4
## 82  10     9     1  0.9
## 83  10     7     3  0.7
## 84  10     3     7  0.3
## 85  10     5     5  0.5
## 86  10     6     4  0.6
## 87  10     6     4  0.6
## 88  10     7     3  0.7
## 89  10     5     5  0.5
## 90  10     7     3  0.7
## 91  10     6     4  0.6
## 92  10     6     4  0.6
## 93  10     3     7  0.3
## 94  10     4     6  0.4
## 95  10     6     4  0.6
## 96  10     3     7  0.3
## 97  10     7     3  0.7
## 98  10     2     8  0.2
## 99  10     5     5  0.5
## 100 10     8     2  0.8
## 101 10     7     3  0.7
## 102 10     6     4  0.6
## 103 10     5     5  0.5
## 104 10     5     5  0.5
## 105 10     7     3  0.7
## 106 10     5     5  0.5
## 107 10     3     7  0.3
## 108 10     5     5  0.5
## 109 10     7     3  0.7
## 110 10     3     7  0.3
## 111 10     8     2  0.8
## 112 10     6     4  0.6
## 113 10     6     4  0.6
## 114 10     2     8  0.2
## 115 10     5     5  0.5
## 116 10     6     4  0.6
## 117 10     5     5  0.5
## 118 10     5     5  0.5
## 119 10     2     8  0.2
## 120 10     4     6  0.4
## 121 10     5     5  0.5
## 122 10     6     4  0.6
## 123 10     5     5  0.5
## 124 10     3     7  0.3
## 125 10     4     6  0.4
## 126 10     3     7  0.3
## 127 10     4     6  0.4
## 128 10     3     7  0.3
## 129 10     6     4  0.6
## 130 10     8     2  0.8
## 131 10     4     6  0.4
## 132 10     5     5  0.5
## 133 10     4     6  0.4
## 134 10     6     4  0.6
## 135 10     5     5  0.5
## 136 10     7     3  0.7
## 137 10     6     4  0.6
## 138 10     4     6  0.4
## 139 10     4     6  0.4
## 140 10     3     7  0.3
## 141 10     6     4  0.6
## 142 10     4     6  0.4
## 143 10     5     5  0.5
## 144 10     2     8  0.2
## 145 10     4     6  0.4
## 146 10     5     5  0.5
## 147 10     6     4  0.6
## 148 10     7     3  0.7
## 149 10     7     3  0.7
## 150 10     6     4  0.6
## 151 10     7     3  0.7
## 152 10     7     3  0.7
## 153 10     3     7  0.3
## 154 10     3     7  0.3
## 155 10     5     5  0.5
## 156 10     4     6  0.4
## 157 10     3     7  0.3
## 158 10     6     4  0.6
## 159 10     4     6  0.4
## 160 10     6     4  0.6
## 161 10     5     5  0.5
## 162 10     5     5  0.5
## 163 10     4     6  0.4
## 164 10     8     2  0.8
## 165 10     4     6  0.4
## 166 10     7     3  0.7
## 167 10     6     4  0.6
## 168 10     5     5  0.5
## 169 10     6     4  0.6
## 170 10     5     5  0.5
## 171 10     4     6  0.4
## 172 10     8     2  0.8
## 173 10     6     4  0.6
## 174 10     4     6  0.4
## 175 10     4     6  0.4
## 176 10     5     5  0.5
## 177 10     5     5  0.5
## 178 10     4     6  0.4
## 179 10     5     5  0.5
## 180 10     6     4  0.6
## 181 10     3     7  0.3
## 182 10     6     4  0.6
## 183 10     6     4  0.6
## 184 10     6     4  0.6
## 185 10     5     5  0.5
## 186 10     5     5  0.5
## 187 10     7     3  0.7
## 188 10     4     6  0.4
## 189 10     3     7  0.3
## 190 10     6     4  0.6
## 191 10     5     5  0.5
## 192 10     5     5  0.5
## 193 10     5     5  0.5
## 194 10     6     4  0.6
## 195 10     6     4  0.6
## 196 10     6     4  0.6
## 197 10     5     5  0.5
## 198 10     8     2  0.8
## 199 10     6     4  0.6
## 200 10     5     5  0.5
## 201 10     8     2  0.8
## 202 10     8     2  0.8
## 203 10     3     7  0.3
## 204 10     6     4  0.6
## 205 10     5     5  0.5
## 206 10     6     4  0.6
## 207 10     4     6  0.4
## 208 10     7     3  0.7
## 209 10     6     4  0.6
## 210 10     4     6  0.4
## 211 10     4     6  0.4
## 212 10     8     2  0.8
## 213 10     7     3  0.7
## 214 10     5     5  0.5
## 215 10     7     3  0.7
## 216 10     5     5  0.5
## 217 10     7     3  0.7
## 218 10     5     5  0.5
## 219 10     9     1  0.9
## 220 10     4     6  0.4
## 221 10     2     8  0.2
## 222 10     4     6  0.4
## 223 10     3     7  0.3
## 224 10     7     3  0.7
## 225 10     3     7  0.3
## 226 10     5     5  0.5
## 227 10     7     3  0.7
## 228 10     6     4  0.6
## 229 10     4     6  0.4
## 230 10     6     4  0.6
## 231 10     4     6  0.4
## 232 10     2     8  0.2
## 233 10     8     2  0.8
## 234 10     9     1  0.9
## 235 10     6     4  0.6
## 236 10     6     4  0.6
## 237 10     3     7  0.3
## 238 10     5     5  0.5
## 239 10     7     3  0.7
## 240 10     5     5  0.5
## 241 10     2     8  0.2
## 242 10     2     8  0.2
## 243 10     5     5  0.5
## 244 10     6     4  0.6
## 245 10     8     2  0.8
## 246 10     3     7  0.3
## 247 10     4     6  0.4
## 248 10     3     7  0.3
## 249 10     4     6  0.4
## 250 10     4     6  0.4
## 251 10     6     4  0.6
## 252 10     4     6  0.4
## 253 10     4     6  0.4
## 254 10     6     4  0.6
## 255 10     4     6  0.4
## 256 10     4     6  0.4
## 257 10     5     5  0.5
## 258 10     7     3  0.7
## 259 10     2     8  0.2
## 260 10     5     5  0.5
## 261 10     7     3  0.7
## 262 10     5     5  0.5
## 263 10     5     5  0.5
## 264 10     6     4  0.6
## 265 10     4     6  0.4
## 266 10     3     7  0.3
## 267 10     4     6  0.4
## 268 10     4     6  0.4
## 269 10     6     4  0.6
## 270 10     1     9  0.1
## 271 10     5     5  0.5
## 272 10     7     3  0.7
## 273 10     6     4  0.6
## 274 10     4     6  0.4
## 275 10     3     7  0.3
## 276 10     4     6  0.4
## 277 10     6     4  0.6
## 278 10     4     6  0.4
## 279 10     4     6  0.4
## 280 10     2     8  0.2
## 281 10     8     2  0.8
## 282 10     3     7  0.3
## 283 10     4     6  0.4
## 284 10     4     6  0.4
## 285 10     6     4  0.6
## 286 10     3     7  0.3
## 287 10     6     4  0.6
## 288 10     6     4  0.6
## 289 10     4     6  0.4
## 290 10     6     4  0.6
## 291 10     4     6  0.4
## 292 10     5     5  0.5
## 293 10     6     4  0.6
## 294 10     6     4  0.6
## 295 10     4     6  0.4
## 296 10     5     5  0.5
## 297 10     8     2  0.8
## 298 10     4     6  0.4
## 299 10     7     3  0.7
## 300 10     6     4  0.6
## 301 10     4     6  0.4
## 302 10     2     8  0.2
## 303 10     3     7  0.3
## 304 10     6     4  0.6
## 305 10     6     4  0.6
## 306 10     7     3  0.7
## 307 10     5     5  0.5
## 308 10     6     4  0.6
## 309 10     3     7  0.3
## 310 10     7     3  0.7
## 311 10     5     5  0.5
## 312 10     6     4  0.6
## 313 10     1     9  0.1
## 314 10     3     7  0.3
## 315 10     7     3  0.7
## 316 10     4     6  0.4
## 317 10     5     5  0.5
## 318 10     7     3  0.7
## 319 10     2     8  0.2
## 320 10     4     6  0.4
## 321 10     9     1  0.9
## 322 10     5     5  0.5
## 323 10     9     1  0.9
## 324 10     7     3  0.7
## 325 10     6     4  0.6
## 326 10     4     6  0.4
## 327 10     2     8  0.2
## 328 10     3     7  0.3
## 329 10     5     5  0.5
## 330 10     3     7  0.3
## 331 10     3     7  0.3
## 332 10     4     6  0.4
## 333 10     6     4  0.6
## 334 10     4     6  0.4
## 335 10     5     5  0.5
## 336 10     4     6  0.4
## 337 10     5     5  0.5
## 338 10     6     4  0.6
## 339 10     5     5  0.5
## 340 10     6     4  0.6
## 341 10     7     3  0.7
## 342 10     4     6  0.4
## 343 10     4     6  0.4
## 344 10     6     4  0.6
## 345 10     7     3  0.7
## 346 10     5     5  0.5
## 347 10     3     7  0.3
## 348 10     2     8  0.2
## 349 10     4     6  0.4
## 350 10     4     6  0.4
## 351 10     7     3  0.7
## 352 10     5     5  0.5
## 353 10     2     8  0.2
## 354 10     6     4  0.6
## 355 10     4     6  0.4
## 356 10     3     7  0.3
## 357 10     4     6  0.4
## 358 10     6     4  0.6
## 359 10     6     4  0.6
## 360 10     9     1  0.9
## 361 10     4     6  0.4
## 362 10     6     4  0.6
## 363 10     7     3  0.7
## 364 10     6     4  0.6
## 365 10     7     3  0.7
## 366 10     5     5  0.5
## 367 10     5     5  0.5
## 368 10     5     5  0.5
## 369 10     4     6  0.4
## 370 10     3     7  0.3
## 371 10     4     6  0.4
## 372 10     2     8  0.2
## 373 10     5     5  0.5
## 374 10     3     7  0.3
## 375 10     6     4  0.6
## 376 10     7     3  0.7
## 377 10     8     2  0.8
## 378 10     4     6  0.4
## 379 10     4     6  0.4
## 380 10     8     2  0.8
## 381 10     6     4  0.6
## 382 10     6     4  0.6
## 383 10     5     5  0.5
## 384 10     4     6  0.4
## 385 10     7     3  0.7
## 386 10     4     6  0.4
## 387 10     6     4  0.6
## 388 10     4     6  0.4
## 389 10     6     4  0.6
## 390 10     5     5  0.5
## 391 10     4     6  0.4
## 392 10     7     3  0.7
## 393 10     3     7  0.3
## 394 10     8     2  0.8
## 395 10     7     3  0.7
## 396 10     6     4  0.6
## 397 10     6     4  0.6
## 398 10     4     6  0.4
## 399 10     4     6  0.4
## 400 10     8     2  0.8
## 401 10     6     4  0.6
## 402 10     4     6  0.4
## 403 10     5     5  0.5
## 404 10     5     5  0.5
## 405 10     5     5  0.5
## 406 10     2     8  0.2
## 407 10     7     3  0.7
## 408 10     3     7  0.3
## 409 10     5     5  0.5
## 410 10     4     6  0.4
## 411 10     2     8  0.2
## 412 10     4     6  0.4
## 413 10     3     7  0.3
## 414 10     6     4  0.6
## 415 10     4     6  0.4
## 416 10     5     5  0.5
## 417 10     4     6  0.4
## 418 10     7     3  0.7
## 419 10     4     6  0.4
## 420 10     7     3  0.7
## 421 10     8     2  0.8
## 422 10     9     1  0.9
## 423 10     5     5  0.5
## 424 10     6     4  0.6
## 425 10     5     5  0.5
## 426 10     5     5  0.5
## 427 10     7     3  0.7
## 428 10     6     4  0.6
## 429 10     6     4  0.6
## 430 10     4     6  0.4
## 431 10     4     6  0.4
## 432 10     5     5  0.5
## 433 10     5     5  0.5
## 434 10     4     6  0.4
## 435 10     7     3  0.7
## 436 10     4     6  0.4
## 437 10     4     6  0.4
## 438 10     5     5  0.5
## 439 10     5     5  0.5
## 440 10     6     4  0.6
## 441 10     5     5  0.5
## 442 10     4     6  0.4
## 443 10     8     2  0.8
## 444 10     2     8  0.2
## 445 10     6     4  0.6
## 446 10     7     3  0.7
## 447 10     4     6  0.4
## 448 10     4     6  0.4
## 449 10     4     6  0.4
## 450 10     3     7  0.3
## 451 10     8     2  0.8
## 452 10     4     6  0.4
## 453 10     7     3  0.7
## 454 10     7     3  0.7
## 455 10     5     5  0.5
## 456 10     5     5  0.5
## 457 10     2     8  0.2
## 458 10     3     7  0.3
## 459 10     6     4  0.6
## 460 10     5     5  0.5
## 461 10     7     3  0.7
## 462 10     5     5  0.5
## 463 10     8     2  0.8
## 464 10     4     6  0.4
## 465 10     6     4  0.6
## 466 10     7     3  0.7
## 467 10     5     5  0.5
## 468 10     3     7  0.3
## 469 10     4     6  0.4
## 470 10     6     4  0.6
## 471 10     6     4  0.6
## 472 10     6     4  0.6
## 473 10     7     3  0.7
## 474 10     5     5  0.5
## 475 10     7     3  0.7
## 476 10     7     3  0.7
## 477 10     9     1  0.9
## 478 10     6     4  0.6
## 479 10     8     2  0.8
## 480 10     4     6  0.4
## 481 10     8     2  0.8
## 482 10     5     5  0.5
## 483 10     4     6  0.4
## 484 10     6     4  0.6
## 485 10     5     5  0.5
## 486 10     4     6  0.4
## 487 10     4     6  0.4
## 488 10     7     3  0.7
## 489 10     6     4  0.6
## 490 10     5     5  0.5
## 491 10     3     7  0.3
## 492 10     8     2  0.8
## 493 10     6     4  0.6
## 494 10     6     4  0.6
## 495 10     4     6  0.4
## 496 10     4     6  0.4
## 497 10     8     2  0.8
## 498 10     3     7  0.3
## 499 10     4     6  0.4
## 500 10     7     3  0.7

R Example

# Gah! There are too many rows!
simulations <- do(500) * rflip(10)

# We could also View() it
View(simulations)

R Example

# Plot our resulting proportions
simulations %>% ggplot(aes(x = prop)) +
  geom_histogram(binwidth = 0.1, color = "white")

R Example

# Plot our resulting proportions
simulations %>% ggplot(aes(x = factor(prop))) +
  geom_bar()

For next time

  • Read all of Chapter 6 of MODERN DIVE
  • Bring treats for the class as payment for my willingness to wear this while teaching a course
  • Carefully review the content of Chapter 6 and take notes on important concepts
    • I will be doing a "notes check" at the beginning of class on Wednesday
    • "I don't take notes" is not an acceptable response. You have to show me you are working on learning the material outside of class.
  • We'll be discussing "bootstrapping" on Wednesday. Remember that this chapter is VITAL to your understanding for the rest of the course.

Questions about Lab 6

Reflection exercise

  • Write down your name at the top of the page
  • Write down as many of the key terms as you can think of from Chapter 5
  • On the back of the piece of paper, write down as many of the key terms as you can think of from lecture today.