-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolutions.html
1695 lines (1638 loc) · 184 KB
/
solutions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Solutions | R for Conditional Process Analysis</title>
<meta name="description" content="Using Conditional Process Analysis to evaluate communication theories - B.A. Seminar at IKMZ, FS 2022" />
<meta name="generator" content="bookdown 0.24 and GitBook 2.6.7" />
<meta property="og:title" content="Solutions | R for Conditional Process Analysis" />
<meta property="og:type" content="book" />
<meta property="og:description" content="Using Conditional Process Analysis to evaluate communication theories - B.A. Seminar at IKMZ, FS 2022" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Solutions | R for Conditional Process Analysis" />
<meta name="twitter:description" content="Using Conditional Process Analysis to evaluate communication theories - B.A. Seminar at IKMZ, FS 2022" />
<meta name="author" content="Lara Kobilke, IKMZ, University of Zurich" />
<meta name="date" content="2022-05-04" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="exercise-7-test-your-knowledge.html"/>
<script src="libs/header-attrs-2.11/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>
<script src="libs/htmlwidgets-1.5.4/htmlwidgets.js"></script>
<script src="libs/viz-1.8.2/viz.js"></script>
<link href="libs/DiagrammeR-styles-0.2/styles.css" rel="stylesheet" />
<script src="libs/grViz-binding-1.0.9/grViz.js"></script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">CPA Seminar</a></li>
<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>General information on the course</a>
<ul>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#how-to-use-this-tutorial"><i class="fa fa-check"></i>How to use this tutorial</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#what-can-i-do-if-questions-arise"><i class="fa fa-check"></i>What can I do if questions arise?</a></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html#what-can-i-do-if-i-have-problems-with-my-r-code"><i class="fa fa-check"></i>What can I do if I have problems with my R code?</a></li>
</ul></li>
<li class="chapter" data-level="1" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html"><i class="fa fa-check"></i><b>1</b> Tutorial: Installing & Understanding R/R Studio</a>
<ul>
<li class="chapter" data-level="1.1" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#installing-r"><i class="fa fa-check"></i><b>1.1</b> Installing R</a></li>
<li class="chapter" data-level="1.2" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#installing-r-studio"><i class="fa fa-check"></i><b>1.2</b> Installing R Studio</a></li>
<li class="chapter" data-level="1.3" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#updating-r-and-r-studio"><i class="fa fa-check"></i><b>1.3</b> Updating R and R Studio</a>
<ul>
<li class="chapter" data-level="1.3.1" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#on-windows"><i class="fa fa-check"></i><b>1.3.1</b> On Windows</a></li>
<li class="chapter" data-level="1.3.2" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#on-mac"><i class="fa fa-check"></i><b>1.3.2</b> On MAC</a></li>
</ul></li>
<li class="chapter" data-level="1.4" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#how-does-r-work"><i class="fa fa-check"></i><b>1.4</b> How does R work?</a></li>
<li class="chapter" data-level="1.5" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#how-does-r-studio-work"><i class="fa fa-check"></i><b>1.5</b> How does R Studio work?</a>
<ul>
<li class="chapter" data-level="1.5.1" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#source-writing-your-own-code"><i class="fa fa-check"></i><b>1.5.1</b> Source: Writing your own code</a></li>
<li class="chapter" data-level="1.5.2" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#console-printing-results"><i class="fa fa-check"></i><b>1.5.2</b> Console: Printing results</a></li>
<li class="chapter" data-level="1.5.3" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#environment-overview-of-objects"><i class="fa fa-check"></i><b>1.5.3</b> Environment: Overview of objects</a></li>
<li class="chapter" data-level="1.5.4" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#plotshelppackages-do-everything-else"><i class="fa fa-check"></i><b>1.5.4</b> Plots/Help/Packages: Do everything else</a></li>
</ul></li>
<li class="chapter" data-level="1.6" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#take-aways"><i class="fa fa-check"></i><b>1.6</b> Take-Aways</a></li>
<li class="chapter" data-level="1.7" data-path="tutorial-installing-understanding-rr-studio.html"><a href="tutorial-installing-understanding-rr-studio.html#additional-tutorials"><i class="fa fa-check"></i><b>1.7</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html"><i class="fa fa-check"></i><b>2</b> Tutorial: Workflow in R</a>
<ul>
<li class="chapter" data-level="2.1" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#defining-your-working-directory"><i class="fa fa-check"></i><b>2.1</b> Defining your working directory</a></li>
<li class="chapter" data-level="2.2" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#packages"><i class="fa fa-check"></i><b>2.2</b> Packages</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#installing-packages"><i class="fa fa-check"></i><b>2.2.1</b> Installing packages</a></li>
<li class="chapter" data-level="2.2.2" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#activating-packages"><i class="fa fa-check"></i><b>2.2.2</b> Activating packages</a></li>
<li class="chapter" data-level="2.2.3" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#getting-information-about-packages"><i class="fa fa-check"></i><b>2.2.3</b> Getting information about packages</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#help"><i class="fa fa-check"></i><b>2.3</b> Help?!</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#finding-information-about-packages"><i class="fa fa-check"></i><b>2.3.1</b> Finding information about packages</a></li>
<li class="chapter" data-level="2.3.2" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#finding-information-about-functions"><i class="fa fa-check"></i><b>2.3.2</b> Finding information about functions</a></li>
<li class="chapter" data-level="2.3.3" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#searching-for-help-online"><i class="fa fa-check"></i><b>2.3.3</b> Searching for help online</a></li>
<li class="chapter" data-level="2.3.4" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#interrupting-r"><i class="fa fa-check"></i><b>2.3.4</b> Interrupting R</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#saving-loading-cleaning-coderesults"><i class="fa fa-check"></i><b>2.4</b> Saving, loading & cleaning code/results</a>
<ul>
<li class="chapter" data-level="2.4.1" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#saving-your-code"><i class="fa fa-check"></i><b>2.4.1</b> Saving your code</a></li>
<li class="chapter" data-level="2.4.2" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#saving-your-results"><i class="fa fa-check"></i><b>2.4.2</b> Saving your results</a></li>
<li class="chapter" data-level="2.4.3" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#loading-working-spaces"><i class="fa fa-check"></i><b>2.4.3</b> Loading working spaces</a></li>
<li class="chapter" data-level="2.4.4" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#clean-your-working-space"><i class="fa fa-check"></i><b>2.4.4</b> Clean your working space</a></li>
<li class="chapter" data-level="2.4.5" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#take-aways-1"><i class="fa fa-check"></i><b>2.4.5</b> Take Aways</a></li>
</ul></li>
<li class="chapter" data-level="2.5" data-path="tutorial-workflow-in-r.html"><a href="tutorial-workflow-in-r.html#additional-tutorials-1"><i class="fa fa-check"></i><b>2.5</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="tutorial-using-r-as-a-calculator.html"><a href="tutorial-using-r-as-a-calculator.html"><i class="fa fa-check"></i><b>3</b> Tutorial: Using R as a calculator</a>
<ul>
<li class="chapter" data-level="3.1" data-path="tutorial-using-r-as-a-calculator.html"><a href="tutorial-using-r-as-a-calculator.html#using-variables-for-calculation"><i class="fa fa-check"></i><b>3.1</b> Using variables for calculation</a></li>
<li class="chapter" data-level="3.2" data-path="tutorial-using-r-as-a-calculator.html"><a href="tutorial-using-r-as-a-calculator.html#using-vectors-for-calculation"><i class="fa fa-check"></i><b>3.2</b> Using vectors for calculation</a></li>
<li class="chapter" data-level="3.3" data-path="tutorial-using-r-as-a-calculator.html"><a href="tutorial-using-r-as-a-calculator.html#take-aways-2"><i class="fa fa-check"></i><b>3.3</b> Take-Aways</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html"><i class="fa fa-check"></i><b>4</b> Tutorial: Objects & structures in R</a>
<ul>
<li class="chapter" data-level="4.1" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#types-of-data"><i class="fa fa-check"></i><b>4.1</b> Types of data</a>
<ul>
<li class="chapter" data-level="4.1.1" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#accessing-variables-in-data-sets"><i class="fa fa-check"></i><b>4.1.1</b> Accessing variables in data sets</a></li>
<li class="chapter" data-level="4.1.2" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#numbers"><i class="fa fa-check"></i><b>4.1.2</b> Numbers</a></li>
<li class="chapter" data-level="4.1.3" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#text"><i class="fa fa-check"></i><b>4.1.3</b> Text</a></li>
<li class="chapter" data-level="4.1.4" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#factors"><i class="fa fa-check"></i><b>4.1.4</b> Factors</a></li>
<li class="chapter" data-level="4.1.5" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#dates"><i class="fa fa-check"></i><b>4.1.5</b> Dates</a></li>
<li class="chapter" data-level="4.1.6" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#missing-datanas"><i class="fa fa-check"></i><b>4.1.6</b> Missing data/NAs</a></li>
<li class="chapter" data-level="4.1.7" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#logicalother-operators"><i class="fa fa-check"></i><b>4.1.7</b> Logical/other operators</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#types-of-objects"><i class="fa fa-check"></i><b>4.2</b> Types of objects</a>
<ul>
<li class="chapter" data-level="4.2.1" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#scalars"><i class="fa fa-check"></i><b>4.2.1</b> Scalars</a></li>
<li class="chapter" data-level="4.2.2" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#vectors"><i class="fa fa-check"></i><b>4.2.2</b> Vectors</a></li>
<li class="chapter" data-level="4.2.3" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#data-frames-matrices"><i class="fa fa-check"></i><b>4.2.3</b> Data frames & matrices</a></li>
<li class="chapter" data-level="4.2.4" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#lists"><i class="fa fa-check"></i><b>4.2.4</b> Lists</a></li>
<li class="chapter" data-level="4.2.5" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#other-types-of-objects"><i class="fa fa-check"></i><b>4.2.5</b> Other types of objects</a></li>
</ul></li>
<li class="chapter" data-level="4.3" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#take-aways-3"><i class="fa fa-check"></i><b>4.3</b> Take Aways</a></li>
<li class="chapter" data-level="4.4" data-path="tutorial-objects-structures-in-r.html"><a href="tutorial-objects-structures-in-r.html#additional-tutorials-2"><i class="fa fa-check"></i><b>4.4</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="tutorial-reading-data-inout.html"><a href="tutorial-reading-data-inout.html"><i class="fa fa-check"></i><b>5</b> Tutorial: Reading data in/out</a>
<ul>
<li class="chapter" data-level="5.1" data-path="tutorial-reading-data-inout.html"><a href="tutorial-reading-data-inout.html#getting-data-into-r"><i class="fa fa-check"></i><b>5.1</b> Getting data into R</a></li>
<li class="chapter" data-level="5.2" data-path="tutorial-reading-data-inout.html"><a href="tutorial-reading-data-inout.html#getting-data-out-of-r"><i class="fa fa-check"></i><b>5.2</b> Getting data out of R</a></li>
<li class="chapter" data-level="5.3" data-path="tutorial-reading-data-inout.html"><a href="tutorial-reading-data-inout.html#other-packages-for-getting-data-intoout-of-r"><i class="fa fa-check"></i><b>5.3</b> Other packages for getting data into/out of R</a></li>
<li class="chapter" data-level="5.4" data-path="tutorial-reading-data-inout.html"><a href="tutorial-reading-data-inout.html#take-aways-4"><i class="fa fa-check"></i><b>5.4</b> Take Aways</a></li>
<li class="chapter" data-level="5.5" data-path="tutorial-reading-data-inout.html"><a href="tutorial-reading-data-inout.html#additional-tutorials-3"><i class="fa fa-check"></i><b>5.5</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="exercise-1-test-your-knowledge.html"><a href="exercise-1-test-your-knowledge.html"><i class="fa fa-check"></i><b>6</b> Exercise 1: Test your knowledge</a>
<ul>
<li class="chapter" data-level="6.1" data-path="exercise-1-test-your-knowledge.html"><a href="exercise-1-test-your-knowledge.html#task-1"><i class="fa fa-check"></i><b>6.1</b> Task 1</a></li>
<li class="chapter" data-level="6.2" data-path="exercise-1-test-your-knowledge.html"><a href="exercise-1-test-your-knowledge.html#task-2"><i class="fa fa-check"></i><b>6.2</b> Task 2</a></li>
<li class="chapter" data-level="6.3" data-path="exercise-1-test-your-knowledge.html"><a href="exercise-1-test-your-knowledge.html#task-3"><i class="fa fa-check"></i><b>6.3</b> Task 3</a></li>
<li class="chapter" data-level="6.4" data-path="exercise-1-test-your-knowledge.html"><a href="exercise-1-test-your-knowledge.html#task-4"><i class="fa fa-check"></i><b>6.4</b> Task 4</a></li>
<li class="chapter" data-level="6.5" data-path="exercise-1-test-your-knowledge.html"><a href="exercise-1-test-your-knowledge.html#task-5"><i class="fa fa-check"></i><b>6.5</b> Task 5</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html"><i class="fa fa-check"></i><b>7</b> Tutorial: Data management with tidyverse</a>
<ul>
<li class="chapter" data-level="7.1" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#why-not-stick-with-base-r"><i class="fa fa-check"></i><b>7.1</b> Why not stick with Base R?</a></li>
<li class="chapter" data-level="7.2" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#tidyverse-packages"><i class="fa fa-check"></i><b>7.2</b> Tidyverse packages</a></li>
<li class="chapter" data-level="7.3" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#tidy-data"><i class="fa fa-check"></i><b>7.3</b> Tidy data</a></li>
<li class="chapter" data-level="7.4" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#the-pipe-operator"><i class="fa fa-check"></i><b>7.4</b> The pipe operator</a></li>
<li class="chapter" data-level="7.5" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#data-transformation-with-dplyr"><i class="fa fa-check"></i><b>7.5</b> Data transformation with dplyr</a>
<ul>
<li class="chapter" data-level="7.5.1" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#select"><i class="fa fa-check"></i><b>7.5.1</b> select()</a></li>
<li class="chapter" data-level="7.5.2" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#filter"><i class="fa fa-check"></i><b>7.5.2</b> filter()</a></li>
<li class="chapter" data-level="7.5.3" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#arrange"><i class="fa fa-check"></i><b>7.5.3</b> arrange()</a></li>
<li class="chapter" data-level="7.5.4" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#mutate"><i class="fa fa-check"></i><b>7.5.4</b> mutate()</a></li>
<li class="chapter" data-level="7.5.5" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#simmarize-group_by"><i class="fa fa-check"></i><b>7.5.5</b> simmarize() [+ group_by()]</a></li>
<li class="chapter" data-level="7.5.6" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#chaining-functions-in-a-pipe"><i class="fa fa-check"></i><b>7.5.6</b> Chaining functions in a pipe</a></li>
</ul></li>
<li class="chapter" data-level="7.6" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#take-aways-5"><i class="fa fa-check"></i><b>7.6</b> Take-Aways</a></li>
<li class="chapter" data-level="7.7" data-path="tutorial-data-management-with-tidyverse.html"><a href="tutorial-data-management-with-tidyverse.html#additional-tutorials-4"><i class="fa fa-check"></i><b>7.7</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html"><i class="fa fa-check"></i><b>8</b> Exercise 2: Test your knowledge</a>
<ul>
<li class="chapter" data-level="8.1" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-1-1"><i class="fa fa-check"></i><b>8.1</b> Task 1</a></li>
<li class="chapter" data-level="8.2" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-2-1"><i class="fa fa-check"></i><b>8.2</b> Task 2</a></li>
<li class="chapter" data-level="8.3" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-3-1"><i class="fa fa-check"></i><b>8.3</b> Task 3</a></li>
<li class="chapter" data-level="8.4" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-4-1"><i class="fa fa-check"></i><b>8.4</b> Task 4</a></li>
<li class="chapter" data-level="8.5" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-5-1"><i class="fa fa-check"></i><b>8.5</b> Task 5</a></li>
<li class="chapter" data-level="8.6" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-6"><i class="fa fa-check"></i><b>8.6</b> Task 6</a></li>
<li class="chapter" data-level="8.7" data-path="exercise-2-test-your-knowledge.html"><a href="exercise-2-test-your-knowledge.html#task-7"><i class="fa fa-check"></i><b>8.7</b> Task 7</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html"><i class="fa fa-check"></i><b>9</b> Tutorial: Data visualization with ggplot</a>
<ul>
<li class="chapter" data-level="9.1" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#why-not-stick-with-base-r-1"><i class="fa fa-check"></i><b>9.1</b> Why not stick with Base R?</a></li>
<li class="chapter" data-level="9.2" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#components-of-a-ggplot-graph"><i class="fa fa-check"></i><b>9.2</b> Components of a ggplot graph</a></li>
<li class="chapter" data-level="9.3" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#installing-activating-ggplot"><i class="fa fa-check"></i><b>9.3</b> Installing & activating ggplot</a></li>
<li class="chapter" data-level="9.4" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#building-your-first-plot"><i class="fa fa-check"></i><b>9.4</b> Building your first plot</a>
<ul>
<li class="chapter" data-level="9.4.1" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#data"><i class="fa fa-check"></i><b>9.4.1</b> Data</a></li>
<li class="chapter" data-level="9.4.2" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#aesthetics"><i class="fa fa-check"></i><b>9.4.2</b> Aesthetics</a></li>
<li class="chapter" data-level="9.4.3" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#geometrics"><i class="fa fa-check"></i><b>9.4.3</b> Geometrics</a></li>
<li class="chapter" data-level="9.4.4" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#scales"><i class="fa fa-check"></i><b>9.4.4</b> Scales</a></li>
<li class="chapter" data-level="9.4.5" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#themes"><i class="fa fa-check"></i><b>9.4.5</b> Themes</a></li>
<li class="chapter" data-level="9.4.6" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#labs"><i class="fa fa-check"></i><b>9.4.6</b> Labs</a></li>
<li class="chapter" data-level="9.4.7" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#facets"><i class="fa fa-check"></i><b>9.4.7</b> Facets</a></li>
<li class="chapter" data-level="9.4.8" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#saving-graphs"><i class="fa fa-check"></i><b>9.4.8</b> Saving graphs</a></li>
</ul></li>
<li class="chapter" data-level="9.5" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#other-common-plot-types"><i class="fa fa-check"></i><b>9.5</b> Other common plot types</a>
<ul>
<li class="chapter" data-level="9.5.1" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#bar-plots"><i class="fa fa-check"></i><b>9.5.1</b> bar plots</a></li>
<li class="chapter" data-level="9.5.2" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#box-plots"><i class="fa fa-check"></i><b>9.5.2</b> box plots</a></li>
</ul></li>
<li class="chapter" data-level="9.6" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#take-aways-6"><i class="fa fa-check"></i><b>9.6</b> Take Aways</a></li>
<li class="chapter" data-level="9.7" data-path="tutorial-data-visualization-with-ggplot.html"><a href="tutorial-data-visualization-with-ggplot.html#additional-tutorials-5"><i class="fa fa-check"></i><b>9.7</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="exercise-3-test-your-knowledge.html"><a href="exercise-3-test-your-knowledge.html"><i class="fa fa-check"></i><b>10</b> Exercise 3: Test your knowledge</a>
<ul>
<li class="chapter" data-level="10.1" data-path="exercise-3-test-your-knowledge.html"><a href="exercise-3-test-your-knowledge.html#task-1-2"><i class="fa fa-check"></i><b>10.1</b> Task 1</a></li>
<li class="chapter" data-level="10.2" data-path="exercise-3-test-your-knowledge.html"><a href="exercise-3-test-your-knowledge.html#task-2-2"><i class="fa fa-check"></i><b>10.2</b> Task 2</a></li>
<li class="chapter" data-level="10.3" data-path="exercise-3-test-your-knowledge.html"><a href="exercise-3-test-your-knowledge.html#task-3-2"><i class="fa fa-check"></i><b>10.3</b> Task 3</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html"><i class="fa fa-check"></i><b>11</b> Tutorial: Linear regression</a>
<ul>
<li class="chapter" data-level="11.1" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#knowing-your-data"><i class="fa fa-check"></i><b>11.1</b> Knowing your data</a></li>
<li class="chapter" data-level="11.2" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#visual-inspection-of-linear-trends"><i class="fa fa-check"></i><b>11.2</b> Visual inspection of linear trends</a></li>
<li class="chapter" data-level="11.3" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#pearsons-r"><i class="fa fa-check"></i><b>11.3</b> Pearson´s r</a></li>
<li class="chapter" data-level="11.4" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#ols-regression"><i class="fa fa-check"></i><b>11.4</b> OLS regression</a></li>
<li class="chapter" data-level="11.5" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#standardizing-coefficients"><i class="fa fa-check"></i><b>11.5</b> Standardizing coefficients</a></li>
<li class="chapter" data-level="11.6" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#multiple-regression"><i class="fa fa-check"></i><b>11.6</b> Multiple regression</a></li>
<li class="chapter" data-level="11.7" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#standardized-multiple-regression"><i class="fa fa-check"></i><b>11.7</b> Standardized multiple regression</a></li>
<li class="chapter" data-level="11.8" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#take-aways-7"><i class="fa fa-check"></i><b>11.8</b> Take Aways</a></li>
<li class="chapter" data-level="11.9" data-path="tutorial-linear-regression.html"><a href="tutorial-linear-regression.html#additional-tutorials-6"><i class="fa fa-check"></i><b>11.9</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html"><i class="fa fa-check"></i><b>12</b> Exercise 4: Test your knowledge</a>
<ul>
<li class="chapter" data-level="12.1" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html#task-1-3"><i class="fa fa-check"></i><b>12.1</b> Task 1</a></li>
<li class="chapter" data-level="12.2" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html#task-2-3"><i class="fa fa-check"></i><b>12.2</b> Task 2</a></li>
<li class="chapter" data-level="12.3" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html#task-3-3"><i class="fa fa-check"></i><b>12.3</b> Task 3</a></li>
<li class="chapter" data-level="12.4" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html#task-4-2"><i class="fa fa-check"></i><b>12.4</b> Task 4</a></li>
<li class="chapter" data-level="12.5" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html#task-5-2"><i class="fa fa-check"></i><b>12.5</b> Task 5</a></li>
<li class="chapter" data-level="12.6" data-path="exercise-4-test-your-knowledge.html"><a href="exercise-4-test-your-knowledge.html#task-6-1"><i class="fa fa-check"></i><b>12.6</b> Task 6</a></li>
</ul></li>
<li class="chapter" data-level="13" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html"><i class="fa fa-check"></i><b>13</b> Tutorial: Mediation analysis</a>
<ul>
<li class="chapter" data-level="13.1" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#introduction-to-mediation"><i class="fa fa-check"></i><b>13.1</b> Introduction to mediation</a></li>
<li class="chapter" data-level="13.2" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#difference-between-mediation-and-moderation"><i class="fa fa-check"></i><b>13.2</b> Difference between mediation and moderation</a></li>
<li class="chapter" data-level="13.3" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#two-step-process-of-mediation"><i class="fa fa-check"></i><b>13.3</b> Two-step process of mediation</a></li>
<li class="chapter" data-level="13.4" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#statistical-representation-and-equations"><i class="fa fa-check"></i><b>13.4</b> Statistical representation and equations</a>
<ul>
<li class="chapter" data-level="13.4.1" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#direct-effect-c"><i class="fa fa-check"></i><b>13.4.1</b> Direct effect <em>c′</em></a></li>
<li class="chapter" data-level="13.4.2" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#indirect-effect-ab"><i class="fa fa-check"></i><b>13.4.2</b> Indirect effect <em>ab</em></a></li>
<li class="chapter" data-level="13.4.3" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#total-effect"><i class="fa fa-check"></i><b>13.4.3</b> Total effect</a></li>
</ul></li>
<li class="chapter" data-level="13.5" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#example"><i class="fa fa-check"></i><b>13.5</b> Example</a>
<ul>
<li class="chapter" data-level="13.5.1" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#knowing-your-data-1"><i class="fa fa-check"></i><b>13.5.1</b> Knowing your data</a></li>
<li class="chapter" data-level="13.5.2" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#visual-inspection-of-linear-trends-1"><i class="fa fa-check"></i><b>13.5.2</b> Visual inspection of linear trends</a></li>
<li class="chapter" data-level="13.5.3" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#pearsons-r-1"><i class="fa fa-check"></i><b>13.5.3</b> Pearson’s r</a></li>
<li class="chapter" data-level="13.5.4" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#fit-models"><i class="fa fa-check"></i><b>13.5.4</b> Fit models</a></li>
<li class="chapter" data-level="13.5.5" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#using-processr"><i class="fa fa-check"></i><b>13.5.5</b> Using processR</a></li>
</ul></li>
<li class="chapter" data-level="13.6" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#take-aways-8"><i class="fa fa-check"></i><b>13.6</b> Take Aways</a></li>
<li class="chapter" data-level="13.7" data-path="tutorial-mediation-analysis.html"><a href="tutorial-mediation-analysis.html#additional-tutorials-7"><i class="fa fa-check"></i><b>13.7</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="14" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html"><i class="fa fa-check"></i><b>14</b> Exercise 5: Test your knowledge</a>
<ul>
<li class="chapter" data-level="14.1" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-1-4"><i class="fa fa-check"></i><b>14.1</b> Task 1</a></li>
<li class="chapter" data-level="14.2" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-2-4"><i class="fa fa-check"></i><b>14.2</b> Task 2</a></li>
<li class="chapter" data-level="14.3" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-3-4"><i class="fa fa-check"></i><b>14.3</b> Task 3</a></li>
<li class="chapter" data-level="14.4" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-4-3"><i class="fa fa-check"></i><b>14.4</b> Task 4</a></li>
<li class="chapter" data-level="14.5" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-5-3"><i class="fa fa-check"></i><b>14.5</b> Task 5</a></li>
<li class="chapter" data-level="14.6" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-6-2"><i class="fa fa-check"></i><b>14.6</b> Task 6</a></li>
<li class="chapter" data-level="14.7" data-path="exercise-5-test-your-knowledge.html"><a href="exercise-5-test-your-knowledge.html#task-7-1"><i class="fa fa-check"></i><b>14.7</b> Task 7</a></li>
</ul></li>
<li class="chapter" data-level="15" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html"><i class="fa fa-check"></i><b>15</b> Tutorial: Moderation analysis</a>
<ul>
<li class="chapter" data-level="15.1" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#introduction-to-moderation"><i class="fa fa-check"></i><b>15.1</b> Introduction to moderation</a></li>
<li class="chapter" data-level="15.2" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#one-step-process-of-moderation"><i class="fa fa-check"></i><b>15.2</b> One-step process of moderation</a></li>
<li class="chapter" data-level="15.3" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#statistical-representation-and-equations-1"><i class="fa fa-check"></i><b>15.3</b> Statistical representation and equations</a></li>
<li class="chapter" data-level="15.4" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#example-1"><i class="fa fa-check"></i><b>15.4</b> Example</a>
<ul>
<li class="chapter" data-level="15.4.1" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#knowing-your-data-2"><i class="fa fa-check"></i><b>15.4.1</b> Knowing your data</a></li>
<li class="chapter" data-level="15.4.2" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#visual-inspection-of-linear-trends-2"><i class="fa fa-check"></i><b>15.4.2</b> Visual inspection of linear trends</a></li>
<li class="chapter" data-level="15.4.3" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#fit-models-1"><i class="fa fa-check"></i><b>15.4.3</b> Fit models</a></li>
<li class="chapter" data-level="15.4.4" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#standardization-and-mean-centering"><i class="fa fa-check"></i><b>15.4.4</b> Standardization and mean-centering</a></li>
<li class="chapter" data-level="15.4.5" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#follow-up-analysis-pobing-the-interaction"><i class="fa fa-check"></i><b>15.4.5</b> Follow-up analysis: Pobing the interaction</a></li>
<li class="chapter" data-level="15.4.6" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#using-processr-1"><i class="fa fa-check"></i><b>15.4.6</b> Using processR</a></li>
</ul></li>
<li class="chapter" data-level="15.5" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#take-aways-9"><i class="fa fa-check"></i><b>15.5</b> Take Aways</a></li>
<li class="chapter" data-level="15.6" data-path="tutorial-moderation-analysis.html"><a href="tutorial-moderation-analysis.html#additional-tutorials-8"><i class="fa fa-check"></i><b>15.6</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="16" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html"><i class="fa fa-check"></i><b>16</b> Exercise 6: Test your knowledge</a>
<ul>
<li class="chapter" data-level="16.1" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html#task-1-5"><i class="fa fa-check"></i><b>16.1</b> Task 1</a></li>
<li class="chapter" data-level="16.2" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html#task-2-5"><i class="fa fa-check"></i><b>16.2</b> Task 2</a></li>
<li class="chapter" data-level="16.3" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html#task-3-5"><i class="fa fa-check"></i><b>16.3</b> Task 3</a></li>
<li class="chapter" data-level="16.4" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html#task-4-4"><i class="fa fa-check"></i><b>16.4</b> Task 4</a></li>
<li class="chapter" data-level="16.5" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html#task-5-4"><i class="fa fa-check"></i><b>16.5</b> Task 5</a></li>
<li class="chapter" data-level="16.6" data-path="exercise-6-test-your-knowledge.html"><a href="exercise-6-test-your-knowledge.html#task-6-3"><i class="fa fa-check"></i><b>16.6</b> Task 6</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html"><i class="fa fa-check"></i><b>17</b> Tutorial: CPA and model fit</a>
<ul>
<li class="chapter" data-level="17.1" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#what-is-cpa"><i class="fa fa-check"></i><b>17.1</b> What is CPA?</a></li>
<li class="chapter" data-level="17.2" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#fitting-models-with-lavaan"><i class="fa fa-check"></i><b>17.2</b> Fitting models with lavaan</a></li>
<li class="chapter" data-level="17.3" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#example-evaluate-model-fit-for-complex-models"><i class="fa fa-check"></i><b>17.3</b> Example: Evaluate model fit for complex models</a>
<ul>
<li class="chapter" data-level="17.3.1" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#theory-driven-hypotheses"><i class="fa fa-check"></i><b>17.3.1</b> Theory-driven hypotheses</a></li>
<li class="chapter" data-level="17.3.2" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#model-fit-and-evaluation"><i class="fa fa-check"></i><b>17.3.2</b> Model fit and evaluation</a></li>
</ul></li>
<li class="chapter" data-level="17.4" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#take-aways-10"><i class="fa fa-check"></i><b>17.4</b> Take-Aways</a></li>
<li class="chapter" data-level="17.5" data-path="tutorial-cpa-and-model-fit.html"><a href="tutorial-cpa-and-model-fit.html#additional-tutorials-9"><i class="fa fa-check"></i><b>17.5</b> Additional tutorials</a></li>
</ul></li>
<li class="chapter" data-level="18" data-path="exercise-7-test-your-knowledge.html"><a href="exercise-7-test-your-knowledge.html"><i class="fa fa-check"></i><b>18</b> Exercise 7: Test your knowledge</a>
<ul>
<li class="chapter" data-level="18.1" data-path="exercise-7-test-your-knowledge.html"><a href="exercise-7-test-your-knowledge.html#task-1-6"><i class="fa fa-check"></i><b>18.1</b> Task 1</a></li>
<li class="chapter" data-level="18.2" data-path="exercise-7-test-your-knowledge.html"><a href="exercise-7-test-your-knowledge.html#task-2-6"><i class="fa fa-check"></i><b>18.2</b> Task 2</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html"><i class="fa fa-check"></i>Solutions</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-1"><i class="fa fa-check"></i>Solutions for Exercise 1</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-7"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-7"><i class="fa fa-check"></i>Task 2</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-3-6"><i class="fa fa-check"></i>Task 3</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-4-5"><i class="fa fa-check"></i>Task 4</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-5-5"><i class="fa fa-check"></i>Task 5</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-2"><i class="fa fa-check"></i>Solutions for Exercise 2</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-8"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-8"><i class="fa fa-check"></i>Task 2</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-3-7"><i class="fa fa-check"></i>Task 3</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-4-6"><i class="fa fa-check"></i>Task 4</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-5-6"><i class="fa fa-check"></i>Task 5</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-6-4"><i class="fa fa-check"></i>Task 6</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-7-2"><i class="fa fa-check"></i>Task 7</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-3"><i class="fa fa-check"></i>Solutions for Exercise 3</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-9"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-9"><i class="fa fa-check"></i>Task 2</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-3-8"><i class="fa fa-check"></i>Task 3</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-4"><i class="fa fa-check"></i>Solutions for Exercise 4</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-10"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-10"><i class="fa fa-check"></i>Task 2</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-3-9"><i class="fa fa-check"></i>Task 3</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-4-7"><i class="fa fa-check"></i>Task 4</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-5-7"><i class="fa fa-check"></i>Task 5</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-6-5"><i class="fa fa-check"></i>Task 6</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-5"><i class="fa fa-check"></i>Solutions for Exercise 5</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-11"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-11"><i class="fa fa-check"></i>Task 2</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-3-10"><i class="fa fa-check"></i>Task 3</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-4-8"><i class="fa fa-check"></i>Task 4</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-5-8"><i class="fa fa-check"></i>Task 5</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-6-6"><i class="fa fa-check"></i>Task 6</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-7-3"><i class="fa fa-check"></i>Task 7</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-6"><i class="fa fa-check"></i>Solutions for Exercise 6</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-12"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-12"><i class="fa fa-check"></i>Task 2</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-3-11"><i class="fa fa-check"></i>Task 3</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-4-9"><i class="fa fa-check"></i>Task 4</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-5-9"><i class="fa fa-check"></i>Task 5</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-6-7"><i class="fa fa-check"></i>Task 6</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#solutions-for-exercise-7"><i class="fa fa-check"></i>Solutions for Exercise 7</a>
<ul>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-1-13"><i class="fa fa-check"></i>Task 1</a></li>
<li class="chapter" data-level="" data-path="solutions.html"><a href="solutions.html#task-2-13"><i class="fa fa-check"></i>Task 2</a></li>
</ul></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/LKobilke/CPA-Seminar" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">R for Conditional Process Analysis</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="solutions" class="section level1 unnumbered">
<h1>Solutions</h1>
<p>This is where you’ll find solutions for all of the tutorials.</p>
<div id="solutions-for-exercise-1" class="section level2 unnumbered">
<h2>Solutions for Exercise 1</h2>
<div id="task-1-7" class="section level3 unnumbered">
<h3>Task 1</h3>
<p>Below you will see multiple choice questions. Please try to identify the correct answers. 1, 2, 3 and 4 correct answers are possible for each question.</p>
<p><strong>1. What panels are part of RStudio?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li>source (x)</li>
<li>console (x)</li>
<li>packages, files & plots (x)</li>
</ul>
<p><strong>2. How do you activate R packages after you have installed them?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li>library() (x)</li>
</ul>
<p><strong>3. How do you create a vector in R with elements 1, 2, 3?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li>c(1,2,3) (x)</li>
</ul>
<p><strong>4. Imagine you have a vector called ‘vector’ with 10 numeric elements. How do you retrieve the 8th element?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li>vector[8] (x)</li>
</ul>
<p><strong>5. Imagine you have a vector called ‘hair’ with 5 elements: brown, black, red, blond, other. How do you retrieve the color ‘blond’?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li>hair[4] (x)</li>
</ul>
</div>
<div id="task-2-7" class="section level3 unnumbered">
<h3>Task 2</h3>
<p>Create a numeric vector with 8 values and assign the name <em>age</em> to the vector. First, display all elements of the vector. Then print only the 5th element. After that, display all elements except the 5th. Finally, display the elements at the positions 6 to 8.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb327"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb327-1"><a href="solutions.html#cb327-1" aria-hidden="true" tabindex="-1"></a>age <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">65</span>,<span class="dv">52</span>,<span class="dv">73</span>,<span class="dv">71</span>,<span class="dv">80</span>,<span class="dv">62</span>,<span class="dv">68</span>,<span class="dv">87</span>)</span>
<span id="cb327-2"><a href="solutions.html#cb327-2" aria-hidden="true" tabindex="-1"></a>age</span></code></pre></div>
<pre><code>## [1] 65 52 73 71 80 62 68 87</code></pre>
<div class="sourceCode" id="cb329"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb329-1"><a href="solutions.html#cb329-1" aria-hidden="true" tabindex="-1"></a>age[<span class="dv">5</span>]</span></code></pre></div>
<pre><code>## [1] 80</code></pre>
<div class="sourceCode" id="cb331"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb331-1"><a href="solutions.html#cb331-1" aria-hidden="true" tabindex="-1"></a>age[<span class="sc">-</span><span class="dv">5</span>]</span></code></pre></div>
<pre><code>## [1] 65 52 73 71 62 68 87</code></pre>
<div class="sourceCode" id="cb333"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb333-1"><a href="solutions.html#cb333-1" aria-hidden="true" tabindex="-1"></a>age[<span class="dv">6</span><span class="sc">:</span><span class="dv">8</span>]</span></code></pre></div>
<pre><code>## [1] 62 68 87</code></pre>
</div>
<div id="task-3-6" class="section level3 unnumbered">
<h3>Task 3</h3>
<p>Create a non-numeric, i.e. character, vector with 4 elements and assign the name <em>eye_color</em> to the vector. First, print all elements of this vector to the console. Then have only the value in the 2nd element displayed, then all values except the 2nd element. At the end, display the elements at the positions 2 to 4.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb335"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb335-1"><a href="solutions.html#cb335-1" aria-hidden="true" tabindex="-1"></a>eye_color <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"blue"</span>, <span class="st">"green"</span>, <span class="st">"brown"</span>, <span class="st">"other"</span>)</span>
<span id="cb335-2"><a href="solutions.html#cb335-2" aria-hidden="true" tabindex="-1"></a>eye_color</span></code></pre></div>
<pre><code>## [1] "blue" "green" "brown" "other"</code></pre>
<div class="sourceCode" id="cb337"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb337-1"><a href="solutions.html#cb337-1" aria-hidden="true" tabindex="-1"></a>eye_color[<span class="dv">2</span>]</span></code></pre></div>
<pre><code>## [1] "green"</code></pre>
<div class="sourceCode" id="cb339"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb339-1"><a href="solutions.html#cb339-1" aria-hidden="true" tabindex="-1"></a>eye_color[<span class="sc">-</span><span class="dv">2</span>]</span></code></pre></div>
<pre><code>## [1] "blue" "brown" "other"</code></pre>
<div class="sourceCode" id="cb341"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb341-1"><a href="solutions.html#cb341-1" aria-hidden="true" tabindex="-1"></a>eye_color[<span class="dv">2</span><span class="sc">:</span><span class="dv">4</span>]</span></code></pre></div>
<pre><code>## [1] "green" "brown" "other"</code></pre>
</div>
<div id="task-4-5" class="section level3 unnumbered">
<h3>Task 4</h3>
<p>Create a data frame called <em>data</em>. The data frame should contain the following variables (in this order):</p>
<ul>
<li>a vector called <em>food</em>. It should contain 5 elements, namely the names of your five favorite dishes.</li>
<li>a vector called <em>description</em>. For every dish mentioned in <em>food</em>, please describe the dish in a single sentence (for instance, if the first food you describe is “pizza”, you could write: “This is an Italian dish, which I prefer with a lot of cheese.”)</li>
<li>a vector called <em>rating</em>. Rate every dish mentioned in <em>food</em> with 1-5 (using every number only once), i.e., by rating your absolute favorite dish out of all five with a 1 and your least favorite dish out of all five with a 5.</li>
</ul>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb343"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb343-1"><a href="solutions.html#cb343-1" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> <span class="fu">data.frame</span>(<span class="st">"food"</span> <span class="ot">=</span> <span class="fu">c</span>(<span class="st">"pizza"</span>, <span class="st">"pasta"</span>, <span class="st">"ice cream"</span>, <span class="st">"crisps"</span>, <span class="st">"passion fruit"</span>),</span>
<span id="cb343-2"><a href="solutions.html#cb343-2" aria-hidden="true" tabindex="-1"></a> <span class="st">"description"</span> <span class="ot">=</span> <span class="fu">c</span>(<span class="st">"Italian dish, I actually prefer mine with little cheese"</span>,</span>
<span id="cb343-3"><a href="solutions.html#cb343-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"Another Italian dish"</span>,</span>
<span id="cb343-4"><a href="solutions.html#cb343-4" aria-hidden="true" tabindex="-1"></a> <span class="st">"The perfect snack in summer"</span>,</span>
<span id="cb343-5"><a href="solutions.html#cb343-5" aria-hidden="true" tabindex="-1"></a> <span class="st">"Potatoes and oil - a luxurious combination"</span>,</span>
<span id="cb343-6"><a href="solutions.html#cb343-6" aria-hidden="true" tabindex="-1"></a> <span class="st">"A fruit that makes me think about vacation"</span>),</span>
<span id="cb343-7"><a href="solutions.html#cb343-7" aria-hidden="true" tabindex="-1"></a> <span class="st">"Rating"</span> <span class="ot">=</span> <span class="fu">c</span>(<span class="dv">3</span>,<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">4</span>,<span class="dv">5</span>))</span>
<span id="cb343-8"><a href="solutions.html#cb343-8" aria-hidden="true" tabindex="-1"></a>data</span></code></pre></div>
<pre><code>## food description Rating
## 1 pizza Italian dish, I actually prefer mine with little cheese 3
## 2 pasta Another Italian dish 1
## 3 ice cream The perfect snack in summer 2
## 4 crisps Potatoes and oil - a luxurious combination 4
## 5 passion fruit A fruit that makes me think about vacation 5</code></pre>
</div>
<div id="task-5-5" class="section level3 unnumbered">
<h3>Task 5</h3>
<p>Can you sort the data in your data set by rating - with your favorite dish (i.e., the one rated “1”) on top of the list and your least favorite dish (i.e., the one rated “5”) on the bottom?</p>
<p><strong>Important</strong>: You do <em>not</em> yet know this command - you’ll have to google for the right solution. Please do and note down the exact search terms you used for googling.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb345"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb345-1"><a href="solutions.html#cb345-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(<span class="st">"dplyr"</span>)</span>
<span id="cb345-2"><a href="solutions.html#cb345-2" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> data <span class="sc">%>%</span> <span class="fu">arrange</span>(Rating)</span>
<span id="cb345-3"><a href="solutions.html#cb345-3" aria-hidden="true" tabindex="-1"></a>data</span></code></pre></div>
<pre><code>## food description Rating
## 1 pasta Another Italian dish 1
## 2 ice cream The perfect snack in summer 2
## 3 pizza Italian dish, I actually prefer mine with little cheese 3
## 4 crisps Potatoes and oil - a luxurious combination 4
## 5 passion fruit A fruit that makes me think about vacation 5</code></pre>
</div>
</div>
<div id="solutions-for-exercise-2" class="section level2 unnumbered">
<h2>Solutions for Exercise 2</h2>
<div id="task-1-8" class="section level3 unnumbered">
<h3>Task 1</h3>
<p>Below you will see multiple choice questions. Please try to identify the correct answers. 1, 2, 3 and 4 correct answers are possible for each question.</p>
<p><strong>1. What are the main characteristics of tidy data?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li>Every observation is a row. (x)</li>
</ul>
<p><strong>2. What are <code>dplyr</code> functions?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li><code>mutate()</code> (x)</li>
</ul>
<p><strong>3. How can you sort the eye_color of Star Wars characters from Z to A?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li><code>starwars_data %>% arrange(desc(eye_color))</code> (x)</li>
<li><code>starwars_data %>% select(eye_color) %>% arrange(desc(eye_color))</code> (x)</li>
</ul>
<p><strong>4. Imagine you want to recode the height of the these characters. You want to have three categories from small and medium to tall. What is a valid approach?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li><code>starwars_data %>% mutate(height = case_when(height<=150~"small",height<=190~"medium",height>190~"tall"))</code> (x)</li>
</ul>
<p><strong>5. Imagine you want to provide a systematic overview over all hair colors and what species wear these hair colors frequently (not accounting for the skewed sampling of species)? What is a valid approach?</strong></p>
<p><em>Solution:</em></p>
<ul>
<li><code>starwars_data %>% group_by(hair_color, species) %>% summarize(count = n()) %>% arrange(hair_color)</code> (x)</li>
</ul>
</div>
<div id="task-2-8" class="section level3 unnumbered">
<h3>Task 2</h3>
<p>Now it’s you turn. Load the starwars data like this:</p>
<div class="sourceCode" id="cb347"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb347-1"><a href="solutions.html#cb347-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dplyr) <span class="co"># to activate the dplyr package</span></span>
<span id="cb347-2"><a href="solutions.html#cb347-2" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="ot"><-</span> starwars <span class="co"># to assign the pre-installed starwars data set (dplyr) into a source object in our environment</span></span></code></pre></div>
<p>How many humans are contained in the starwars data overall? (Hint: use <code>summarize(count = n())</code> or <code>count()</code>)?</p>
<p><em>Solution:</em></p>
<p>You can use <code>summarize(count = n())</code>:</p>
<div class="sourceCode" id="cb348"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb348-1"><a href="solutions.html#cb348-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb348-2"><a href="solutions.html#cb348-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(species <span class="sc">==</span> <span class="st">"Human"</span>) <span class="sc">%>%</span> </span>
<span id="cb348-3"><a href="solutions.html#cb348-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">count =</span> <span class="fu">n</span>())</span></code></pre></div>
<pre><code>## # A tibble: 1 x 1
## count
## <int>
## 1 35</code></pre>
<p>Alternatively, you can use the <code>count()</code> function:</p>
<div class="sourceCode" id="cb350"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb350-1"><a href="solutions.html#cb350-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb350-2"><a href="solutions.html#cb350-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(species <span class="sc">==</span> <span class="st">"Human"</span>) <span class="sc">%>%</span> </span>
<span id="cb350-3"><a href="solutions.html#cb350-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">count</span>(species)</span></code></pre></div>
<pre><code>## # A tibble: 1 x 2
## species n
## <chr> <int>
## 1 Human 35</code></pre>
</div>
<div id="task-3-7" class="section level3 unnumbered">
<h3>Task 3</h3>
<p>How many humans are contained in starwars by gender?</p>
<p><em>Solution:</em></p>
<p>You can use <code>summarize(count = n())</code>:</p>
<div class="sourceCode" id="cb352"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb352-1"><a href="solutions.html#cb352-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb352-2"><a href="solutions.html#cb352-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(species <span class="sc">==</span> <span class="st">"Human"</span>) <span class="sc">%>%</span> </span>
<span id="cb352-3"><a href="solutions.html#cb352-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(species, gender) <span class="sc">%>%</span> </span>
<span id="cb352-4"><a href="solutions.html#cb352-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">count =</span> <span class="fu">n</span>())</span></code></pre></div>
<pre><code>## # A tibble: 2 x 3
## # Groups: species [1]
## species gender count
## <chr> <chr> <int>
## 1 Human feminine 9
## 2 Human masculine 26</code></pre>
<p>Alternatively, you can use the <code>count()</code> function:</p>
<div class="sourceCode" id="cb354"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb354-1"><a href="solutions.html#cb354-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb354-2"><a href="solutions.html#cb354-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(species <span class="sc">==</span> <span class="st">"Human"</span>) <span class="sc">%>%</span> </span>
<span id="cb354-3"><a href="solutions.html#cb354-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">count</span>(species, gender)</span></code></pre></div>
<pre><code>## # A tibble: 2 x 3
## species gender n
## <chr> <chr> <int>
## 1 Human feminine 9
## 2 Human masculine 26</code></pre>
</div>
<div id="task-4-6" class="section level3 unnumbered">
<h3>Task 4</h3>
<p>What is the most common eye_color among Star Wars characters? (Hint: use <code>arrange()</code>)__</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb356"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb356-1"><a href="solutions.html#cb356-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb356-2"><a href="solutions.html#cb356-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(eye_color) <span class="sc">%>%</span> </span>
<span id="cb356-3"><a href="solutions.html#cb356-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">count =</span> <span class="fu">n</span>()) <span class="sc">%>%</span></span>
<span id="cb356-4"><a href="solutions.html#cb356-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(<span class="fu">desc</span>(count))</span></code></pre></div>
<pre><code>## # A tibble: 15 x 2
## eye_color count
## <chr> <int>
## 1 brown 21
## 2 blue 19
## 3 yellow 11
## 4 black 10
## 5 orange 8
## 6 red 5
## 7 hazel 3
## 8 unknown 3
## 9 blue-gray 1
## 10 dark 1
## 11 gold 1
## 12 green, yellow 1
## 13 pink 1
## 14 red, blue 1
## 15 white 1</code></pre>
</div>
<div id="task-5-6" class="section level3 unnumbered">
<h3>Task 5</h3>
<p>What is the average mass of Star Wars characters that are not human and have yellow eyes? (Hint: remove all <code>NAs</code>)__</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb358"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb358-1"><a href="solutions.html#cb358-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb358-2"><a href="solutions.html#cb358-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(species <span class="sc">!=</span> <span class="st">"Human"</span> <span class="sc">&</span> eye_color<span class="sc">==</span><span class="st">"yellow"</span>) <span class="sc">%>%</span></span>
<span id="cb358-3"><a href="solutions.html#cb358-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">mean_mass =</span> <span class="fu">mean</span>(mass, <span class="at">na.rm=</span><span class="cn">TRUE</span>))</span></code></pre></div>
<pre><code>## # A tibble: 1 x 1
## mean_mass
## <dbl>
## 1 74.1</code></pre>
</div>
<div id="task-6-4" class="section level3 unnumbered">
<h3>Task 6</h3>
<p>Compare the mean, median, and standard deviation of mass for all humans and droids. (Hint: remove all <code>NAs</code>)__</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb360"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb360-1"><a href="solutions.html#cb360-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span></span>
<span id="cb360-2"><a href="solutions.html#cb360-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(species<span class="sc">==</span><span class="st">"Human"</span> <span class="sc">|</span> species<span class="sc">==</span><span class="st">"Droid"</span>) <span class="sc">%>%</span></span>
<span id="cb360-3"><a href="solutions.html#cb360-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(species) <span class="sc">%>%</span> </span>
<span id="cb360-4"><a href="solutions.html#cb360-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarize</span>(<span class="at">M =</span> <span class="fu">mean</span>(mass, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb360-5"><a href="solutions.html#cb360-5" aria-hidden="true" tabindex="-1"></a> <span class="at">Med =</span> <span class="fu">median</span>(mass, <span class="at">na.rm =</span> <span class="cn">TRUE</span>),</span>
<span id="cb360-6"><a href="solutions.html#cb360-6" aria-hidden="true" tabindex="-1"></a> <span class="at">SD =</span> <span class="fu">sd</span>(mass, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)</span>
<span id="cb360-7"><a href="solutions.html#cb360-7" aria-hidden="true" tabindex="-1"></a> )</span></code></pre></div>
<pre><code>## # A tibble: 2 x 4
## species M Med SD
## <chr> <dbl> <dbl> <dbl>
## 1 Droid 69.8 53.5 51.0
## 2 Human 82.8 79 19.4</code></pre>
</div>
<div id="task-7-2" class="section level3 unnumbered">
<h3>Task 7</h3>
<p>Create a new variable in which you store the mass in gram. Add it to the data frame.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb362"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb362-1"><a href="solutions.html#cb362-1" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="ot"><-</span> starwars_data <span class="sc">%>%</span></span>
<span id="cb362-2"><a href="solutions.html#cb362-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">gr_mass =</span> mass<span class="sc">*</span><span class="dv">1000</span>)</span>
<span id="cb362-3"><a href="solutions.html#cb362-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb362-4"><a href="solutions.html#cb362-4" aria-hidden="true" tabindex="-1"></a>starwars_data <span class="sc">%>%</span> </span>
<span id="cb362-5"><a href="solutions.html#cb362-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(name, species, mass, gr_mass)</span></code></pre></div>
<pre><code>## # A tibble: 87 x 4
## name species mass gr_mass
## <chr> <chr> <dbl> <dbl>
## 1 Luke Skywalker Human 77 77000
## 2 C-3PO Droid 75 75000
## 3 R2-D2 Droid 32 32000
## 4 Darth Vader Human 136 136000
## 5 Leia Organa Human 49 49000
## 6 Owen Lars Human 120 120000
## 7 Beru Whitesun lars Human 75 75000
## 8 R5-D4 Droid 32 32000
## 9 Biggs Darklighter Human 84 84000
## 10 Obi-Wan Kenobi Human 77 77000
## # ... with 77 more rows</code></pre>
</div>
</div>
<div id="solutions-for-exercise-3" class="section level2 unnumbered">
<h2>Solutions for Exercise 3</h2>
<div id="task-1-9" class="section level3 unnumbered">
<h3>Task 1</h3>
<p>Try to reproduce this plot with <code>dplyr</code> and <code>ggplot2</code>. (<strong>Hint:</strong> You can hide the legend by adding <code>theme(legend.position = "none")</code> to your plot.)</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb364"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb364-1"><a href="solutions.html#cb364-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> </span>
<span id="cb364-2"><a href="solutions.html#cb364-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">sex =</span> <span class="fu">case_when</span>(</span>
<span id="cb364-3"><a href="solutions.html#cb364-3" aria-hidden="true" tabindex="-1"></a> sex <span class="sc">==</span> <span class="dv">0</span> <span class="sc">~</span> <span class="st">"Female"</span>,</span>
<span id="cb364-4"><a href="solutions.html#cb364-4" aria-hidden="true" tabindex="-1"></a> sex <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="st">"Male"</span>)) <span class="sc">%>%</span></span>
<span id="cb364-5"><a href="solutions.html#cb364-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Party =</span> <span class="fu">case_when</span>(</span>
<span id="cb364-6"><a href="solutions.html#cb364-6" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="st">"Democrat"</span>,</span>
<span id="cb364-7"><a href="solutions.html#cb364-7" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> <span class="st">"Independent"</span>,</span>
<span id="cb364-8"><a href="solutions.html#cb364-8" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">3</span> <span class="sc">~</span> <span class="st">"Republican"</span>)) <span class="sc">%>%</span></span>
<span id="cb364-9"><a href="solutions.html#cb364-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>Party,<span class="at">y=</span>negemot, <span class="at">fill=</span>Party)) <span class="sc">+</span></span>
<span id="cb364-10"><a href="solutions.html#cb364-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">stat_summary</span>(<span class="at">geom =</span> <span class="st">"bar"</span>, <span class="at">fun =</span> <span class="st">"mean"</span>) <span class="sc">+</span></span>
<span id="cb364-11"><a href="solutions.html#cb364-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb364-12"><a href="solutions.html#cb364-12" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">legend.position =</span> <span class="st">"none"</span>) <span class="sc">+</span></span>
<span id="cb364-13"><a href="solutions.html#cb364-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Climate change attitudes of U.S. partisans by gender"</span>,</span>
<span id="cb364-14"><a href="solutions.html#cb364-14" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="st">"Negative emotions about climate change"</span>) <span class="sc">+</span></span>
<span id="cb364-15"><a href="solutions.html#cb364-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span>sex, <span class="at">nrow=</span><span class="dv">2</span>)</span></code></pre></div>
</div>
<div id="task-2-9" class="section level3 unnumbered">
<h3>Task 2</h3>
<p>Now, try to reproduce this graph. (<strong>Hint:</strong> You will need to recode the <em>ideology</em> variable in a way that higher values represent stronger attitudes, <em>independent of partisanship</em>.)</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb365"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb365-1"><a href="solutions.html#cb365-1" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> data <span class="sc">%>%</span> </span>
<span id="cb365-2"><a href="solutions.html#cb365-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">ideology_ext =</span> <span class="fu">case_when</span>(</span>
<span id="cb365-3"><a href="solutions.html#cb365-3" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="dv">4</span>,</span>
<span id="cb365-4"><a href="solutions.html#cb365-4" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> <span class="dv">3</span>,</span>
<span id="cb365-5"><a href="solutions.html#cb365-5" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">3</span> <span class="sc">~</span> <span class="dv">2</span>,</span>
<span id="cb365-6"><a href="solutions.html#cb365-6" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">4</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb365-7"><a href="solutions.html#cb365-7" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">5</span> <span class="sc">~</span> <span class="dv">2</span>,</span>
<span id="cb365-8"><a href="solutions.html#cb365-8" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">6</span> <span class="sc">~</span> <span class="dv">3</span>,</span>
<span id="cb365-9"><a href="solutions.html#cb365-9" aria-hidden="true" tabindex="-1"></a> ideology <span class="sc">==</span> <span class="dv">7</span> <span class="sc">~</span> <span class="dv">4</span>)) <span class="sc">%>%</span></span>
<span id="cb365-10"><a href="solutions.html#cb365-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">sex =</span> <span class="fu">case_when</span>(</span>
<span id="cb365-11"><a href="solutions.html#cb365-11" aria-hidden="true" tabindex="-1"></a> sex <span class="sc">==</span> <span class="dv">0</span> <span class="sc">~</span> <span class="st">"Female"</span>,</span>
<span id="cb365-12"><a href="solutions.html#cb365-12" aria-hidden="true" tabindex="-1"></a> sex <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="st">"Male"</span>)) <span class="sc">%>%</span></span>
<span id="cb365-13"><a href="solutions.html#cb365-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Party =</span> <span class="fu">case_when</span>(</span>
<span id="cb365-14"><a href="solutions.html#cb365-14" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="st">"Democrat"</span>,</span>
<span id="cb365-15"><a href="solutions.html#cb365-15" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> <span class="st">"Independent"</span>,</span>
<span id="cb365-16"><a href="solutions.html#cb365-16" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">3</span> <span class="sc">~</span> <span class="st">"Republican"</span>))</span></code></pre></div>
<div class="sourceCode" id="cb366"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb366-1"><a href="solutions.html#cb366-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> </span>
<span id="cb366-2"><a href="solutions.html#cb366-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>Party,<span class="at">y=</span>ideology_ext, <span class="at">fill=</span>Party)) <span class="sc">+</span></span>
<span id="cb366-3"><a href="solutions.html#cb366-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_boxplot</span>() <span class="sc">+</span></span>
<span id="cb366-4"><a href="solutions.html#cb366-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb366-5"><a href="solutions.html#cb366-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme</span>(<span class="at">legend.position =</span> <span class="st">"none"</span>) <span class="sc">+</span></span>
<span id="cb366-6"><a href="solutions.html#cb366-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Ideological extremity of U.S. partisans by gender"</span>,</span>
<span id="cb366-7"><a href="solutions.html#cb366-7" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="st">"Ideological extremity"</span>) <span class="sc">+</span></span>
<span id="cb366-8"><a href="solutions.html#cb366-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span>sex)</span></code></pre></div>
</div>
<div id="task-3-8" class="section level3 unnumbered">
<h3>Task 3</h3>
<p>Can you make a chart that breaks down the relationship between <em>age</em>, <em>negative emotions about climate change</em>, and <em>ideological extremity</em> for the different <em>sexes</em> AND <em>parties</em>?</p>
<p><em>Solution 1:</em></p>
<div class="sourceCode" id="cb367"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb367-1"><a href="solutions.html#cb367-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span></span>
<span id="cb367-2"><a href="solutions.html#cb367-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>age,<span class="at">y=</span>negemot, <span class="at">size=</span>ideology_ext, <span class="at">color =</span> Party)) <span class="sc">+</span></span>
<span id="cb367-3"><a href="solutions.html#cb367-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb367-4"><a href="solutions.html#cb367-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_size</span>(<span class="at">range =</span> <span class="fu">c</span>(<span class="fl">0.3</span>, <span class="dv">3</span>), <span class="at">name =</span> <span class="st">"Ideological extremity"</span>) <span class="sc">+</span></span>
<span id="cb367-5"><a href="solutions.html#cb367-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb367-6"><a href="solutions.html#cb367-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Relationship between age, climate change attitudes, </span><span class="sc">\n</span><span class="st"> and ideological extremity"</span>,</span>
<span id="cb367-7"><a href="solutions.html#cb367-7" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Age"</span>, <span class="at">y =</span> <span class="st">"Negative emotions about climate change"</span>) <span class="sc">+</span></span>
<span id="cb367-8"><a href="solutions.html#cb367-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_wrap</span>(<span class="sc">~</span>sex, <span class="at">nrow=</span><span class="dv">2</span>)</span></code></pre></div>
<p><img src="CPA-Seminar_files/figure-html/unnamed-chunk-181-1.png" width="672" /></p>
<p><em>Solution 2:</em></p>
<p>Alternatively, you might enjoy this look that you can create with <code>facet_grid()</code>:</p>
<div class="sourceCode" id="cb368"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb368-1"><a href="solutions.html#cb368-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> </span>
<span id="cb368-2"><a href="solutions.html#cb368-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>age,<span class="at">y=</span>negemot, <span class="at">size=</span>ideology_ext, <span class="at">color =</span> Party)) <span class="sc">+</span></span>
<span id="cb368-3"><a href="solutions.html#cb368-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb368-4"><a href="solutions.html#cb368-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_size</span>(<span class="at">range =</span> <span class="fu">c</span>(<span class="fl">0.3</span>, <span class="dv">3</span>), <span class="at">name =</span> <span class="st">"Ideological extremity"</span>) <span class="sc">+</span></span>
<span id="cb368-5"><a href="solutions.html#cb368-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb368-6"><a href="solutions.html#cb368-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Relationship between age, climate change attitudes, and ideological extremity"</span>,</span>
<span id="cb368-7"><a href="solutions.html#cb368-7" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Age"</span>, <span class="at">y =</span> <span class="st">"Negative emotions about climate change"</span>) <span class="sc">+</span></span>
<span id="cb368-8"><a href="solutions.html#cb368-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_grid</span>(<span class="fu">vars</span>(sex), <span class="fu">vars</span>(Party))</span></code></pre></div>
<p><img src="CPA-Seminar_files/figure-html/unnamed-chunk-182-1.png" width="672" /></p>
<p><em>Solution 3:</em></p>
<p>Or even this look, also done with <code>facet_grid()</code>:</p>
<div class="sourceCode" id="cb369"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb369-1"><a href="solutions.html#cb369-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> </span>
<span id="cb369-2"><a href="solutions.html#cb369-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>age,<span class="at">y=</span>negemot, <span class="at">size=</span>ideology_ext, <span class="at">color =</span> Party)) <span class="sc">+</span></span>
<span id="cb369-3"><a href="solutions.html#cb369-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_point</span>() <span class="sc">+</span></span>
<span id="cb369-4"><a href="solutions.html#cb369-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scale_size</span>(<span class="at">range =</span> <span class="fu">c</span>(<span class="fl">0.3</span>, <span class="dv">3</span>), <span class="at">name =</span> <span class="st">"Ideological extremity"</span>) <span class="sc">+</span></span>
<span id="cb369-5"><a href="solutions.html#cb369-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb369-6"><a href="solutions.html#cb369-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">title =</span> <span class="st">"Relationship between age, climate change attitudes, and ideological extremity"</span>,</span>
<span id="cb369-7"><a href="solutions.html#cb369-7" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="st">"Age"</span>, <span class="at">y =</span> <span class="st">"Negative emotions about climate change"</span>) <span class="sc">+</span></span>
<span id="cb369-8"><a href="solutions.html#cb369-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">facet_grid</span>(<span class="sc">~</span>sex <span class="sc">+</span> Party)</span></code></pre></div>
<p><img src="CPA-Seminar_files/figure-html/unnamed-chunk-183-1.png" width="672" /></p>
</div>
</div>
<div id="solutions-for-exercise-4" class="section level2 unnumbered">
<h2>Solutions for Exercise 4</h2>
<div id="task-1-10" class="section level3 unnumbered">
<h3>Task 1</h3>
<p>Let’s use the data set <em>glbwarm</em> again, which you should know well by now. Install / activate the <code>processR</code> package and assign the <em>glbwarm</em> data to a source object.</p>
<div class="sourceCode" id="cb370"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb370-1"><a href="solutions.html#cb370-1" aria-hidden="true" tabindex="-1"></a><span class="co"># installing/loading the package:</span></span>
<span id="cb370-2"><a href="solutions.html#cb370-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span>(<span class="sc">!</span><span class="fu">require</span>(processR)) {</span>
<span id="cb370-3"><a href="solutions.html#cb370-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">install.packages</span>(<span class="st">"processR"</span>); </span>
<span id="cb370-4"><a href="solutions.html#cb370-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">require</span>(processR)</span>
<span id="cb370-5"><a href="solutions.html#cb370-5" aria-hidden="true" tabindex="-1"></a>} <span class="co">#load / install+load processR</span></span>
<span id="cb370-6"><a href="solutions.html#cb370-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb370-7"><a href="solutions.html#cb370-7" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> processR<span class="sc">::</span>glbwarm</span></code></pre></div>
<p>In this task, we want to tackle simple linear regression. More specifically, we want to predict the <em>ideology</em> of our respondents by their <em>age</em> because we assume that older respondents will hold more conservative viewpoints. The higher the values of the <em>ideology</em> variable, the more conservative the respondents are (coded from 1 ‘very liberal’ to 7 ‘very conservative’).</p>
<p><strong>Research question:</strong> Do older U.S. Americans hold more conservative viewpoints than younger U.S. Americans?</p>
<p>To answer this question, prepare a visual inspection of this relationship without fitting a regression line. Can you recognize a relationship? What is its nature?</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb371"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb371-1"><a href="solutions.html#cb371-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>age, <span class="at">y=</span>ideology)) <span class="sc">+</span> </span>
<span id="cb371-2"><a href="solutions.html#cb371-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_count</span>() <span class="sc">+</span> </span>
<span id="cb371-3"><a href="solutions.html#cb371-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span> </span>
<span id="cb371-4"><a href="solutions.html#cb371-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">x=</span><span class="st">"Age"</span>, <span class="at">y=</span><span class="st">"Conservatism"</span>)</span></code></pre></div>
<p><img src="CPA-Seminar_files/figure-html/unnamed-chunk-185-1.png" width="672" /></p>
<p><strong>Evaluation:</strong> We can observe a small, positive relationship between age and conservatism. (This can be inferred from the amount of bigger bubbles clustering on the top right corner of the graph.)</p>
</div>
<div id="task-2-10" class="section level3 unnumbered">
<h3>Task 2</h3>
<p>Next, try to quantify the association using Pearson’s r. Interpret the result.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb372"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb372-1"><a href="solutions.html#cb372-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cor.test</span>(glbwarm<span class="sc">$</span>ideology,glbwarm<span class="sc">$</span>age, <span class="at">method=</span><span class="st">"pearson"</span>)</span></code></pre></div>
<pre><code>##
## Pearson's product-moment correlation
##
## data: glbwarm$ideology and glbwarm$age
## t = 6.1978, df = 813, p-value = 0.0000000009096
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1458602 0.2770376
## sample estimates:
## cor
## 0.2124056</code></pre>
<p><strong>Evaluation:</strong> There is a small, positive, and highly significant relationship between age and conservatism (r = 0.21, p < 0.001). We can conclude that older U.S. Americans are more conservative.</p>
</div>
<div id="task-3-9" class="section level3 unnumbered">
<h3>Task 3</h3>
<p>Using your graph from Task 1, fit a regression line to your data points (<strong>Hint:</strong> You will need to load the <code>ggpubr</code> package). Interpret the parameters of the regression line.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb374"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb374-1"><a href="solutions.html#cb374-1" aria-hidden="true" tabindex="-1"></a><span class="co"># installing/loading the package:</span></span>
<span id="cb374-2"><a href="solutions.html#cb374-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span>(<span class="sc">!</span><span class="fu">require</span>(ggpubr)) {</span>
<span id="cb374-3"><a href="solutions.html#cb374-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">install.packages</span>(<span class="st">"ggpubr"</span>); </span>
<span id="cb374-4"><a href="solutions.html#cb374-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">require</span>(ggpubr)</span>
<span id="cb374-5"><a href="solutions.html#cb374-5" aria-hidden="true" tabindex="-1"></a>} <span class="co">#load / install+load ggpubr</span></span></code></pre></div>
<div class="sourceCode" id="cb375"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb375-1"><a href="solutions.html#cb375-1" aria-hidden="true" tabindex="-1"></a>data <span class="sc">%>%</span> </span>
<span id="cb375-2"><a href="solutions.html#cb375-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x=</span>age, <span class="at">y=</span>ideology)) <span class="sc">+</span> </span>
<span id="cb375-3"><a href="solutions.html#cb375-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_count</span>() <span class="sc">+</span> </span>
<span id="cb375-4"><a href="solutions.html#cb375-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">theme_bw</span>() <span class="sc">+</span></span>
<span id="cb375-5"><a href="solutions.html#cb375-5" aria-hidden="true" tabindex="-1"></a><span class="co"># xlim(0,7) +</span></span>
<span id="cb375-6"><a href="solutions.html#cb375-6" aria-hidden="true" tabindex="-1"></a><span class="co"># ylim(0,7.5) +</span></span>
<span id="cb375-7"><a href="solutions.html#cb375-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">labs</span>(<span class="at">x=</span><span class="st">"Age"</span>, <span class="at">y=</span><span class="st">"Conservatism"</span>) <span class="sc">+</span> </span>
<span id="cb375-8"><a href="solutions.html#cb375-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_smooth</span>(<span class="at">method=</span><span class="st">'lm'</span>, <span class="at">formula=</span> y<span class="sc">~</span>x, <span class="at">color =</span> <span class="st">"darkred"</span>) <span class="sc">+</span></span>
<span id="cb375-9"><a href="solutions.html#cb375-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">stat_cor</span>(<span class="fu">aes</span>(<span class="at">label =</span> ..rr.label..)) <span class="sc">+</span> </span>
<span id="cb375-10"><a href="solutions.html#cb375-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">stat_regline_equation</span>(<span class="at">label.y =</span> <span class="fl">6.2</span>)</span></code></pre></div>
<p><img src="CPA-Seminar_files/figure-html/unnamed-chunk-188-1.png" width="672" /></p>
<p><strong>Evaluation:</strong> The equation is Y = 3.1 + 0.02*X. This means that a person who becomes one year older is estimated to become 0.02 points more conservative. Similarly, two U.S. Americans with an age difference of 10 years are estimated to differ by 0.2 points on the ideology scale. However, age is not a really good predictor of conservatism as the predictor only explains about 4.5% of the observed variance in conservatism scores (R<sup>2</sup>).</p>
</div>
<div id="task-4-7" class="section level3 unnumbered">
<h3>Task 4</h3>
<p>Run a linear model in R using the <em>ideology</em> and <em>age</em> variables. Interpret the results.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb376"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb376-1"><a href="solutions.html#cb376-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(<span class="fu">lm</span>(ideology <span class="sc">~</span> age,<span class="at">data=</span>data))</span></code></pre></div>
<pre><code>##
## Call:
## lm(formula = ideology ~ age, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.7807 -0.8187 0.0647 0.8091 3.3793
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.109423 0.165465 18.792 < 0.0000000000000002 ***
## age 0.019663 0.003173 6.198 0.00000000091 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.478 on 813 degrees of freedom
## Multiple R-squared: 0.04512, Adjusted R-squared: 0.04394
## F-statistic: 38.41 on 1 and 813 DF, p-value: 0.0000000009096</code></pre>
<p><strong>Evaluation:</strong> Again, we can extract the parameters for the intercept (<em>b<sub>[0]</sub></em> = 3.1), the regression coefficient (<em>b<sub>[1]</sub></em> = 0.019, <em>p</em> < 0.001), and R<sup>2</sup> = 0.045. There is a significant, positive relationship between age and conservatism, but the effect is very small (size of <em>b<sub>[1]</sub></em>).</p>
</div>
<div id="task-5-7" class="section level3 unnumbered">
<h3>Task 5</h3>
<p>Since age alone does not seem to be a good predictor of conservatism, we want to introduce other predictors into the model and run a Multiple Linear Regression. This means that we will predict the effect of age on conservatism while controlling for the effect of third variables. For example, the respondents’ gender (<em>sex</em>, 0 = female, 1 = male) and their party preference (<em>partyid</em>, 1 = Democrat, 2 = Independent, 3 = Republican) might be great predictors of conservatism.</p>
<p><strong>Note:</strong> In a linear regression model, we can only include metric variables and variables that are binary coded (0/1). However, <em>partyid</em> is a categorical, i.e. factor variable, since Democrats are coded 1, Independents 2, and Republicans 3. Therefore, you need to mutate <em>partyid</em> and create two new binary variables <em>democrat</em> (0/1) and <em>republican</em> (0/1), where 1 indicates that the respondent identifies with that political party. (You don’t need to create a variable <em>independent</em>, since that information would be redundant: someone who has a value of 0 for both <em>republican</em> AND <em>democrat</em> MUST be an independent, so you can derive party preference with just two variables).</p>
<p>Then, run a multiple linear model that predicts <em>ideology</em> by <em>sex</em>, <em>democrat</em>, <em>republican</em>, and <em>age</em>. Interpret the results and the meaning of the age coefficient.</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb378"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb378-1"><a href="solutions.html#cb378-1" aria-hidden="true" tabindex="-1"></a>data <span class="ot"><-</span> data <span class="sc">%>%</span></span>
<span id="cb378-2"><a href="solutions.html#cb378-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">democrat =</span> <span class="fu">case_when</span>(</span>
<span id="cb378-3"><a href="solutions.html#cb378-3" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="dv">1</span>,</span>
<span id="cb378-4"><a href="solutions.html#cb378-4" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> <span class="dv">0</span>,</span>
<span id="cb378-5"><a href="solutions.html#cb378-5" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">3</span> <span class="sc">~</span> <span class="dv">0</span>)) <span class="sc">%>%</span></span>
<span id="cb378-6"><a href="solutions.html#cb378-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">republican =</span> <span class="fu">case_when</span>(</span>
<span id="cb378-7"><a href="solutions.html#cb378-7" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">1</span> <span class="sc">~</span> <span class="dv">0</span>,</span>
<span id="cb378-8"><a href="solutions.html#cb378-8" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">2</span> <span class="sc">~</span> <span class="dv">0</span>,</span>
<span id="cb378-9"><a href="solutions.html#cb378-9" aria-hidden="true" tabindex="-1"></a> partyid <span class="sc">==</span> <span class="dv">3</span> <span class="sc">~</span> <span class="dv">1</span>)</span>
<span id="cb378-10"><a href="solutions.html#cb378-10" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb378-11"><a href="solutions.html#cb378-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb378-12"><a href="solutions.html#cb378-12" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(<span class="fu">lm</span>(ideology <span class="sc">~</span> sex <span class="sc">+</span> republican <span class="sc">+</span> democrat <span class="sc">+</span> age,<span class="at">data=</span>data))</span></code></pre></div>
<pre><code>##
## Call:
## lm(formula = ideology ~ sex + republican + democrat + age, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.0975 -0.9313 0.0256 0.7641 3.9739
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.504712 0.146041 23.998 < 0.0000000000000002 ***
## sex 0.158677 0.083620 1.898 0.058105 .
## republican 1.251718 0.113609 11.018 < 0.0000000000000002 ***
## democrat -0.848157 0.105368 -8.049 0.00000000000000296 ***
## age 0.009475 0.002610 3.630 0.000301 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.171 on 810 degrees of freedom
## Multiple R-squared: 0.4031, Adjusted R-squared: 0.4002
## F-statistic: 136.8 on 4 and 810 DF, p-value: < 0.00000000000000022</code></pre>
<p><strong>Evaluation:</strong> Compared to our simple model, the R<sup>2</sup> has increased dramatically, from 0.045 to 0.403! We can now explain 40.3% of the variance in conservatism with the newly introduced covariates. While gender is not a significant predictor of conservatism (<em>b<sub>[1]</sub></em> = 0.158, p = 0.058), i.e., there is no significant difference in conservatism between men and women, party preference plays a large role in explaining conservative viewpoints. Republicans are more conservative (<em>b<sub>[2]</sub></em> = 1.251, p < 0.001) than Independents (reference category, not included as a separate variable), while Democrats are less conservative than Independents (<em>b<sub>[3]</sub></em> = -0.848, p < 0.001). The size of the effect that age has on conservatism has decreased further now that we control for sex and party preference (<em>b<sub>[4]</sub></em> = 0.009, p < 0.001). This implies that some of the effects of age are now transported through sex and, more likely, party preference. We can conclude that two U.S. citizens who differ by 10 years but have the same gender and party preference are estimated to differ by 0.09 points on the conservatism scale. That’s a really small effect, but it’s still significant.</p>
</div>
<div id="task-6-5" class="section level3 unnumbered">
<h3>Task 6</h3>
<p>Standardize all relevant variables and run the model again (note that binary variables shouldn’t be standardized). How does the interpretation of the age coefficient change?</p>
<p><em>Solution:</em></p>
<div class="sourceCode" id="cb380"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb380-1"><a href="solutions.html#cb380-1" aria-hidden="true" tabindex="-1"></a>data<span class="sc">$</span>ideology_st <span class="ot"><-</span> <span class="fu">scale</span>(data<span class="sc">$</span>ideology)</span>
<span id="cb380-2"><a href="solutions.html#cb380-2" aria-hidden="true" tabindex="-1"></a>data<span class="sc">$</span>age_st <span class="ot"><-</span> <span class="fu">scale</span>(data<span class="sc">$</span>age)</span>
<span id="cb380-3"><a href="solutions.html#cb380-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb380-4"><a href="solutions.html#cb380-4" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(<span class="fu">lm</span>(ideology_st <span class="sc">~</span> sex <span class="sc">+</span> republican <span class="sc">+</span> democrat <span class="sc">+</span> age_st,<span class="at">data=</span>data))</span></code></pre></div>
<pre><code>##
## Call:
## lm(formula = ideology_st ~ sex + republican + democrat + age_st,
## data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.71045 -0.61607 0.01696 0.50543 2.62866
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.07233 0.06386 -1.133 0.257702
## sex 0.10496 0.05531 1.898 0.058105 .
## republican 0.82799 0.07515 11.018 < 0.0000000000000002 ***
## democrat -0.56104 0.06970 -8.049 0.00000000000000296 ***
## age_st 0.10236 0.02819 3.630 0.000301 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7745 on 810 degrees of freedom
## Multiple R-squared: 0.4031, Adjusted R-squared: 0.4002
## F-statistic: 136.8 on 4 and 810 DF, p-value: < 0.00000000000000022</code></pre>
<p><strong>Evaluation:</strong> The age coefficient is now expressed in standard deviations from the mean: Two U.S. Americans with one standard deviation difference in their age are expected to rank <em>b<sub>[4]</sub></em> = 0.102 (p < 0.001) standard deviations higher on the conservatism scale, when controlling for the influence of sex and party preference. If we had a second standardized coefficient in the model, then we could compare their effect sizes directly.</p>
</div>
</div>
<div id="solutions-for-exercise-5" class="section level2 unnumbered">
<h2>Solutions for Exercise 5</h2>
<p>In this Exercise, we will work with the <em>pmi</em> data set. It’s a data set of a communication science experiment that was conducted by Tal-Or, Cohen, Tsfati, & Gunther in 2010 and comes pre-installed with <code>processR</code>. The data set contains 123 observations of 6 variables. There are three variables of interest to us in this data set:</p>
<ol style="list-style-type: decimal">
<li><p><strong>cond:</strong> article about sugar shortage was placed at the front (1) or interior (0) page of a newspaper</p></li>
<li><p><strong>pmi</strong>: belief that others will be prompted to buy sugar as a result of exposure to the article (scale: 1-7)</p></li>
<li><p><strong>reaction:</strong> intention to buy sugar (scale: 1-7)</p></li>
</ol>
<p>Let’s load <code>processR</code> and save the <em>pmi</em> data to a source object called <em>data</em>:</p>
<div class="sourceCode" id="cb382"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb382-1"><a href="solutions.html#cb382-1" aria-hidden="true" tabindex="-1"></a><span class="co"># installing/loading the package:</span></span>