ch 4

Michael Taylor

2018/08/21

knitr::opts_chunk$set(cache=TRUE)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
facebookData <- read.delim("FacebookNarcissism.dat",
                           header = TRUE)
head(facebookData)
##   id NPQC_R_Total Rating_Type Rating
## 1  1           31  Attractive      2
## 2  1           31 Fashionable      2
## 3  1           31  Glamourous      2
## 4  1           31        Cool      2
## 5  2           37  Attractive      2
## 6  2           37 Fashionable      2
p <- facebookData %>% ggplot(aes(x=NPQC_R_Total, y=Rating)) +
  geom_point(shape = 17)

p1 <- facebookData %>% ggplot(aes(x=NPQC_R_Total, y=Rating)) +
  geom_point(aes(color = Rating_Type), position = "jitter")

grid.arrange(p, p1, nrow = 2)

examData <- read.delim("ExamAnxiety.dat")
head(examData)
##   Code Revise Exam Anxiety Gender
## 1    1      4   40   86.30   Male
## 2    2     11   65   88.72 Female
## 3    3     27   80   70.18   Male
## 4    4     53   80   61.31   Male
## 5    5      4   40   89.52   Male
## 6    6     22   70   60.51 Female
p <- examData %>% ggplot(aes(Anxiety, Exam)) +
  geom_point() +
  geom_smooth() +
  labs(x="Exam Anxiety", 
       y="Exam Performance %")

p1 <- examData %>% ggplot(aes(Anxiety, Exam)) +
  geom_point() +
  geom_smooth(method = "lm", color = "red") +
  labs(x="Exam Anxiety", 
       y="Exam Performance %")

p2 <- examData %>% ggplot(aes(Anxiety, Exam)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x="Exam Anxiety", 
       y="Exam Performance %")

p3 <- examData %>% ggplot(aes(Anxiety, Exam)) +
  geom_point() +
  geom_smooth(method = "lm", alpha = 0.1, fill = "blue") +
  labs(x="Exam Anxiety", 
       y="Exam Performance %")

grid.arrange(p, p1, p2, p3, nrow = 2, ncol = 2)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

p <- examData %>% ggplot(aes(Anxiety, 
                             Exam, 
                             color = Gender)) +
  geom_point() +
  geom_smooth(method = "lm", 
              aes(fill = Gender), 
              alpha = 0.1) +
  labs(x="Exam Anxiety", 
       y="Exam Performance %")

p

p <- facebookData %>% ggplot(aes(x=NPQC_R_Total,
                                 y=Rating,
                                 color=Rating_Type)) +
  geom_smooth(method = "lm", 
              alpha=0.1) +
  geom_point() +
  labs(x="total score on the narcissism questionnaire",
       color="Rating Type")

p

festivalHistogram <- read.delim("DownloadFestival.dat")
head(festivalHistogram)
##   ticknumb gender day1 day2 day3
## 1     2111   Male 2.64 1.35 1.61
## 2     2229 Female 0.97 1.41 0.29
## 3     2338   Male 0.84   NA   NA
## 4     2384 Female 3.03   NA   NA
## 5     2401 Female 0.88 0.08   NA
## 6     2405   Male 0.85   NA   NA
festivalHistogram %>% ggplot(aes(day1))+
  geom_histogram(binwidth = 0.4) +
  labs(x="Hygiene (Day 1 of Festival)",
       y="Frequency")

festivalBoxplot <- festivalHistogram %>% 
  arrange(desc(day1))

head(festivalBoxplot)
##   ticknumb gender  day1 day2 day3
## 1     4158 Female 20.02 2.44   NA
## 2     4016 Female  3.69   NA   NA
## 3     3374   Male  3.58 3.35   NA
## 4     4264   Male  3.44   NA   NA
## 5     3371 Female  3.41   NA   NA
## 6     3338 Female  3.38   NA   NA
festivalBoxplot[1,3] <- 2.02
head(festivalBoxplot)
##   ticknumb gender day1 day2 day3
## 1     4158 Female 2.02 2.44   NA
## 2     4016 Female 3.69   NA   NA
## 3     3374   Male 3.58 3.35   NA
## 4     4264   Male 3.44   NA   NA
## 5     3371 Female 3.41   NA   NA
## 6     3338 Female 3.38   NA   NA
festivalBoxplot %>% 
  ggplot(aes(gender, day1))+
  geom_boxplot() +
  labs(x="Hygiene (Day 1 of Festival)",
       y="Frequency")

scale_this <- function(x){
  (x - mean(x, na.rm=TRUE)) / sd(x, na.rm=TRUE)
}

festivalBoxplotZ <- festivalBoxplot %>% 
  select(1:3) %>%
  mutate(z_score = scale_this(day1) )

