- 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 17 and 18:
1. Why do we learn statistics? “T
- Page 19 and 20:
And finally, an invalid argument wi
- Page 21 and 22:
Admission rate (both genders) 0 20
- Page 23 and 24:
experiment, and they don’t get an
- Page 25 and 26:
2. A brief introduction to research
- Page 27 and 28:
different ways: the length of time
- Page 29 and 30:
that when I ask 100 people how they
- Page 31 and 32:
Table 2.1: The relationship between
- Page 33 and 34:
2.3 Assessing the reliability of a
- Page 35 and 36:
2.5.1 Experimental research The key
- Page 37 and 38:
things “inside” the study. Let
- Page 39 and 40:
they lack face validity, you’ll f
- Page 41 and 42:
that age is growing at an incredibl
- Page 43 and 44:
then it can be a big problem. 2.7.7
- Page 45 and 46:
2.7.10 Placebo effects The placebo
- Page 47 and 48:
it doesn’t, which one do you thin
- Page 49:
Part II. An introduction to R - 35
- Page 52 and 53:
go out into the real world. It’s
- Page 54 and 55:
download Rstudio. To understand why
- Page 56 and 57:
Most of this text is pretty uninter
- Page 58 and 59:
citation() To cite R in publication
- Page 60 and 61:
Table 3.1: Basic arithmetic operati
- Page 62 and 63:
Division / and Multiplication *, th
- Page 64 and 65:
sales * royalty [1] 2450 As far as
- Page 66 and 67:
x to the power of 0.5”. Personall
- Page 68 and 69:
As you can see, specifying the argu
- Page 70 and 71:
Figure 3.3: If you’ve typed the n
- Page 72 and 73:
sales.by.month sales.by.month [1]
- Page 74 and 75:
profit / days.per.month [1] 0.00000
- Page 76 and 77: not true of R. R is not infinitely
- Page 78 and 79: Table 3.3: Some more logical operat
- Page 80 and 81: In other words, any.sales.this.mont
- Page 82 and 83: and gotten exactly the same result.
- Page 84 and 85: Figure 3.6: The options window in R
- Page 86 and 87: - 72 -
- Page 88 and 89: print( keeper ) [1] 8.539539 So, fr
- Page 90 and 91: to import an SPSS data file into R,
- Page 92 and 93: The output here is telling you that
- Page 94 and 95: Figure 4.3: The Rstudio dialog box
- Page 96 and 97: Figure 4.5: The Rstudio “Environm
- Page 98 and 99: this should be obvious already. But
- Page 100 and 101: Figure 4.6: The “file panel” is
- Page 102 and 103: from this file into my workspace. T
- Page 104 and 105: 2 February 28 100 high 3 March 31 2
- Page 106 and 107: Figure 4.9: The Rstudio window for
- Page 108 and 109: 4.6.1 Special values The first thin
- Page 110 and 111: x y x * y Error in x * y : non-nu
- Page 112 and 113: 4.7.1 Introducing factors Suppose,
- Page 114 and 115: factors in 7.11.2, but for now you
- Page 116 and 117: An alternative method is to use the
- Page 118 and 119: 4.11 Generic functions There’s on
- Page 120 and 121: load (base) R Documentation The R D
- Page 122 and 123: Warning Saved R objects are binary
- Page 124 and 125: - 110 -
- 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.