- Page 2 and 3: Learning statistics with R: A tutor
- Page 4 and 5: This book is published under a Crea
- Page 6 and 7: Preface Table of Contents I Backgro
- Page 8 and 9: 8.6 Summary . . . . . . . . . . . .
- Page 10 and 11: VI Endings, alternatives and prospe
- Page 12 and 13: February 16, 2015 Preface to Versio
- Page 14 and 15: and density is discussed. A detaile
- Page 18 and 19: ut for my money, the best answer is
- Page 20 and 21: statistics. It’s just too easy fo
- Page 22 and 23: all this with the concern that Berk
- Page 24 and 25: 1.4 Statistics in everyday life “
- Page 26 and 27: • My chromosomal gender is male.
- Page 28 and 29: • A theoretical construct. This i
- Page 30 and 31: So, let’s suppose I asked 100 peo
- Page 32 and 33: 2.2.6 Some complexities Okay, I kno
- Page 34 and 35: Table 2.2: The terminology used to
- Page 36 and 37: wouldn’t get lung cancer, and our
- Page 38 and 39: do in real life. • Your lab exper
- Page 40 and 41: that the reason that a lot of studi
- Page 42 and 43: people that they do have this right
- Page 44 and 45: able to read and count, and perform
- Page 46 and 47: Often, the point of a hoax is to di
- Page 48 and 49: • Validity and its threats (Secti
- Page 51 and 52: 3. Getting started with R Robots ar
- Page 53 and 54: 3.1.1 Installing R on a Windows com
- Page 55 and 56: Figure 3.1: An R session in progres
- Page 57 and 58: 10 = 20 Error in 10 = 20 : invalid
- Page 59 and 60: And as far as R is concerned, this
- Page 61 and 62: probably mention: taking powers, do
- Page 63 and 64: When you hit enter, R doesn’t pri
- Page 65 and 66: NA_real_, NA_complex_, and finally,
- Page 67 and 68:
sqrt( 1 + abs(-8) ) [1] 3 When R ex
- Page 69 and 70:
Figure 3.2: Start typing the name o
- Page 71 and 72:
Figure 3.4: The history panel is lo
- Page 73 and 74:
february.sales. The fact that this
- Page 75 and 76:
3.8.1 Working with text Working wit
- Page 77 and 78:
Table 3.2: Some logical operators.
- Page 79 and 80:
producing are actually a third kind
- Page 81 and 82:
vector. So, suppose I wanted the da
- Page 83 and 84:
Figure 3.5: The dialog box that sho
- Page 85 and 86:
• Basic commands. Wetalkedabitabo
- Page 87 and 88:
4. Additional R concepts In Chapter
- Page 89 and 90:
Figure 4.1: The packages panel. ...
- Page 91 and 92:
4.2.4 A few extra comments Sections
- Page 93 and 94:
(a) (b) Figure 4.2: The package ins
- Page 95 and 96:
Figure 4.4: The Rstudio “Environm
- Page 97 and 98:
who() -- Name -- -- Class -- -- Siz
- Page 99 and 100:
setwd("/Users/dan/Rbook/data") > se
- Page 101 and 102:
In other words, Rstudio sends a com
- Page 103 and 104:
Figure 4.7: The booksales.csv data
- Page 105 and 106:
Figure 4.8: A dialog box on a Mac a
- Page 107 and 108:
een used in about 20 years. Alterna
- Page 109 and 110:
profit profit [1] 3.1 0.1 -1.4 1.1
- Page 111 and 112:
x class(x) [1] "logical" > x clas
- Page 113 and 114:
gender, with two levels correspondi
- Page 115 and 116:
expt expt age gender group score 1
- Page 117 and 118:
$nerd [1] TRUE $parents [1] "Joe" "
- Page 119 and 120:
Hm. You can kind of see that it is
- Page 121 and 122:
Okay, so what this is telling us is
- Page 123 and 124:
is dense and highly technical, it
- Page 125:
Part III. Working with data - 111 -
- Page 128 and 129:
Frequency 0 10 20 30 0 20 40 60 80
- Page 130 and 131:
values up, and then divide by the t
- Page 132 and 133:
Figure 5.2: An illustration of the
- Page 134 and 135:
Couldn’t have put it better mysel
- Page 136 and 137:
Essendon Fitzroy Fremantle Geelong
- Page 138 and 139:
And not surprisingly, this agrees w
- Page 140 and 141:
ather than absolute deviations. If
- Page 142 and 143:
the variance is that there really i
- Page 144 and 145:
winning margin of about 30 points.
- Page 146 and 147:
negatively skewed. On the other han
- Page 148 and 149:
Okay, what about if we feed it a lo
- Page 150 and 151:
Notice that these descriptive stati
- Page 152 and 153:
or, alternatively, if you want to c
- Page 154 and 155:
Table 5.1: Descriptive statistics f
- Page 156 and 157:
My grumpiness 40 50 60 70 80 90 5 6
- Page 158 and 159:
positive correlations negative corr
- Page 160 and 161:
Table 5.2: A rough guide to interpr
- Page 162 and 163:
Grade Received 0 20 40 60 80 100 0
- Page 164 and 165:
weekday on which you actually did t
- Page 166 and 167:
automaton to do, but it’s rarely
- Page 168 and 169:
cor(parenthood2, use = "pairwise.co
- Page 170 and 171:
Thus it is no small thing to say th
- Page 172 and 173:
100 m. 0 2 4 Snow’s cholera map o
- Page 174 and 175:
can (or should) be painted using th
- Page 176 and 177:
You specify title using the ’main
- Page 178 and 179:
The Fibonacci number 2 4 6 8 10 12
- Page 180 and 181:
pch (i.e., plot character) values l
- Page 182 and 183:
arguments. For instance, if I decid
- Page 184 and 185:
• Orientation of the axis labels
- Page 186 and 187:
Histogram of afl.margins Histogram
- Page 188 and 189:
that, they don’t work very well f
- Page 190 and 191:
have a look at how they work, again
- Page 192 and 193:
The first part of the argument name
- Page 194 and 195:
the middle man and use a command li
- Page 196 and 197:
0 50 100 150 1987 1990 1993 1996 19
- Page 198 and 199:
parenthood$dan.grump 40 50 60 70 80
- Page 200 and 201:
dan.grump 40 50 60 70 80 90 5 6 7 8
- Page 202 and 203:
4 6 8 10 12 0 20 60 100 dan.sleep 5
- Page 204 and 205:
[1] "Adelaide" "Brisbane" "Carlton"
- Page 206 and 207:
This works pretty nicely for most s
- Page 208 and 209:
- 194 -
- Page 210 and 211:
chapter once and try to follow as m
- Page 212 and 213:
tombliboo 1 0 1 0 upsy-daisy 0 2 0
- Page 214 and 215:
Now let’s load and look at the da
- Page 216 and 217:
age.group data.frame( age, age.gro
- Page 218 and 219:
Table 7.1: Some of the mathematical
- Page 220 and 221:
-42 %% 10 [1] 8 7.3.3 Logarithms an
- Page 222 and 223:
7.4.1 Refresher This section return
- Page 224 and 225:
who() -- Name -- -- Class -- -- Siz
- Page 226 and 227:
speaker utterance 7 makka-pakka pip
- Page 228 and 229:
is.MP.speaking is.MP.speaking [1]
- Page 230 and 231:
ackets (next section). As I say, it
- Page 232 and 233:
Because of the fact that a data fra
- Page 234 and 235:
what R does is first sort by speake
- Page 236 and 237:
[1,] 1 1 2 3 5 8 [2,] 1 1 2 3 5 8 [
- Page 238 and 239:
7.7 Reshaping a data frame One of t
- Page 240 and 241:
under the influence of alcohol, caf
- Page 242 and 243:
Notice that this time around we hav
- Page 244 and 245:
7.8.2 Pasting strings together Much
- Page 246 and 247:
However, if we don’t do this, the
- Page 248 and 249:
makes use of a number of “special
- Page 250 and 251:
cat( "xxxx\roo" ) # \r returns you
- Page 252 and 253:
7.9.1 Loading data from text files
- Page 254 and 255:
iefly showing how to open SPSS data
- Page 256 and 257:
x class(x) # what class is it? [1]
- Page 258 and 259:
Table 7.5: An illustration of two d
- Page 260 and 261:
likert.ordinal print( likert.ordin
- Page 262 and 263:
7.12.1 The problems with floating p
- Page 264 and 265:
Figure 7.2: The environment panel i
- Page 266 and 267:
investigate yourself once you’re
- Page 268 and 269:
8.1.1 Why use scripts? Before discu
- Page 270 and 271:
Figure 8.1: A screenshot showing th
- Page 272 and 273:
help make scripting easier, but I w
- Page 274 and 275:
} STATEMENT2 ETC The code correspon
- Page 276 and 277:
at an annual interest rate of 5%. T
- Page 278 and 279:
if ( CONDITION ) { STATEMENT1 STATE
- Page 280 and 281:
slightly more complicated functions
- Page 282 and 283:
The tapply() and by() functions are
- Page 285 and 286:
Prelude to Part IV Part IV of the b
- Page 287 and 288:
me: Hm, that is a good point and I
- Page 289 and 290:
9. Introduction to probability [God
- Page 291 and 292:
H H H H H H H H H H H and what I’
- Page 293 and 294:
Proportion of Heads 0.3 0.4 0.5 0.6
- Page 295 and 296:
For the most part, I’m a pragmati
- Page 297 and 298:
Table 9.1: Some basic rules that pr
- Page 299 and 300:
Probability 0.00 0.05 0.10 0.15 0.2
- Page 301 and 302:
Table 9.2: Formulas for the binomia
- Page 303 and 304:
Probability Density 0.0 0.1 0.2 0.3
- Page 305 and 306:
Probability Density 0.0 0.1 0.2 0.3
- Page 307 and 308:
than density. Maybe you noticed tha
- Page 309 and 310:
Probability Density 0.00 0.05 0.10
- Page 311 and 312:
Simulated Normal Data Simulated Chi
- Page 313 and 314:
introduced the idea of a probabilit
- Page 315 and 316:
10. Estimating unknown quantities f
- Page 317 and 318:
Figure 10.1: Simple random sampling
- Page 319 and 320:
scope of this book, but to give you
- Page 321 and 322:
Probability Density 0.000 0.010 0.0
- Page 323 and 324:
is... an average), so let’s look
- Page 325 and 326:
60 80 100 120 140 IQ Score Figure 1
- Page 327 and 328:
SEM decreases. Okay, so that’s on
- Page 329 and 330:
10.4 Estimating population paramete
- Page 331 and 332:
Population Standard Deviation 0 10
- Page 333 and 334:
need to make a tiny tweak to transf
- Page 335 and 336:
sufficiently large - large enough f
- Page 337 and 338:
Sample Size = 10 (a) Mean IQ 80 90
- Page 339 and 340:
Average Attendance 20000 30000 4000
- Page 341 and 342:
11. Hypothesis testing The process
- Page 343 and 344:
Maybe I’m just not creative enoug
- Page 345 and 346:
chance that this would happen even
- Page 347 and 348:
Sampling Distribution for X if the
- Page 349 and 350:
appropriate α level (0-40 and 60-1
- Page 351 and 352:
my N “ 100 participants got the a
- Page 353 and 354:
Table 11.1: A commonly adopted conv
- Page 355 and 356:
Sampling Distribution for X if θ=.
- Page 357 and 358:
Probability of Rejecting the Null 0
- Page 359 and 360:
Probability of Rejecting the Null 0
- Page 361 and 362:
null hypothesis and an alternative
- Page 363:
Part V. Statistical tools - 349 -
- Page 366 and 367:
library( lsr ) > load( "randomness.
- Page 368 and 369:
clubs diamonds hearts spades 0.25 0
- Page 370 and 371:
Okay, let’s suppose that the null
- Page 372 and 373:
The critical value is 7.81 The obse
- Page 374 and 375:
hearts 64 50 0.25 spades 50 50 0.25
- Page 376 and 377:
describe it in maths if you like, b
- Page 378 and 379:
- Futurama, “Fear of a Bot Planet
- Page 380 and 381:
Next, in much the same way that we
- Page 382 and 383:
Chi-square test of categorical asso
- Page 384 and 385:
12.4 Effect size As we discussed ea
- Page 386 and 387:
detailed output, showing you the re
- Page 388 and 389:
chisq.test( salem.tabs ) Pearson’
- Page 390 and 391:
Next, let’s think about what our
- Page 392 and 393:
chisq.test( cardChoices ) Pearson
- Page 394 and 395:
13.1.1 The inference problem that t
- Page 396 and 397:
null hypothesis σ=σ 0 μ=μ 0 alt
- Page 398 and 399:
Let’s also create a variable for
- Page 400 and 401:
null hypothesis σ=?? μ=μ 0 alter
- Page 402 and 403:
pnorm(). And so instead of going th
- Page 404 and 405:
13.3.1 The data Suppose we have 33
- Page 406 and 407:
Grade 66 68 70 72 74 76 78 80 Anast
- Page 408 and 409:
So why not just use these deviation
- Page 410 and 411:
hypothesis and the alternative hypo
- Page 412 and 413:
• Homogeneity of variance (also c
- Page 414 and 415:
estimated effect size (Cohen’s d)
- Page 416 and 417:
Grade 54 56 58 60 Grade for Test 2
- Page 418 and 419:
just gone through is that you need
- Page 420 and 421:
3 student3 test1 71.7 4 student4 te
- Page 422 and 423:
quite similar to the way that mixed
- Page 424 and 425:
) Paired samples t-test Variables:
- Page 426 and 427:
set up to handle data in long form.
- Page 428 and 429:
13.8.2 Cohen’s d from a Student t
- Page 430 and 431:
the practical consequences of your
- Page 432 and 433:
Skewed Data Normal Q−Q Plot Frequ
- Page 434 and 435:
13.10 Testing non-normal data with
- Page 436 and 437:
7 29 31 2 8 56 21 -35 9 38 8 -30 10
- Page 438 and 439:
- 424 -
- Page 440 and 441:
With that as the study design, let
- Page 442 and 443:
the ground up and showing you how y
- Page 444 and 445:
Between−group variation (i.e., di
- Page 446 and 447:
Table 14.1: All of the key quantiti
- Page 448 and 449:
statistics: group outcome group mea
- Page 450 and 451:
gp.means grand.mean dev.from.gran
- Page 452 and 453:
14.3.1 Using the aov() function to
- Page 454 and 455:
drug 2 3.45 1.727 18.6 8.6e-05 ***
- Page 456 and 457:
By rejecting the null hypothesis, w
- Page 458 and 459:
The usual solution to this problem
- Page 460 and 461:
As you can see, the biggest p-value
- Page 462 and 463:
where median k pY q is the median f
- Page 464 and 465:
oneway.test(mood.gain ~ drug, data
- Page 466 and 467:
this in mind, let’s follow the sa
- Page 468 and 469:
No, really. It’s not just that th
- Page 470 and 471:
- 456 -
- Page 472 and 473:
My grumpiness (0−100) 40 50 60 70
- Page 474 and 475:
Regression Line Close to the Data R
- Page 476 and 477:
framework to be able to include mul
- Page 478 and 479:
15.3.2 Formula for the general case
- Page 480 and 481:
15.4.3 The adjusted R 2 value One f
- Page 482 and 483:
I can’t help but notice that the
- Page 484 and 485:
15.6 Testing the significance of a
- Page 486 and 487:
- correction for multiple testing:
- Page 488 and 489:
is that, by converting all the pred
- Page 490 and 491:
The first and simplest kind of resi
- Page 492 and 493:
High leverage Outcome Predictor Fig
- Page 494 and 495:
As a rough guide, Cook’s distance
- Page 496 and 497:
Frequency 0 2 4 6 8 10 12 −10 −
- Page 498 and 499:
Observed Values 40 50 60 70 80 90 5
- Page 500 and 501:
Pearson residuals −10 0 5 10 Pear
- Page 502 and 503:
Standardized residuals 0.0 0.5 1.0
- Page 504 and 505:
15.10 Model selection One fairly ma
- Page 506 and 507:
Okay,sowhatwecanseeisthatremovingth
- Page 508 and 509:
might expect from the amount of sle
- Page 510 and 511:
- 496 -
- Page 512 and 513:
xtabs( ~ drug + therapy, clin.trial
- Page 514 and 515:
Now that we have this notation, it
- Page 516 and 517:
The last part of the ANOVA table is
- Page 518 and 519:
Okay, now let’s calculate the sum
- Page 520 and 521:
Why does that happen? The answer li
- Page 522 and 523:
Crossover interaction Effect for on
- Page 524 and 525:
mood gain 0.0 0.5 1.0 1.5 2.0 CBT n
- Page 526 and 527:
the model with interaction has a to
- Page 528 and 529:
outcome). Moreover, the sum of all
- Page 530 and 531:
Upper 95 Percent Confidence Limits
- Page 532 and 533:
16.4.2 Normality of residuals As wi
- Page 534 and 535:
MS R1 “ SS R1 df R1 Finally, taki
- Page 536 and 537:
16.6.1 Some data To make things con
- Page 538 and 539:
for all intents and purposes. 9 Let
- Page 540 and 541:
eading 28.000 3.873 7.230 0.00079 *
- Page 542 and 543:
value of 43.5 as the expected basel
- Page 544 and 545:
druganxifree 0.267 0.148 1.80 0.094
- Page 546 and 547:
way I did above. Because you’ve c
- Page 548 and 549:
contrasts, in which the intercept t
- Page 550 and 551:
contrasts( clin.trial$drug) [,1] [,
- Page 552 and 553:
diff lwr upr p adj anxifree-placebo
- Page 554 and 555:
papers in psychology without runnin
- Page 556 and 557:
the strategy that is the important
- Page 558 and 559:
mod anova( mod ) Analysis of Varia
- Page 560 and 561:
is meaningless to talk about non-si
- Page 562 and 563:
serious flaws: Type I tests are dep
- Page 564 and 565:
etaSquared( mod, type=2 ) eta.sq et
- Page 566 and 567:
• Understanding the linear model
- Page 569 and 570:
17. Bayesian statistics In our reas
- Page 571 and 572:
P pd|hq, which you can read as “t
- Page 573 and 574:
Umbrella No-umbrella Rainy 0 Dry 0
- Page 575 and 576:
Or, to write the same thing in term
- Page 577 and 578:
theory is true or it is not, and no
- Page 579 and 580:
• Let’s start with option 1. If
- Page 581 and 582:
So how bad is it? The answer is sho
- Page 583 and 584:
1 robot flower 2 human data 3 human
- Page 585 and 586:
Null, independence, a = 1 --- Bayes
- Page 587 and 588:
Poisson sampling plan (i.e., nothin
- Page 589 and 590:
are, before finally getting to the
- Page 591 and 592:
17.6 Bayesian regression Okay, so n
- Page 593 and 594:
to know that you can use the head()
- Page 595 and 596:
[2] Omit dan.sleep : 1.025401e-26
- Page 597 and 598:
By “dividing” the models output
- Page 599 and 600:
psychologist, you might want to che
- Page 601 and 602:
18. Epilogue “Begin at the beginn
- Page 603 and 604:
• Nonlinear regression. When disc
- Page 605 and 606:
analysis uncovers a latent variable
- Page 607 and 608:
fromthepast. Or,moregenerally,newda
- Page 609 and 610:
tool: it is just as applicable to p
- Page 611 and 612:
Author’s note - I’ve mentioned
- Page 613:
No Starch Press. 268 McGrath, R. E.