festivalBoxplotZ
##     ticknumb gender day1   z_score
## 1       4158 Female 2.02  0.358832
## 2       4016 Female 3.69  2.766772
## 3       3374   Male 3.58  2.608165
## 4       4264   Male 3.44  2.406302
## 5       3371 Female 3.41  2.363046
## 6       3338 Female 3.38  2.319789
## 7       4564 Female 3.38  2.319789
## 8       3828 Female 3.32  2.233277
## 9       4172 Female 3.32  2.233277
## 10      4193   Male 3.32  2.233277
## 11      3646 Female 3.29  2.190020
## 12      4459 Female 3.29  2.190020
## 13      2989 Female 3.26  2.146764
## 14      2601   Male 3.23  2.103507
## 15      3395 Female 3.21  2.074670
## 16      3716 Female 3.21  2.074670
## 17      4590 Female 3.21  2.074670
## 18      3726 Female 3.20  2.060251
## 19      4106 Female 3.20  2.060251
## 20      4569   Male 3.17  2.016995
## 21      3787 Female 3.15  1.988157
## 22      4383 Female 3.15  1.988157
## 23      3116 Female 3.14  1.973738
## 24      3919 Female 3.12  1.944901
## 25      4470   Male 3.11  1.930482
## 26      3599 Female 3.09  1.901644
## 27      3869 Female 3.08  1.887225
## 28      2384 Female 3.03  1.815131
## 29      2478 Female 3.02  1.800712
## 30      3309 Female 3.02  1.800712
## 31      2935 Female 3.00  1.771875
## 32      3052 Female 3.00  1.771875
## 33      2712 Female 2.97  1.728618
## 34      4533 Female 2.97  1.728618
## 35      4553 Female 2.97  1.728618
## 36      2876 Female 2.94  1.685362
## 37      3784 Female 2.94  1.685362
## 38      4220 Female 2.94  1.685362
## 39      3759 Female 2.92  1.656524
## 40      2783   Male 2.91  1.642106
## 41      3133   Male 2.91  1.642106
## 42      4756 Female 2.91  1.642106
## 43      3420 Female 2.90  1.627687
## 44      3311 Female 2.88  1.598849
## 45      3456 Female 2.88  1.598849
## 46      3622 Female 2.88  1.598849
## 47      3788 Female 2.88  1.598849
## 48      3870 Female 2.88  1.598849
## 49      4025   Male 2.88  1.598849
## 50      4333 Female 2.88  1.598849
## 51      4692 Female 2.88  1.598849
## 52      3804 Female 2.87  1.584430
## 53      4010   Male 2.85  1.555593
## 54      3192 Female 2.84  1.541174
## 55      4517 Female 2.84  1.541174
## 56      4165 Female 2.82  1.512336
## 57      4274 Female 2.82  1.512336
## 58      2758   Male 2.81  1.497918
## 59      2899 Female 2.81  1.497918
## 60      3278 Female 2.81  1.497918
## 61      4436 Female 2.81  1.497918
## 62      2521 Female 2.79  1.469080
## 63      3570 Female 2.79  1.469080
## 64      3797 Female 2.78  1.454661
## 65      2566 Female 2.76  1.425824
## 66      2842 Female 2.76  1.425824
## 67      3676   Male 2.76  1.425824
## 68      3996 Female 2.76  1.425824
## 69      3464 Female 2.75  1.411405
## 70      3455   Male 2.73  1.382567
## 71      3606   Male 2.73  1.382567
## 72      3713   Male 2.73  1.382567
## 73      4430 Female 2.73  1.382567
## 74      4482 Female 2.73  1.382567
## 75      3095   Male 2.71  1.353730
## 76      2828 Female 2.70  1.339311
## 77      3363 Female 2.70  1.339311
## 78      3602 Female 2.70  1.339311
## 79      4512 Female 2.70  1.339311
## 80      2959 Female 2.67  1.296054
## 81      2972 Female 2.67  1.296054
## 82      3678   Male 2.67  1.296054
## 83      3882 Female 2.67  1.296054
## 84      4597   Male 2.67  1.296054
## 85      3171 Female 2.66  1.281636
## 86      2111   Male 2.64  1.252798
## 87      2688 Female 2.64  1.252798
## 88      2769 Female 2.64  1.252798
## 89      3413 Female 2.64  1.252798
## 90      3728 Female 2.64  1.252798
## 91      3107 Female 2.63  1.238379
## 92      4238 Female 2.63  1.238379
## 93      4467 Female 2.63  1.238379
## 94      3932 Female 2.62  1.223960
## 95      3056 Female 2.61  1.209542
## 96      4559 Female 2.61  1.209542
## 97      4758 Female 2.61  1.209542
## 98      2794 Female 2.58  1.166285
## 99      2964 Female 2.58  1.166285
## 100     3261   Male 2.58  1.166285
## 101     3416 Female 2.58  1.166285
## 102     3551   Male 2.58  1.166285
## 103     4164 Female 2.58  1.166285
## 104     2604   Male 2.57  1.151866
## 105     4366 Female 2.57  1.151866
## 106     3722 Female 2.56  1.137448
## 107     4109 Female 2.56  1.137448
## 108     3109   Male 2.55  1.123029
## 109     3490 Female 2.55  1.123029
## 110     3653 Female 2.55  1.123029
## 111     3917 Female 2.55  1.123029
## 112     3850 Female 2.53  1.094191
## 113     2933 Female 2.52  1.079772
## 114     3453   Male 2.52  1.079772
## 115     3539 Female 2.52  1.079772
## 116     3729   Male 2.52  1.079772
## 117     4030   Male 2.52  1.079772
## 118     4236 Female 2.52  1.079772
## 119     4262   Male 2.52  1.079772
## 120     4269   Male 2.52  1.079772
## 121     4271 Female 2.52  1.079772
## 122     3501   Male 2.51  1.065354
## 123     3987 Female 2.51  1.065354
## 124     2900 Female 2.50  1.050935
## 125     2948 Female 2.50  1.050935
## 126     3276 Female 2.50  1.050935
## 127     3525 Female 2.50  1.050935
## 128     3620 Female 2.50  1.050935
## 129     3696 Female 2.50  1.050935
## 130     3920   Male 2.50  1.050935
## 131     3924 Female 2.50  1.050935
## 132     4151   Male 2.50  1.050935
## 133     4441 Female 2.50  1.050935
## 134     3449 Female 2.48  1.022097
## 135     2692 Female 2.47  1.007678
## 136     3070   Male 2.47  1.007678
## 137     3392 Female 2.47  1.007678
## 138     4437 Female 2.47  1.007678
## 139     2813 Female 2.46  0.993260
## 140     4153 Female 2.46  0.993260
## 141     2779 Female 2.45  0.978841
## 142     4442 Female 2.45  0.978841
## 143     3093   Male 2.44  0.964422
## 144     3168 Female 2.44  0.964422
## 145     3307   Male 2.44  0.964422
## 146     3314 Female 2.44  0.964422
## 147     3510 Female 2.44  0.964422
## 148     3522 Female 2.44  0.964422
## 149     3952 Female 2.44  0.964422
## 150     4725 Female 2.44  0.964422
## 151     4396 Female 2.42  0.935584
## 152     3017   Male 2.41  0.921166
## 153     3879 Female 2.41  0.921166
## 154     3955   Male 2.41  0.921166
## 155     2883 Female 2.39  0.892328
## 156     3545 Female 2.39  0.892328
## 157     3053 Female 2.38  0.877909
## 158     3836 Female 2.38  0.877909
## 159     4334 Female 2.36  0.849072
## 160     4335 Female 2.36  0.849072
## 161     3483 Female 2.35  0.834653
## 162     3597   Male 2.35  0.834653
## 163     3655 Female 2.35  0.834653
## 164     4297   Male 2.35  0.834653
## 165     4308 Female 2.35  0.834653
## 166     3594   Male 2.34  0.820234
## 167     4382 Female 2.33  0.805815
## 168     2535 Female 2.32  0.791396
## 169     2968   Male 2.32  0.791396
## 170     3049 Female 2.32  0.791396
## 171     3065 Female 2.32  0.791396
## 172     3182 Female 2.32  0.791396
## 173     3370 Female 2.32  0.791396
## 174     3573 Female 2.32  0.791396
## 175     3754 Female 2.32  0.791396
## 176     4393 Female 2.32  0.791396
## 177     4655 Female 2.32  0.791396
## 178     3494 Female 2.31  0.776978
## 179     2565 Female 2.30  0.762559
## 180     3721 Female 2.30  0.762559
## 181     4111 Female 2.30  0.762559
## 182     2490   Male 2.29  0.748140
## 183     2731 Female 2.29  0.748140
## 184     2772   Male 2.29  0.748140
## 185     2811 Female 2.29  0.748140
## 186     2830   Male 2.29  0.748140
## 187     3072 Female 2.29  0.748140
## 188     3916 Female 2.29  0.748140
## 189     4166 Female 2.29  0.748140
## 190     4195   Male 2.29  0.748140
## 191     4266 Female 2.29  0.748140
## 192     4363 Female 2.29  0.748140
## 193     4384 Female 2.29  0.748140
## 194     3922 Female 2.28  0.733721
## 195     3964 Female 2.27  0.719302
## 196     2941 Female 2.26  0.704884
## 197     3277 Female 2.26  0.704884
## 198     3569 Female 2.26  0.704884
## 199     3596 Female 2.26  0.704884
## 200     3698 Female 2.26  0.704884
## 201     4294   Male 2.26  0.704884
## 202     3010 Female 2.24  0.676046
## 203     2775   Male 2.23  0.661627
## 204     2862 Female 2.23  0.661627
## 205     3027   Male 2.23  0.661627
## 206     3137 Female 2.23  0.661627
## 207     3282 Female 2.23  0.661627
## 208     3351 Female 2.23  0.661627
## 209     3480 Female 2.23  0.661627
## 210     3495   Male 2.23  0.661627
## 211     3607 Female 2.23  0.661627
## 212     3782 Female 2.23  0.661627
## 213     3991 Female 2.23  0.661627
## 214     4034 Female 2.23  0.661627
## 215     4295 Female 2.23  0.661627
## 216     4724   Male 2.23  0.661627
## 217     3574   Male 2.22  0.647208
## 218     3014 Female 2.21  0.632790
## 219     3973 Female 2.21  0.632790
## 220     2770 Female 2.20  0.618371
## 221     3035   Male 2.20  0.618371
## 222     3146 Female 2.20  0.618371
## 223     3255   Male 2.20  0.618371
## 224     3796   Male 2.20  0.618371
## 225     3945 Female 2.20  0.618371
## 226     4032 Female 2.20  0.618371
## 227     4198   Male 2.20  0.618371
## 228     4336 Female 2.20  0.618371
## 229     4570 Female 2.20  0.618371
## 230     3308 Female 2.18  0.589533
## 231     4022 Female 2.18  0.589533
## 232     4152 Female 2.18  0.589533
## 233     2509   Male 2.17  0.575114
## 234     2549   Male 2.17  0.575114
## 235     2952   Male 2.17  0.575114
## 236     3031   Male 2.17  0.575114
## 237     3048   Male 2.17  0.575114
## 238     3394 Female 2.17  0.575114
## 239     3512 Female 2.17  0.575114
## 240     3719   Male 2.17  0.575114
## 241     3720 Female 2.17  0.575114
## 242     3880 Female 2.17  0.575114
## 243     3890   Male 2.17  0.575114
## 244     4023 Female 2.17  0.575114
## 245     4313   Male 2.17  0.575114
## 246     4349 Female 2.17  0.575114
## 247     4443 Female 2.17  0.575114
## 248     4394   Male 2.16  0.560696
## 249     3029 Female 2.14  0.531858
## 250     3709 Female 2.14  0.531858
## 251     3856 Female 2.14  0.531858
## 252     3926 Female 2.14  0.531858
## 253     4448 Female 2.14  0.531858
## 254     4571 Female 2.14  0.531858
## 255     4607 Female 2.14  0.531858
## 256     4690 Female 2.14  0.531858
## 257     2894 Female 2.12  0.503020
## 258     3557 Female 2.12  0.503020
## 259     3717 Female 2.11  0.488602
## 260     3723 Female 2.11  0.488602
## 261     4105 Female 2.11  0.488602
## 262     4704 Female 2.11  0.488602
## 263     2686 Female 2.09  0.459764
## 264     3791 Female 2.09  0.459764
## 265     2624 Female 2.08  0.445345
## 266     2664   Male 2.08  0.445345
## 267     2737 Female 2.08  0.445345
## 268     2925 Female 2.08  0.445345
## 269     2983   Male 2.08  0.445345
## 270     3542 Female 2.08  0.445345
## 271     3831 Female 2.08  0.445345
## 272     3837 Female 2.08  0.445345
## 273     4197   Male 2.08  0.445345
## 274     4440   Male 2.08  0.445345
## 275     3798 Female 2.06  0.416508
## 276     2538   Male 2.05  0.402089
## 277     2551 Female 2.05  0.402089
## 278     2669 Female 2.05  0.402089
## 279     2863 Female 2.05  0.402089
## 280     2875 Female 2.05  0.402089
## 281     3106   Male 2.05  0.402089
## 282     3450 Female 2.05  0.402089
## 283     3610   Male 2.05  0.402089
## 284     3718 Female 2.05  0.402089
## 285     3888 Female 2.05  0.402089
## 286     3988 Female 2.05  0.402089
## 287     3990 Female 2.05  0.402089
## 288     4147 Female 2.05  0.402089
## 289     4356 Female 2.05  0.402089
## 290     3009 Female 2.03  0.373251
## 291     2727 Female 2.02  0.358832
## 292     2825 Female 2.02  0.358832
## 293     3372 Female 2.02  0.358832
## 294     3418 Female 2.02  0.358832
## 295     3565 Female 2.02  0.358832
## 296     3727 Female 2.02  0.358832
## 297     3873   Male 2.02  0.358832
## 298     4110 Female 2.02  0.358832
## 299     4114   Male 2.02  0.358832
## 300     4281 Female 2.02  0.358832
## 301     4435 Female 2.02  0.358832
## 302     4488 Female 2.02  0.358832
## 303     4518   Male 2.02  0.358832
## 304     4654 Female 2.02  0.358832
## 305     4695   Male 2.02  0.358832
## 306     2670   Male 2.00  0.329995
## 307     2687   Male 2.00  0.329995
## 308     2773 Female 2.00  0.329995
## 309     3111 Female 2.00  0.329995
## 310     3112   Male 2.00  0.329995
## 311     3253   Male 2.00  0.329995
## 312     3281 Female 2.00  0.329995
## 313     3284   Male 2.00  0.329995
## 314     3368 Female 2.00  0.329995
## 315     3419   Male 2.00  0.329995
## 316     3521 Female 2.00  0.329995
## 317     3576   Male 2.00  0.329995
## 318     3631 Female 2.00  0.329995
## 319     3913 Female 2.00  0.329995
## 320     4090   Male 2.00  0.329995
## 321     4218   Male 2.00  0.329995
## 322     4237 Female 2.00  0.329995
## 323     4291 Female 2.00  0.329995
## 324     4354   Male 2.00  0.329995
## 325     3536 Female 1.97  0.286738
## 326     3986   Male 1.97  0.286738
## 327     4014   Male 1.97  0.286738
## 328     4079   Male 1.97  0.286738
## 329     4101 Female 1.97  0.286738
## 330     4514 Female 1.97  0.286738
## 331     4388 Female 1.96  0.272320
## 332     2612   Male 1.94  0.243482
## 333     2807 Female 1.94  0.243482
## 334     2890   Male 1.94  0.243482
## 335     2940   Male 1.94  0.243482
## 336     2988 Female 1.94  0.243482
## 337     3016   Male 1.94  0.243482
## 338     3132 Female 1.94  0.243482
## 339     3467 Female 1.94  0.243482
## 340     3859   Male 1.94  0.243482
## 341     3875   Male 1.94  0.243482
## 342     3883   Male 1.94  0.243482
## 343     3954 Female 1.94  0.243482
## 344     4310 Female 1.94  0.243482
## 345     4358   Male 1.94  0.243482
## 346     3069   Male 1.93  0.229063
## 347     3458 Female 1.93  0.229063
## 348     4386 Female 1.93  0.229063
## 349     4428 Female 1.93  0.229063
## 350     2533 Female 1.91  0.200226
## 351     2616   Male 1.91  0.200226
## 352     2633 Female 1.91  0.200226
## 353     2977 Female 1.91  0.200226
## 354     3348 Female 1.91  0.200226
## 355     3672 Female 1.91  0.200226
## 356     3714   Male 1.91  0.200226
## 357     3871 Female 1.91  0.200226
## 358     4092 Female 1.91  0.200226
## 359     4256   Male 1.91  0.200226
## 360     4314 Female 1.91  0.200226
## 361     3518   Male 1.90  0.185807
## 362     4012 Female 1.90  0.185807
## 363     4268   Male 1.90  0.185807
## 364     2681   Male 1.88  0.156969
## 365     2788   Male 1.88  0.156969
## 366     2976 Female 1.88  0.156969
## 367     3454 Female 1.88  0.156969
## 368     3966   Male 1.88  0.156969
## 369     2901   Male 1.87  0.142550
## 370     3279 Female 1.87  0.142550
## 371     2791 Female 1.85  0.113713
## 372     2839   Male 1.85  0.113713
## 373     2982   Male 1.85  0.113713
## 374     3129   Male 1.85  0.113713
## 375     3135 Female 1.85  0.113713
## 376     3341 Female 1.85  0.113713
## 377     3626   Male 1.85  0.113713
## 378     3838   Male 1.85  0.113713
## 379     3972   Male 1.85  0.113713
## 380     4194   Male 1.85  0.113713
## 381     4263 Female 1.85  0.113713
## 382     4301 Female 1.85  0.113713
## 383     4305   Male 1.85  0.113713
## 384     4598   Male 1.85  0.113713
## 385     2962 Female 1.84  0.099294
## 386     3659   Male 1.84  0.099294
## 387     2953   Male 1.82  0.070456
## 388     2957   Male 1.82  0.070456
## 389     3147   Male 1.82  0.070456
## 390     3393   Male 1.82  0.070456
## 391     3423   Male 1.82  0.070456
## 392     3526   Male 1.82  0.070456
## 393     3736   Male 1.82  0.070456
## 394     3951 Female 1.82  0.070456
## 395     4171 Female 1.82  0.070456
## 396     4387 Female 1.82  0.070456
## 397     4479 Female 1.82  0.070456
## 398     4699 Female 1.82  0.070456
## 399     4249 Female 1.81  0.056038
## 400     4359 Female 1.81  0.056038
## 401     2698 Female 1.79  0.027200
## 402     2728   Male 1.79  0.027200
## 403     2985 Female 1.79  0.027200
## 404     3248   Male 1.79  0.027200
## 405     3251 Female 1.79  0.027200
## 406     3921   Male 1.79  0.027200
## 407     3929   Male 1.79  0.027200
## 408     3965   Male 1.79  0.027200
## 409     3994   Male 1.79  0.027200
## 410     4516   Male 1.79  0.027200
## 411     3567   Male 1.78  0.012781
## 412     4486   Male 1.78  0.012781
## 413     3321 Female 1.77 -0.001638
## 414     2515 Female 1.76 -0.016056
## 415     2735 Female 1.76 -0.016056
## 416     3992 Female 1.76 -0.016056
## 417     4235   Male 1.76 -0.016056
## 418     4267 Female 1.76 -0.016056
## 419     2924 Female 1.75 -0.030475
## 420     2611 Female 1.73 -0.059313
## 421     2752   Male 1.73 -0.059313
## 422     2966   Male 1.73 -0.059313
## 423     3096 Female 1.73 -0.059313
## 424     3613 Female 1.73 -0.059313
## 425     3715   Male 1.73 -0.059313
## 426     4033   Male 1.73 -0.059313
## 427     4155 Female 1.73 -0.059313
## 428     4357 Female 1.73 -0.059313
## 429     4563 Female 1.73 -0.059313
## 430     4698 Female 1.73 -0.059313
## 431     3656 Female 1.71 -0.088150
## 432     3136   Male 1.70 -0.102569
## 433     3245 Female 1.70 -0.102569
## 434     3598 Female 1.70 -0.102569
## 435     3724   Male 1.70 -0.102569
## 436     4148 Female 1.70 -0.102569
## 437     4444   Male 1.70 -0.102569
## 438     4468 Female 1.70 -0.102569
## 439     3712   Male 1.69 -0.116988
## 440     3379 Female 1.68 -0.131407
## 441     2663   Male 1.67 -0.145826
## 442     2814 Female 1.67 -0.145826
## 443     3032 Female 1.67 -0.145826
## 444     3391 Female 1.67 -0.145826
## 445     3457 Female 1.67 -0.145826
## 446     3460 Female 1.67 -0.145826
## 447     3519 Female 1.67 -0.145826
## 448     3997 Female 1.67 -0.145826
## 449     4162 Female 1.67 -0.145826
## 450     4219 Female 1.67 -0.145826
## 451     4245 Female 1.67 -0.145826
## 452     2562 Female 1.66 -0.160245
## 453     2732 Female 1.66 -0.160245
## 454     2956 Female 1.66 -0.160245
## 455     2975 Female 1.66 -0.160245
## 456     2709 Female 1.64 -0.189082
## 457     2857   Male 1.64 -0.189082
## 458     2978 Female 1.64 -0.189082
## 459     3028 Female 1.64 -0.189082
## 460     3051   Male 1.64 -0.189082
## 461     3291   Male 1.64 -0.189082
## 462     3292   Male 1.64 -0.189082
## 463     3313 Female 1.64 -0.189082
## 464     3603 Female 1.64 -0.189082
## 465     3697   Male 1.64 -0.189082
## 466     4157   Male 1.64 -0.189082
## 467     4168 Female 1.64 -0.189082
## 468     4519   Male 1.64 -0.189082
## 469     2558 Female 1.61 -0.232339
## 470     2829 Female 1.61 -0.232339
## 471     3316 Female 1.61 -0.232339
## 472     3730   Male 1.61 -0.232339
## 473     3785   Male 1.61 -0.232339
## 474     3794   Male 1.61 -0.232339
## 475     4149   Male 1.61 -0.232339
## 476     3054 Female 1.60 -0.246757
## 477     3369   Male 1.60 -0.246757
## 478     3397 Female 1.60 -0.246757
## 479     2812   Male 1.59 -0.261176
## 480     2676 Female 1.58 -0.275595
## 481     3055 Female 1.58 -0.275595
## 482     3092 Female 1.58 -0.275595
## 483     3097   Male 1.58 -0.275595
## 484     3365   Male 1.58 -0.275595
## 485     3477   Male 1.58 -0.275595
## 486     3593 Female 1.58 -0.275595
## 487     3846   Male 1.58 -0.275595
## 488     3944   Male 1.58 -0.275595
## 489     4024 Female 1.58 -0.275595
## 490     4161 Female 1.58 -0.275595
## 491     4240   Male 1.58 -0.275595
## 492     4361   Male 1.58 -0.275595
## 493     4370 Female 1.58 -0.275595
## 494     4481 Female 1.58 -0.275595
## 495     2859   Male 1.57 -0.290014
## 496     3064   Male 1.57 -0.290014
## 497     2467 Female 1.56 -0.304433
## 498     4456   Male 1.56 -0.304433
## 499     3493   Male 1.55 -0.318851
## 500     3645 Female 1.55 -0.318851
## 501     3677   Male 1.55 -0.318851
## 502     4221 Female 1.55 -0.318851
## 503     4265 Female 1.55 -0.318851
## 504     4311   Male 1.55 -0.318851
## 505     4398   Male 1.55 -0.318851
## 506     3312   Male 1.54 -0.333270
## 507     3431   Male 1.53 -0.347689
## 508     2675   Male 1.52 -0.362108
## 509     2759 Female 1.52 -0.362108
## 510     3172   Male 1.52 -0.362108
## 511     3236 Female 1.52 -0.362108
## 512     3306 Female 1.52 -0.362108
## 513     3377 Female 1.52 -0.362108
## 514     3588   Male 1.52 -0.362108
## 515     3600 Female 1.52 -0.362108
## 516     4226 Female 1.52 -0.362108
## 517     4353 Female 1.52 -0.362108
## 518     4454   Male 1.52 -0.362108
## 519     3273   Male 1.51 -0.376527
## 520     4446   Male 1.51 -0.376527
## 521     2529   Male 1.50 -0.390945
## 522     2644   Male 1.50 -0.390945
## 523     2736 Female 1.50 -0.390945
## 524     2827   Male 1.50 -0.390945
## 525     3008 Female 1.50 -0.390945
## 526     3098   Male 1.50 -0.390945
## 527     3328 Female 1.50 -0.390945
## 528     3375   Male 1.50 -0.390945
## 529     3469 Female 1.50 -0.390945
## 530     3731   Male 1.50 -0.390945
## 531     3753 Female 1.50 -0.390945
## 532     4015 Female 1.50 -0.390945
## 533     4154 Female 1.50 -0.390945
## 534     4485 Female 1.50 -0.390945
## 535     3635 Female 1.48 -0.419783
## 536     2768   Male 1.47 -0.434202
## 537     2961 Female 1.47 -0.434202
## 538     3139 Female 1.47 -0.434202
## 539     3250   Male 1.47 -0.434202
## 540     3275 Female 1.47 -0.434202
## 541     3352 Female 1.47 -0.434202
## 542     3380   Male 1.47 -0.434202
## 543     3390 Female 1.47 -0.434202
## 544     3647   Male 1.47 -0.434202
## 545     3652   Male 1.47 -0.434202
## 546     3793   Male 1.47 -0.434202
## 547     3947   Male 1.47 -0.434202
## 548     4196 Female 1.47 -0.434202
## 549     4247 Female 1.47 -0.434202
## 550     4259   Male 1.47 -0.434202
## 551     4555   Male 1.47 -0.434202
## 552     4759 Female 1.47 -0.434202
## 553     3546   Male 1.45 -0.463039
## 554     2568 Female 1.44 -0.477458
## 555     2726 Female 1.44 -0.477458
## 556     2922 Female 1.44 -0.477458
## 557     2954 Female 1.44 -0.477458
## 558     3057   Male 1.44 -0.477458
## 559     3118   Male 1.44 -0.477458
## 560     3367 Female 1.44 -0.477458
## 561     3523   Male 1.44 -0.477458
## 562     3621   Male 1.44 -0.477458
## 563     3949   Male 1.44 -0.477458
## 564     4156   Male 1.44 -0.477458
## 565     2642 Female 1.42 -0.506296
## 566     3148 Female 1.42 -0.506296
## 567     3340 Female 1.42 -0.506296
## 568     3411 Female 1.42 -0.506296
## 569     2514   Male 1.41 -0.520715
## 570     2936 Female 1.41 -0.520715
## 571     2942   Male 1.41 -0.520715
## 572     3131 Female 1.41 -0.520715
## 573     3247   Male 1.41 -0.520715
## 574     3290 Female 1.41 -0.520715
## 575     3764   Male 1.41 -0.520715
## 576     3872   Male 1.41 -0.520715
## 577     3925 Female 1.41 -0.520715
## 578     3948 Female 1.41 -0.520715
## 579     4509 Female 1.41 -0.520715
## 580     2520   Male 1.38 -0.563971
## 581     2806   Male 1.38 -0.563971
## 582     3257 Female 1.38 -0.563971
## 583     3258 Female 1.38 -0.563971
## 584     3667 Female 1.38 -0.563971
## 585     3840   Male 1.38 -0.563971
## 586     4419 Female 1.38 -0.563971
## 587     2898 Female 1.35 -0.607227
## 588     3173 Female 1.35 -0.607227
## 589     3769   Male 1.35 -0.607227
## 590     3858   Male 1.35 -0.607227
## 591     4223 Female 1.35 -0.607227
## 592     4309   Male 1.35 -0.607227
## 593     4439   Male 1.35 -0.607227
## 594     4601 Female 1.35 -0.607227
## 595     4693   Male 1.35 -0.607227
## 596     2730   Male 1.34 -0.621646
## 597     2979   Male 1.34 -0.621646
## 598     3855 Female 1.34 -0.621646
## 599     2920   Male 1.33 -0.636065
## 600     2685 Female 1.32 -0.650484
## 601     2710   Male 1.32 -0.650484
## 602     3114 Female 1.32 -0.650484
## 603     3350 Female 1.32 -0.650484
## 604     3783 Female 1.32 -0.650484
## 605     3792 Female 1.32 -0.650484
## 606     4355   Male 1.32 -0.650484
## 607     4389 Female 1.32 -0.650484
## 608     4095 Female 1.31 -0.664903
## 609     3180 Female 1.29 -0.693740
## 610     3315 Female 1.29 -0.693740
## 611     3989 Female 1.29 -0.693740
## 612     4284 Female 1.29 -0.693740
## 613     4312 Female 1.29 -0.693740
## 614     4582   Male 1.29 -0.693740
## 615     2677   Male 1.28 -0.708159
## 616     4760   Male 1.28 -0.708159
## 617     2921 Female 1.26 -0.736997
## 618     2958   Male 1.26 -0.736997
## 619     3296   Male 1.26 -0.736997
## 620     3378   Male 1.26 -0.736997
## 621     4285   Male 1.26 -0.736997
## 622     4765 Female 1.26 -0.736997
## 623     4611   Male 1.24 -0.765834
## 624     2967   Male 1.23 -0.780253
## 625     3725 Female 1.23 -0.780253
## 626     3849   Male 1.23 -0.780253
## 627     3950 Female 1.23 -0.780253
## 628     4013   Male 1.23 -0.780253
## 629     4306   Male 1.23 -0.780253
## 630     4447 Female 1.23 -0.780253
## 631     4511 Female 1.23 -0.780253
## 632     4710 Female 1.23 -0.780253
## 633     3627 Female 1.21 -0.809091
## 634     2780   Male 1.20 -0.823509
## 635     2938   Male 1.20 -0.823509
## 636     3461   Male 1.20 -0.823509
## 637     4089   Male 1.20 -0.823509
## 638     4159 Female 1.20 -0.823509
## 639     2858   Male 1.17 -0.866766
## 640     3019 Female 1.17 -0.866766
## 641     3634 Female 1.17 -0.866766
## 642     4404 Female 1.17 -0.866766
## 643     4740   Male 1.17 -0.866766
## 644     3734   Male 1.15 -0.895603
## 645     2784 Female 1.14 -0.910022
## 646     2990   Male 1.14 -0.910022
## 647     3068 Female 1.14 -0.910022
## 648     3412   Male 1.14 -0.910022
## 649     3826   Male 1.14 -0.910022
## 650     3844   Male 1.14 -0.910022
## 651     3946 Female 1.14 -0.910022
## 652     4167 Female 1.14 -0.910022
## 653     4392 Female 1.14 -0.910022
## 654     4397 Female 1.14 -0.910022
## 655     4452   Male 1.14 -0.910022
## 656     4666   Male 1.14 -0.910022
## 657     2504 Female 1.11 -0.953279
## 658     2895 Female 1.11 -0.953279
## 659     3013 Female 1.11 -0.953279
## 660     3138   Male 1.11 -0.953279
## 661     3660 Female 1.11 -0.953279
## 662     2937 Female 1.08 -0.996535
## 663     3249   Male 1.08 -0.996535
## 664     3376   Male 1.08 -0.996535
## 665     3503   Male 1.08 -0.996535
## 666     3711   Male 1.08 -0.996535
## 667     4525 Female 1.08 -0.996535
## 668     4663   Male 1.08 -0.996535
## 669     2586 Female 1.06 -1.025373
## 670     3609 Female 1.06 -1.025373
## 671     3628   Male 1.06 -1.025373
## 672     4199 Female 1.06 -1.025373
## 673     4257   Male 1.06 -1.025373
## 674     2756 Female 1.05 -1.039791
## 675     3100 Female 1.05 -1.039791
## 676     3329   Male 1.05 -1.039791
## 677     3993   Male 1.05 -1.039791
## 678     4410 Female 1.05 -1.039791
## 679     3680 Female 1.03 -1.068629
## 680     2974 Female 1.02 -1.083048
## 681     2984   Male 1.02 -1.083048
## 682     3310 Female 1.02 -1.083048
## 683     3930   Male 1.02 -1.083048
## 684     3995 Female 1.02 -1.083048
## 685     4391 Female 1.02 -1.083048
## 686     2748 Female 1.00 -1.111885
## 687     3033 Female 1.00 -1.111885
## 688     3073 Female 1.00 -1.111885
## 689     3366   Male 1.00 -1.111885
## 690     3586   Male 1.00 -1.111885
## 691     3649   Male 1.00 -1.111885
## 692     3786 Female 1.00 -1.111885
## 693     3857 Female 1.00 -1.111885
## 694     4163 Female 1.00 -1.111885
## 695     4225   Male 1.00 -1.111885
## 696     4234   Male 1.00 -1.111885
## 697     4405 Female 1.00 -1.111885
## 698     4694   Male 1.00 -1.111885
## 699     2229 Female 0.97 -1.155142
## 700     2602   Male 0.97 -1.155142
## 701     2831 Female 0.97 -1.155142
## 702     2897 Female 0.97 -1.155142
## 703     3202   Male 0.97 -1.155142
## 704     4216 Female 0.97 -1.155142
## 705     4554 Female 0.97 -1.155142
## 706     3648   Male 0.96 -1.169561
## 707     4453 Female 0.96 -1.169561
## 708     2789   Male 0.94 -1.198398
## 709     3246 Female 0.94 -1.198398
## 710     3256 Female 0.94 -1.198398
## 711     3670 Female 0.94 -1.198398
## 712     4287 Female 0.94 -1.198398
## 713     4552 Female 0.94 -1.198398
## 714     3614 Female 0.93 -1.212817
## 715     3267 Female 0.91 -1.241655
## 716     3325   Male 0.91 -1.241655
## 717     4360   Male 0.90 -1.256073
## 718     4510   Male 0.90 -1.256073
## 719     2401 Female 0.88 -1.284911
## 720     3018   Male 0.88 -1.284911
## 721     3034 Female 0.88 -1.284911
## 722     3669   Male 0.88 -1.284911
## 723     3942   Male 0.88 -1.284911
## 724     4222   Male 0.88 -1.284911
## 725     2405   Male 0.85 -1.328167
## 726     2689   Male 0.85 -1.328167
## 727     2932   Male 0.85 -1.328167
## 728     3326 Female 0.85 -1.328167
## 729     3327   Male 0.85 -1.328167
## 730     2338   Male 0.84 -1.342586
## 731     4515   Male 0.84 -1.342586
## 732     3094 Female 0.83 -1.357005
## 733     2510 Female 0.82 -1.371424
## 734     3349   Male 0.82 -1.371424
## 735     3524   Male 0.82 -1.371424
## 736     3605   Male 0.82 -1.371424
## 737     3918 Female 0.82 -1.371424
## 738     4385 Female 0.82 -1.371424
## 739     4093   Male 0.81 -1.385843
## 740     3595 Female 0.79 -1.414680
## 741     3190   Male 0.78 -1.429099
## 742     3254 Female 0.76 -1.457937
## 743     3874 Female 0.76 -1.457937
## 744     3927   Male 0.76 -1.457937
## 745     3568   Male 0.73 -1.501193
## 746     3779 Female 0.73 -1.501193
## 747     3854 Female 0.73 -1.501193
## 748     4150   Male 0.73 -1.501193
## 749     4239 Female 0.73 -1.501193
## 750     4292 Female 0.73 -1.501193
## 751     2799   Male 0.70 -1.544449
## 752     3577 Female 0.70 -1.544449
## 753     4445   Male 0.70 -1.544449
## 754     3500 Female 0.67 -1.587706
## 755     3625 Female 0.67 -1.587706
## 756     3851   Male 0.67 -1.587706
## 757     3876   Male 0.67 -1.587706
## 758     4302   Male 0.67 -1.587706
## 759     4507   Male 0.67 -1.587706
## 760     3373   Male 0.64 -1.630962
## 761     4696 Female 0.64 -1.630962
## 762     4711   Male 0.64 -1.630962
## 763     3912   Male 0.62 -1.659800
## 764     2796 Female 0.61 -1.674219
## 765     3629   Male 0.61 -1.674219
## 766     3778   Male 0.61 -1.674219
## 767     4224 Female 0.61 -1.674219
## 768     4744 Female 0.61 -1.674219
## 769     2734 Female 0.60 -1.688637
## 770     3468 Female 0.59 -1.703056
## 771     3575   Male 0.58 -1.717475
## 772     3923   Male 0.58 -1.717475
## 773     4241 Female 0.58 -1.717475
## 774     2771   Male 0.55 -1.760731
## 775     2923   Male 0.55 -1.760731
## 776     3407 Female 0.55 -1.760731
## 777     4298 Female 0.55 -1.760731
## 778     3572   Male 0.52 -1.803988
## 779     3710   Male 0.52 -1.803988
## 780     4351   Male 0.52 -1.803988
## 781     4455   Male 0.52 -1.803988
## 782     4749 Female 0.52 -1.803988
## 783     3262   Male 0.51 -1.818407
## 784     3429 Female 0.50 -1.832825
## 785     3860   Male 0.50 -1.832825
## 786     4017 Female 0.50 -1.832825
## 787     2609 Female 0.47 -1.876082
## 788     3799 Female 0.47 -1.876082
## 789     3909   Male 0.47 -1.876082
## 790     3914   Male 0.45 -1.904919
## 791     4464   Male 0.45 -1.904919
## 792     3654 Female 0.44 -1.919338
## 793     3571   Male 0.43 -1.933757
## 794     4096 Female 0.38 -2.005851
## 795     4104 Female 0.38 -2.005851
## 796     4160   Male 0.38 -2.005851
## 797     3601 Female 0.35 -2.049107
## 798     3260   Male 0.32 -2.092364
## 799     3264 Female 0.32 -2.092364
## 800     3398 Female 0.32 -2.092364
## 801     4352   Male 0.32 -2.092364
## 802     3587   Male 0.30 -2.121202
## 803     4697   Male 0.29 -2.135620
## 804     2606 Female 0.26 -2.178877
## 805     3511 Female 0.23 -2.222133
## 806     4011 Female 0.23 -2.222133
## 807     2662 Female 0.11 -2.395159
## 808     3030   Male 0.11 -2.395159
## 809     3540 Female 0.05 -2.481672
## 810     4107 Female 0.02 -2.524928
for (i in c(1.96, 2.58, 3.29)) {
  festivalBoxplot %>% 
    select(1:2,4) %>% na.omit() %>% 
    mutate(z_score = scale_this(day2)) %>%
    summarise(mean_z_score = 
              paste("Absolute z-score greater than", 
                    i, 
                    "=", 
                    mean(abs(z_score) > i) * 100,
                    "%", 
                    sep = " " )
              ) %>% 
    print()
}
##                                              mean_z_score
## 1 Absolute z-score greater than 1.96 = 6.81818181818182 %
##                                              mean_z_score
## 1 Absolute z-score greater than 2.58 = 2.27272727272727 %
##                                               mean_z_score
## 1 Absolute z-score greater than 3.29 = 0.757575757575758 %
festivalBoxplot %>% 
  filter(!is.na(day2)) %>% 
  ggplot(aes(gender, day2))+
  geom_boxplot() +
  labs(x="Hygiene (Day 2 of Festival)",
       y="Frequency")

