STATISTIEK 5
INHOUDSOPGAVE
principe van het boek ............................................................................................................................. 6
1 visualization ........................................................................................................................................ 6
te gebruiken functies.................................................................................................................................. 6
our data: happiness vs. GDP (per capita) across the world ........................................................................... 8
the “mise en place”: setting up ................................................................................................................... 8
visualization: let’s start simple! .................................................................................................................. 9
data ....................................................................................................................................................... 9
mapping ............................................................................................................................................... 10
geoms .................................................................................................................................................. 10
multiple geoms..................................................................................................................................... 11
assigning plots to objects ...................................................................................................................... 11
combining plots .................................................................................................................................... 11
saving plots .......................................................................................................................................... 11
flexible smooth regression line .............................................................................................................. 12
customizing plots .................................................................................................................................... 12
styling geoms ....................................................................................................................................... 12
setting aesthetics overall versus by category.......................................................................................... 12
logarithmic axes ................................................................................................................................... 12
separate lines per group........................................................................................................................ 13
format axes .......................................................................................................................................... 13
axis limits ............................................................................................................................................. 13
making dots proportional to population size........................................................................................... 13
themes................................................................................................................................................. 13
adding tekst to the plot ......................................................................................................................... 14
other plot types ....................................................................................................................................... 14
bar plot: categorieën tellen ................................................................................................................... 14
column plot .......................................................................................................................................... 14
pie chart ............................................................................................................................................... 14
one continuous variable ........................................................................................................................ 14
other visualizations of distributions ....................................................................................................... 15
more visualisations .................................................................................................................................. 15
conclusion on plotting.............................................................................................................................. 15
On the use of AI ....................................................................................................................................... 15
code checking and debugging ............................................................................................................... 15
code review .......................................................................................................................................... 15
code generation.................................................................................................................................... 16
uitleg functies .......................................................................................................................................... 16
read_csv() ............................................................................................................................................ 16
read_csv2() .......................................................................................................................................... 16
read_tsv() ............................................................................................................................................. 16
read_delim() ......................................................................................................................................... 17
scale_x_continuous() ............................................................................................................................ 17
1
, geom_boxplot() .................................................................................................................................... 17
2 workflow basics ................................................................................................................................ 19
leerdoelen ............................................................................................................................................... 19
functions used ......................................................................................................................................... 19
workflow basics ....................................................................................................................................... 20
folder structure and naming .................................................................................................................. 20
R project .............................................................................................................................................. 21
code style............................................................................................................................................. 22
import data: cvs files ................................................................................................................................ 23
the reverse operation: Saving data in a csv file........................................................................................ 23
some common problems when importing data.......................................................................................... 24
wrong file path or directory .................................................................................................................... 24
missing values ...................................................................................................................................... 24
unexpected variable types .................................................................................................................... 24
european decimal seperators ............................................................................................................... 24
problem with variable names ................................................................................................................ 24
import other data types ............................................................................................................................ 24
Rdata en rds ......................................................................................................................................... 24
SPSS data files ..................................................................................................................................... 26
excel files ............................................................................................................................................. 26
variable types .......................................................................................................................................... 26
logical vectors ...................................................................................................................................... 26
numbers .............................................................................................................................................. 28
strings .................................................................................................................................................. 28
factors ................................................................................................................................................. 28
dates and times .................................................................................................................................... 29
missing values ...................................................................................................................................... 29
les 2 extra info ......................................................................................................................................... 29
uitleg functies .......................................................................................................................................... 29
dim() .................................................................................................................................................... 29
readRDS()............................................................................................................................................. 30
read_rds() ............................................................................................................................................. 30
glimpse() .............................................................................................................................................. 30
as_factor() ............................................................................................................................................ 32
levels() ................................................................................................................................................. 33
3 data transformation ........................................................................................................................... 34
leerdoelen ............................................................................................................................................... 34
functions used ......................................................................................................................................... 34
example data .......................................................................................................................................... 35
the basics of dplyr.................................................................................................................................... 35
the piping operator: |> .............................................................................................................................. 35
operations on rows .................................................................................................................................. 36
filter() ................................................................................................................................................... 36
arrange() .............................................................................................................................................. 36
distinct()............................................................................................................................................... 37
operations on columns ............................................................................................................................ 37
select() ................................................................................................................................................. 37
Statistiek 5 – samenvatting 2
, mutate() ............................................................................................................................................... 38
rename() .............................................................................................................................................. 38
relocate() ............................................................................................................................................. 39
groups..................................................................................................................................................... 39
group_by() ............................................................................................................................................ 39
summarize() (of summarise()) ............................................................................................................... 39
slice_*()................................................................................................................................................ 40
grouping by multiple variables ............................................................................................................... 40
ungrouping ........................................................................................................................................... 40
.by ....................................................................................................................................................... 40
the pipe returns ....................................................................................................................................... 41
save each intermediate object as a new one .......................................................................................... 41
overwrite the object many times ............................................................................................................ 41
composite function .............................................................................................................................. 41
saving data .............................................................................................................................................. 41
andere functies ....................................................................................................................................... 42
count() ................................................................................................................................................. 42
case_when() ......................................................................................................................................... 42
if_else() ................................................................................................................................................ 42
starts_with(), ends_with(), contains(), num_range() ................................................................................ 43
les 3 extra info ......................................................................................................................................... 43
chapter 4: reproducible reports ............................................................................................................ 44
learning objectives ................................................................................................................................... 44
functions used ......................................................................................................................................... 44
required packages ................................................................................................................................... 44
why use reproducible reports? ................................................................................................................. 44
projects................................................................................................................................................... 45
introduction to quarto .............................................................................................................................. 45
wat is het? ............................................................................................................................................ 45
waarom gebruiken we het?.................................................................................................................... 45
starten met quarto ................................................................................................................................ 45
quarti syntax and structure.................................................................................................................... 46
writing a report ........................................................................................................................................ 58
setup chunk ......................................................................................................................................... 58
chunk options ...................................................................................................................................... 59
online source ....................................................................................................................................... 59
local data files ...................................................................................................................................... 59
data analysis ........................................................................................................................................ 60
code comments ................................................................................................................................... 60
images ................................................................................................................................................. 60
tables................................................................................................................................................... 60
cross references ................................................................................................................................... 60
exploring the palmerpeguins dataset ........................................................................................................ 61
code .................................................................................................................................................... 61
including visual Elements...................................................................................................................... 61
cross-references .................................................................................................................................. 62
chapter 5: data tidying .......................................................................................................................... 63
Intended Learning Outcomes ................................................................................................................... 63
Statistiek 5 – samenvatting 3
, functions used ......................................................................................................................................... 63
set-up ..................................................................................................................................................... 63
tidy and untidy data.................................................................................................................................. 63
untidy data ........................................................................................................................................... 64
tidy data ............................................................................................................................................... 64
reshaping data......................................................................................................................................... 64
wide to long .......................................................................................................................................... 65
long to wide .......................................................................................................................................... 65
les 5 ........................................................................................................................................................ 67
chapter 6: planning a study ................................................................................................................... 68
introduction............................................................................................................................................. 68
factors influencing statistical power ......................................................................................................... 68
methods for conducting power analysis .................................................................................................... 70
the superpower package .......................................................................................................................... 70
specifying the design ............................................................................................................................ 71
One-way ANOVA...................................................................................................................................... 72
ANOVA_power ...................................................................................................................................... 72
plot_power ........................................................................................................................................... 73
Two-way ANOVA ...................................................................................................................................... 73
additional considerations ......................................................................................................................... 74
what else can superpower do? .............................................................................................................. 74
alternative packages and software ........................................................................................................ 74
les 6 ........................................................................................................................................................ 75
chapter 7: data relations....................................................................................................................... 76
intended learning outcomes ..................................................................................................................... 76
functions used ......................................................................................................................................... 76
loading data ............................................................................................................................................ 76
mutating joins .......................................................................................................................................... 76
left_join() .............................................................................................................................................. 76
right_join() ............................................................................................................................................ 76
inner_join() ........................................................................................................................................... 77
full_join() .............................................................................................................................................. 77
filtering hoins ........................................................................................................................................... 77
semi_join() ........................................................................................................................................... 77
anti-join() ............................................................................................................................................. 77
multiple joins........................................................................................................................................... 77
binding joins ............................................................................................................................................ 78
Bind_rows() .......................................................................................................................................... 78
Bind_cols() ........................................................................................................................................... 78
set operations ......................................................................................................................................... 78
intersect() ............................................................................................................................................ 78
union() ................................................................................................................................................. 79
setdiff() ................................................................................................................................................ 79
les 7..................................................................................................................................................... 80
Statistiek 5 – samenvatting 4