festivalBoxplot %>% 
  filter(!is.na(day3)) %>% 
  ggplot(aes(gender, day3)) +
  geom_boxplot() +
  labs(x="Hygiene (Day 3 of Festival)",
       y="Frequency")

Desity plots

festivalHistogram[festivalHistogram$day1==20.02,3] <- 2.02
festivalHistogram %>%
  ggplot(aes(day1)) +
  geom_density()

(chickFlick <- read.delim("ChickFlick.dat", header = TRUE))
##    gender                 film arousal
## 1    Male Bridget Jones' Diary      22
## 2    Male Bridget Jones' Diary      13
## 3    Male Bridget Jones' Diary      16
## 4    Male Bridget Jones' Diary      10
## 5    Male Bridget Jones' Diary      18
## 6    Male Bridget Jones' Diary      24
## 7    Male Bridget Jones' Diary      13
## 8    Male Bridget Jones' Diary      14
## 9    Male Bridget Jones' Diary      19
## 10   Male Bridget Jones' Diary      23
## 11   Male              Memento      37
## 12   Male              Memento      20
## 13   Male              Memento      16
## 14   Male              Memento      28
## 15   Male              Memento      27
## 16   Male              Memento      18
## 17   Male              Memento      32
## 18   Male              Memento      24
## 19   Male              Memento      21
## 20   Male              Memento      35
## 21 Female Bridget Jones' Diary       3
## 22 Female Bridget Jones' Diary      15
## 23 Female Bridget Jones' Diary       5
## 24 Female Bridget Jones' Diary      16
## 25 Female Bridget Jones' Diary      13
## 26 Female Bridget Jones' Diary      20
## 27 Female Bridget Jones' Diary      11
## 28 Female Bridget Jones' Diary      19
## 29 Female Bridget Jones' Diary      15
## 30 Female Bridget Jones' Diary       7
## 31 Female              Memento      30
## 32 Female              Memento      25
## 33 Female              Memento      31
## 34 Female              Memento      36
## 35 Female              Memento      23
## 36 Female              Memento      14
## 37 Female              Memento      21
## 38 Female              Memento      31
## 39 Female              Memento      22
## 40 Female              Memento      14
p <- ggplot(chickFlick, aes(film, arousal))
p + stat_summary(fun.y = mean, 
                 geom = "bar", 
                 fill = "white", 
                 color = "Black")

p + stat_summary(fun.data = mean_cl_normal, 
                 geom = "pointrange",
                 color = "blue") +
  labs(x = "Film", y = "Mean Arousal")

p + stat_summary(fun.y = mean, 
                 geom = "bar", 
                 fill = "white", 
                 color = "Black") +
  stat_summary(fun.data = mean_cl_normal, 
                 geom = "pointrange",
                 color = "blue") +
  labs(x = "Film", y = "Mean Arousal")

p + stat_summary(fun.y = mean, 
                 geom = "bar", 
                 fill = "white", 
                 color = "black") +
  stat_summary(fun.data = mean_cl_normal, 
                 geom = "errorbar",
                 color = "red") +
  labs(x = "Film", y = "Mean Arousal")

p <- ggplot(chickFlick, aes(film, arousal, fill=gender))
p + stat_summary(fun.y = mean, 
               geom = "bar", 
               position="dodge")+
  stat_summary(fun.data = mean_cl_normal, 
               geom = "errorbar", 
               position = position_dodge(width=0.90), 
               width = 0.2)+
  labs(x = "Film", y = "Mean Arousal", fill = "Gender")

p <- ggplot(chickFlick, aes(film, arousal, fill=gender))
p + stat_summary(fun.y = mean, geom = "bar")+
  stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 0.2)+
  facet_wrap( ~ gender)+
  labs(x = "Film", y = "Mean Arousal")+
  theme(legend.position = "none")

(hiccupsData <- read.delim("Hiccups.dat"))
##    Baseline Tongue Carotid Rectum
## 1        15      9       7      2
## 2        13     18       7      4
## 3         9     17       5      4
## 4         7     15      10      5
## 5        11     18       7      4
## 6        14      8      10      3
## 7        20      3       7      3
## 8         9     16      12      3
## 9        17     10       9      4
## 10       19     10       8      4
## 11        3     14      11      4
## 12       13     22       6      4
## 13       20      4      13      4
## 14       14     16      11      2
## 15       13     12       8      3
names(hiccupsData)
## [1] "Baseline" "Tongue"   "Carotid"  "Rectum"
(hiccups <- stack(hiccupsData))
##    values      ind
## 1      15 Baseline
## 2      13 Baseline
## 3       9 Baseline
## 4       7 Baseline
## 5      11 Baseline
## 6      14 Baseline
## 7      20 Baseline
## 8       9 Baseline
## 9      17 Baseline
## 10     19 Baseline
## 11      3 Baseline
## 12     13 Baseline
## 13     20 Baseline
## 14     14 Baseline
## 15     13 Baseline
## 16      9   Tongue
## 17     18   Tongue
## 18     17   Tongue
## 19     15   Tongue
## 20     18   Tongue
## 21      8   Tongue
## 22      3   Tongue
## 23     16   Tongue
## 24     10   Tongue
## 25     10   Tongue
## 26     14   Tongue
## 27     22   Tongue
## 28      4   Tongue
## 29     16   Tongue
## 30     12   Tongue
## 31      7  Carotid
## 32      7  Carotid
## 33      5  Carotid
## 34     10  Carotid
## 35      7  Carotid
## 36     10  Carotid
## 37      7  Carotid
## 38     12  Carotid
## 39      9  Carotid
## 40      8  Carotid
## 41     11  Carotid
## 42      6  Carotid
## 43     13  Carotid
## 44     11  Carotid
## 45      8  Carotid
## 46      2   Rectum
## 47      4   Rectum
## 48      4   Rectum
## 49      5   Rectum
## 50      4   Rectum
## 51      3   Rectum
## 52      3   Rectum
## 53      3   Rectum
## 54      4   Rectum
## 55      4   Rectum
## 56      4   Rectum
## 57      4   Rectum
## 58      4   Rectum
## 59      2   Rectum
## 60      3   Rectum
names(hiccups) <- c("Hiccup", "Intervention")
hiccups
##    Hiccup Intervention
## 1      15     Baseline
## 2      13     Baseline
## 3       9     Baseline
## 4       7     Baseline
## 5      11     Baseline
## 6      14     Baseline
## 7      20     Baseline
## 8       9     Baseline
## 9      17     Baseline
## 10     19     Baseline
## 11      3     Baseline
## 12     13     Baseline
## 13     20     Baseline
## 14     14     Baseline
## 15     13     Baseline
## 16      9       Tongue
## 17     18       Tongue
## 18     17       Tongue
## 19     15       Tongue
## 20     18       Tongue
## 21      8       Tongue
## 22      3       Tongue
## 23     16       Tongue
## 24     10       Tongue
## 25     10       Tongue
## 26     14       Tongue
## 27     22       Tongue
## 28      4       Tongue
## 29     16       Tongue
## 30     12       Tongue
## 31      7      Carotid
## 32      7      Carotid
## 33      5      Carotid
## 34     10      Carotid
## 35      7      Carotid
## 36     10      Carotid
## 37      7      Carotid
## 38     12      Carotid
## 39      9      Carotid
## 40      8      Carotid
## 41     11      Carotid
## 42      6      Carotid
## 43     13      Carotid
## 44     11      Carotid
## 45      8      Carotid
## 46      2       Rectum
## 47      4       Rectum
## 48      4       Rectum
## 49      5       Rectum
## 50      4       Rectum
## 51      3       Rectum
## 52      3       Rectum
## 53      3       Rectum
## 54      4       Rectum
## 55      4       Rectum
## 56      4       Rectum
## 57      4       Rectum
## 58      4       Rectum
## 59      2       Rectum
## 60      3       Rectum
str(hiccups)
## 'data.frame':    60 obs. of  2 variables:
##  $ Hiccup      : int  15 13 9 7 11 14 20 9 17 19 ...
##  $ Intervention: Factor w/ 4 levels "Baseline","Tongue",..: 1 1 1 1 1 1 1 1 1 1 ...
levels(hiccups$Intervention)
## [1] "Baseline" "Tongue"   "Carotid"  "Rectum"
p <- hiccups %>% ggplot(aes(Intervention, Hiccup))
p + stat_summary(fun.y = mean, geom = 'point')

p + stat_summary(fun.y = mean, geom = 'point') +
  stat_summary(fun.y = mean, geom = "line", aes(group = 1))

p + stat_summary(fun.y = mean, geom = 'point') +
  stat_summary(fun.y = mean, 
               geom = "line", aes(group = 1),
               color="blue",
               linetype = "dashed")

p + 
  stat_summary(fun.y = mean, geom = 'point') +
  stat_summary(fun.y = mean, 
               geom = "line", aes(group = 1),
               color="blue",
               linetype = "dashed")+
  stat_summary(fun.data = mean_cl_boot, 
               geom = "errorbar",
               width= 0.2)+
  labs(x = "Intervention", y = "Mean Number of Hiccups")

(textData <- read.delim("TextMessages.dat"))
##             Group Baseline Six_months
## 1  Text Messagers       52         32
## 2  Text Messagers       68         48
## 3  Text Messagers       85         62
## 4  Text Messagers       47         16
## 5  Text Messagers       73         63
## 6  Text Messagers       57         53
## 7  Text Messagers       63         59
## 8  Text Messagers       50         58
## 9  Text Messagers       66         59
## 10 Text Messagers       60         57
## 11 Text Messagers       51         60
## 12 Text Messagers       72         56
## 13 Text Messagers       77         61
## 14 Text Messagers       57         52
## 15 Text Messagers       79          9
## 16 Text Messagers       75         76
## 17 Text Messagers       53         38
## 18 Text Messagers       72         63
## 19 Text Messagers       62         53
## 20 Text Messagers       71         61
## 21 Text Messagers       53         50
## 22 Text Messagers       64         78
## 23 Text Messagers       79         33
## 24 Text Messagers       75         68
## 25 Text Messagers       60         59
## 26       Controls       65         62
## 27       Controls       57         50
## 28       Controls       66         62
## 29       Controls       71         61
## 30       Controls       75         70
## 31       Controls       61         64
## 32       Controls       80         64
## 33       Controls       66         55
## 34       Controls       53         47
## 35       Controls       62         61
## 36       Controls       61         56
## 37       Controls       77         64
## 38       Controls       66         62
## 39       Controls       52         47
## 40       Controls       60         56
## 41       Controls       58         78
## 42       Controls       54         74
## 43       Controls       72         61
## 44       Controls       71         61
## 45       Controls       87         78
## 46       Controls       75         62
## 47       Controls       57         71
## 48       Controls       59         55
## 49       Controls       46         46
## 50       Controls       89         79
textMessages <- tidyr::gather(textData, 
                              Time, 
                              Grammar_Score,
                              2:3)
textMessages
##              Group       Time Grammar_Score
## 1   Text Messagers   Baseline            52
## 2   Text Messagers   Baseline            68
## 3   Text Messagers   Baseline            85
## 4   Text Messagers   Baseline            47
## 5   Text Messagers   Baseline            73
## 6   Text Messagers   Baseline            57
## 7   Text Messagers   Baseline            63
## 8   Text Messagers   Baseline            50
## 9   Text Messagers   Baseline            66
## 10  Text Messagers   Baseline            60
## 11  Text Messagers   Baseline            51
## 12  Text Messagers   Baseline            72
## 13  Text Messagers   Baseline            77
## 14  Text Messagers   Baseline            57
## 15  Text Messagers   Baseline            79
## 16  Text Messagers   Baseline            75
## 17  Text Messagers   Baseline            53
## 18  Text Messagers   Baseline            72
## 19  Text Messagers   Baseline            62
## 20  Text Messagers   Baseline            71
## 21  Text Messagers   Baseline            53
## 22  Text Messagers   Baseline            64
## 23  Text Messagers   Baseline            79
## 24  Text Messagers   Baseline            75
## 25  Text Messagers   Baseline            60
## 26        Controls   Baseline            65
## 27        Controls   Baseline            57
## 28        Controls   Baseline            66
## 29        Controls   Baseline            71
## 30        Controls   Baseline            75
## 31        Controls   Baseline            61
## 32        Controls   Baseline            80
## 33        Controls   Baseline            66
## 34        Controls   Baseline            53
## 35        Controls   Baseline            62
## 36        Controls   Baseline            61
## 37        Controls   Baseline            77
## 38        Controls   Baseline            66
## 39        Controls   Baseline            52
## 40        Controls   Baseline            60
## 41        Controls   Baseline            58
## 42        Controls   Baseline            54
## 43        Controls   Baseline            72
## 44        Controls   Baseline            71
## 45        Controls   Baseline            87
## 46        Controls   Baseline            75
## 47        Controls   Baseline            57
## 48        Controls   Baseline            59
## 49        Controls   Baseline            46
## 50        Controls   Baseline            89
## 51  Text Messagers Six_months            32
## 52  Text Messagers Six_months            48
## 53  Text Messagers Six_months            62
## 54  Text Messagers Six_months            16
## 55  Text Messagers Six_months            63
## 56  Text Messagers Six_months            53
## 57  Text Messagers Six_months            59
## 58  Text Messagers Six_months            58
## 59  Text Messagers Six_months            59
## 60  Text Messagers Six_months            57
## 61  Text Messagers Six_months            60
## 62  Text Messagers Six_months            56
## 63  Text Messagers Six_months            61
## 64  Text Messagers Six_months            52
## 65  Text Messagers Six_months             9
## 66  Text Messagers Six_months            76
## 67  Text Messagers Six_months            38
## 68  Text Messagers Six_months            63
## 69  Text Messagers Six_months            53
## 70  Text Messagers Six_months            61
## 71  Text Messagers Six_months            50
## 72  Text Messagers Six_months            78
## 73  Text Messagers Six_months            33
## 74  Text Messagers Six_months            68
## 75  Text Messagers Six_months            59
## 76        Controls Six_months            62
## 77        Controls Six_months            50
## 78        Controls Six_months            62
## 79        Controls Six_months            61
## 80        Controls Six_months            70
## 81        Controls Six_months            64
## 82        Controls Six_months            64
## 83        Controls Six_months            55
## 84        Controls Six_months            47
## 85        Controls Six_months            61
## 86        Controls Six_months            56
## 87        Controls Six_months            64
## 88        Controls Six_months            62
## 89        Controls Six_months            47
## 90        Controls Six_months            56
## 91        Controls Six_months            78
## 92        Controls Six_months            74
## 93        Controls Six_months            61
## 94        Controls Six_months            61
## 95        Controls Six_months            78
## 96        Controls Six_months            62
## 97        Controls Six_months            71
## 98        Controls Six_months            55
## 99        Controls Six_months            46
## 100       Controls Six_months            79
str(textMessages)
## 'data.frame':    100 obs. of  3 variables:
##  $ Group        : Factor w/ 2 levels "Controls","Text Messagers": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Time         : chr  "Baseline" "Baseline" "Baseline" "Baseline" ...
##  $ Grammar_Score: int  52 68 85 47 73 57 63 50 66 60 ...
textMessages %>% 
  ggplot(aes(Time, Grammar_Score, color = Group))+
  stat_summary(fun.y = mean, 
               geom ="point") +
  stat_summary(fun.y = mean, 
               geom = "line",
               aes(group = Group))+
  stat_summary(fun.data = mean_cl_boot, 
               geom = "errorbar", 
               width = 0.2) + 
  scale_color_manual(values = c("black", "blue")) +
  labs(x = "Time", 
       y = "Mean Grammar Score", 
       colour = "Group")

sessionInfo()
## R version 3.5.1 (2018-07-02)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.1 LTS
## 
## Matrix products: default
## BLAS: /home/michael/anaconda3/lib/R/lib/libRblas.so
## LAPACK: /home/michael/anaconda3/lib/R/lib/libRlapack.so
## 
## locale:
## [1] en_CA.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] bindrcpp_0.2.2       Hmisc_4.1-1          Formula_1.2-3       
##  [4] survival_2.42-3      lattice_0.20-35      gridExtra_2.3       
##  [7] ggplot2_3.0.0        dplyr_0.7.6          RevoUtils_11.0.1    
## [10] RevoUtilsMath_11.0.0
## 
## loaded via a namespace (and not attached):
##  [1] tidyselect_0.2.4    xfun_0.4.11         purrr_0.2.5        
##  [4] splines_3.5.1       colorspace_1.3-2    htmltools_0.3.6    
##  [7] yaml_2.2.0          base64enc_0.1-3     rlang_0.2.1        
## [10] pillar_1.3.0        foreign_0.8-70      glue_1.3.0         
## [13] withr_2.1.2         RColorBrewer_1.1-2  bindr_0.1.1        
## [16] plyr_1.8.4          stringr_1.3.1       munsell_0.5.0      
## [19] blogdown_0.9.8      gtable_0.2.0        htmlwidgets_1.2    
## [22] codetools_0.2-15    evaluate_0.11       labeling_0.3       
## [25] latticeExtra_0.6-28 knitr_1.20          htmlTable_1.12     
## [28] Rcpp_0.12.18        acepack_1.4.1       scales_0.5.0       
## [31] backports_1.1.2     checkmate_1.8.5     digest_0.6.15      
## [34] stringi_1.2.4       bookdown_0.7        grid_3.5.1         
## [37] rprojroot_1.3-2     tools_3.5.1         magrittr_1.5       
## [40] lazyeval_0.2.1      tibble_1.4.2        cluster_2.0.7-1    
## [43] tidyr_0.8.1         crayon_1.3.4        pkgconfig_2.0.1    
## [46] Matrix_1.2-14       data.table_1.11.4   assertthat_0.2.0   
## [49] rmarkdown_1.10      rstudioapi_0.7      R6_2.2.2           
## [52] rpart_4.1-13        nnet_7.3-12         compiler_3.5.1

References

knitr::write_bib(.packages(), "packages.bib") 
## tweaking Hmisc

Auguie, Baptiste. 2017. GridExtra: Miscellaneous Functions for “Grid” Graphics. https://CRAN.R-project.org/package=gridExtra.

Harrell, Frank E, Jr. 2018. Hmisc: Harrell Miscellaneous. https://CRAN.R-project.org/package=Hmisc.

R Core Team. 2018. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.

Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, and Kara Woo. 2018. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.

Wickham, Hadley, Romain François, Lionel Henry, and Kirill Müller. 2018. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.