diff --git a/book/06-corsi-analysis.Rmd b/book/06-corsi-analysis.Rmd index a0d7f15..532882a 100644 --- a/book/06-corsi-analysis.Rmd +++ b/book/06-corsi-analysis.Rmd @@ -3,47 +3,11 @@ ```{r echo = FALSE, message=FALSE, warning=FALSE} library(tidyverse) - -# Set the seed for reproducibility -set.seed(123) - -# Define the number of participants -n_participants <- 600 - -# Define the variables -Gender <- c(rep('Woman', n_participants * 0.5), - rep('Man', n_participants * 0.40), - rep('Non-Binary', n_participants * 0.1)) - -Age <- sample(18:60, n_participants, replace = TRUE) - -# Set conditions and mean Corsi scores -Condition <- c(rep('8 hours sleep', n_participants * 1/3), - rep('4 hours sleep', n_participants * 1/3), - rep('Sleep deprived', n_participants * 1/3)) - -Mean_Corsi_Score <- ifelse(Condition == '8 hours sleep', 6, ifelse(Condition == '4 hours sleep', 5, 4)) - -# Simulate Corsi scores around mean, considering a small correlation with age -Corsi_Score <- round(rnorm(n_participants, Mean_Corsi_Score + 0.01*(Age - mean(Age)), sd = 1)) -Corsi_Score <- ifelse(Corsi_Score > 9, 9, ifelse(Corsi_Score < 0, 0, Corsi_Score)) - -# Create a data frame -data <- data.frame(Participant = 1:n_participants, - Gender = sample(Gender), - Age = Age, - Condition = Condition, - Corsi_Score = Corsi_Score) - -# Define Demographic data -demographic_data <- data %>% - select(Participant, Gender, Age, Condition) - -# Define Score data -score_data <- data %>% - select(Participant, Corsi_Score) - -full_dat <- inner_join(x = demographic_data, y = score_data, by = "Participant") +demographic_data <- read_csv("data/corsi/demographic_data.csv") +score_data <- read_csv("data/corsi/score_data.csv") +full_dat <- inner_join(x = demographic_data, + y = score_data, + by = "Participant") ``` @@ -215,7 +179,7 @@ age_control <- analysis_data %>% `r unhide()` -How many participants are left in the sample after filtering for age? `r fitb(163)` +How many participants are left in the sample after filtering for age? `r fitb(168)` ## Activity 5: Summarise diff --git a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png index 61a5391..346ff17 100644 Binary files a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png and b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png differ diff --git a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png index 4b10cb1..d704c0c 100644 Binary files a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png and b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png index d5783cf..836873d 100644 Binary files a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png and b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png differ diff --git a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png index d578591..54780c5 100644 Binary files a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png and b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png differ diff --git a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png index 62fe167..132c566 100644 Binary files a/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png and b/book/_bookdown_files/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png differ diff --git a/book/packages.bib b/book/packages.bib index dd14b25..76d3d7d 100644 --- a/book/packages.bib +++ b/book/packages.bib @@ -23,6 +23,14 @@ @Manual{R-dplyr url = {https://CRAN.R-project.org/package=dplyr}, } +@Manual{R-faux, + title = {faux: Simulation for Factorial Designs}, + author = {Lisa DeBruine}, + year = {2023}, + note = {R package version 1.2.1}, + url = {https://github.com/debruine/faux}, +} + @Manual{R-forcats, title = {forcats: Tools for Working with Categorical Variables (Factors)}, author = {Hadley Wickham}, @@ -40,11 +48,26 @@ @Manual{R-ggplot2 } @Manual{R-glossary, - title = {glossary: Glossaries for Markdown and Quarto Documents}, + title = {glossary: PsyTeachR Glossary of Statistical and Coding Terms}, author = {Lisa DeBruine}, + year = {2022}, + note = {R package version 0.0.0.9002}, +} + +@Manual{R-kableExtra, + title = {kableExtra: Construct Complex Table with kable and Pipe Syntax}, + author = {Hao Zhu}, + year = {2021}, + note = {R package version 1.3.4}, + url = {https://CRAN.R-project.org/package=kableExtra}, +} + +@Manual{R-knitr, + title = {knitr: A General-Purpose Package for Dynamic Report Generation in R}, + author = {Yihui Xie}, year = {2023}, - note = {R package version 1.0.0}, - url = {https://CRAN.R-project.org/package=glossary}, + note = {R package version 1.42}, + url = {https://yihui.org/knitr/}, } @Manual{R-lubridate, @@ -71,6 +94,14 @@ @Manual{R-readr url = {https://CRAN.R-project.org/package=readr}, } +@Manual{R-rvest, + title = {rvest: Easily Harvest (Scrape) Web Pages}, + author = {Hadley Wickham}, + year = {2022}, + note = {R package version 1.0.3}, + url = {https://CRAN.R-project.org/package=rvest}, +} + @Manual{R-stringr, title = {stringr: Simple, Consistent Wrappers for Common String Operations}, author = {Hadley Wickham}, @@ -121,6 +152,14 @@ @Manual{R-webexercises url = {https://github.com/psyteachr/webexercises}, } +@Manual{R-xml2, + title = {xml2: Parse XML}, + author = {Hadley Wickham and Jim Hester and Jeroen Ooms}, + year = {2023}, + note = {R package version 1.3.4}, + url = {https://CRAN.R-project.org/package=xml2}, +} + @Book{bookdown2016, title = {bookdown: Authoring Books and Technical Documents with {R} Markdown}, author = {Yihui Xie}, @@ -140,6 +179,38 @@ @Book{ggplot22016 url = {https://ggplot2.tidyverse.org}, } +@Manual{glossary2022, + title = {PsyTeachR Glossary of Statistical and Coding Terms}, + author = {{PsyTeachR Team}}, + year = {2022}, + url = {https://psyteachr.github.io/glossary/}, + doi = {10.5281/zenodo.6619215}, + version = {0.0.0.9002}, + publisher = {Zenodo}, + note = {v0.0.0.9002}, +} + +@Book{knitr2015, + title = {Dynamic Documents with {R} and knitr}, + author = {Yihui Xie}, + publisher = {Chapman and Hall/CRC}, + address = {Boca Raton, Florida}, + year = {2015}, + edition = {2nd}, + note = {ISBN 978-1498716963}, + url = {https://yihui.org/knitr/}, +} + +@InCollection{knitr2014, + booktitle = {Implementing Reproducible Computational Research}, + editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng}, + title = {knitr: A Comprehensive Tool for Reproducible Research in {R}}, + author = {Yihui Xie}, + publisher = {Chapman and Hall/CRC}, + year = {2014}, + note = {ISBN 978-1466561595}, +} + @Article{lubridate2011, title = {Dates and Times Made Easy with {lubridate}}, author = {Garrett Grolemund and Hadley Wickham}, diff --git a/book/template.rds b/book/template.rds index eea2e41..8f02783 100644 Binary files a/book/template.rds and b/book/template.rds differ diff --git a/docs/01-intro.md b/docs/01-intro.md index 2be6d93..bd1d053 100644 --- a/docs/01-intro.md +++ b/docs/01-intro.md @@ -19,7 +19,7 @@ There is a walkthrough video of this chapter available via [Echo360.](https://ec ## R and RStudio {#sec-intro-r} -R is a programming language that you will write code in. RStudio is an Integrated Development Environment (IDE). Think of it as knowing English and using a plain text editor like NotePad to write a book versus using a word processor like Microsoft Word. You could do it, but it would be much harder without things like spell-checking and formatting and you wouldn't be able to use some of the advanced features that Word has developed. In a similar way, you can use R without R Studio but we wouldn't recommend it. RStudio serves as a text editor, file manager, spreadsheet viewer, and more. +R is a programming language that you will write code in. RStudio is an Integrated Development Environment (IDE). Think of it as knowing English and using a plain text editor like NotePad to write a book versus using a word processor like Microsoft Word. You could do it, but it would be much harder without things like spell-checking and formatting and you wouldn't be able to use some of the advanced features that Word has developed. In a similar way, you can use R without R Studio but we wouldn't recommend it. RStudio serves as a text editor, file manager, spreadsheet viewer, and more. * There's an [RStudio IDE Cheatsheet](https://raw.githubusercontent.com/rstudio/cheatsheets/main/rstudio-ide.pdf){download=""} you will find helpful to download and keep as a reference. @@ -72,7 +72,7 @@ Do the following, in this order: ## RStudio panes -RStudio is arranged with four window panes. By default, the upper left pane is the **source pane**, where you view, write, and edit code from files and view data tables in a spreadsheet format. **When you first open a new project this pane won't display until you open a document or load in some data** -- don't worry, we'll get to that soon. +RStudio is arranged with four window panes. By default, the upper left pane is the **source pane**, where you view, write, and edit code from files and view data tables in a spreadsheet format. **When you first open a new project this pane won't display until you open a document or load in some data** -- don't worry, we'll get to that soon.
The RStudio IDE @@ -85,7 +85,7 @@ The lower left pane is the **console pane**, where you can type in commands and Try using the console as a calculator - type `1 + 1` and press enter. ::: -The right panes have several different tabs that show you information about your code. The most used tab in the upper right pane is the **Environment** tab. The Environment tab lists some information about the objects that you have defined in your code. +The right panes have several different tabs that show you information about your code. The most used tab in the upper right pane is the **Environment** tab. The Environment tab lists some information about the objects that you have defined in your code. In the lower right pane, the most used tabs are the **Files** tab for directory structure, the **Plots** tab for plots, the **Packages** tab for managing add-on packages (we'll explain what these are in the next chapter), and the **Viewer** tab to display reports created by your scripts. You can change the location of panes and what tabs are shown under `Tools > Global Options... > Pane Layout`. When you open a new project, the Files tab will be set to your project working directory and will show a file with the file extension `.Rproj` which is the file that has all the information about your project. Don't delete this file! @@ -141,8 +141,8 @@ birthday <- as.Date("2024-07-11") You'll see that four objects now appear in the environment pane: -* `name` is character (text) data. In order for R to recognise it as text, it **must** be enclosed in double quotation marks `" "`. -* `age` is numeric data. In order for R to recognise this as a number, it **must not** be enclosed in quotation marks. Every year I have to update my age in this book and I am confronted with my own mortality drawing ever closer. +* `name` is character (text) data. In order for R to recognise it as text, it **must** be enclosed in double quotation marks `" "`. +* `age` is numeric data. In order for R to recognise this as a number, it **must not** be enclosed in quotation marks. Every year I have to update my age in this book and I am confronted with my own mortality drawing ever closer. * `today` stores the result of the function `Sys.Date()`. This function returns your computer system's date. Unlike `name` and `age`, which are hard-coded (i.e., they will always return the values you enter), the contents of the object `today` will change dynamically with the date. That is, if you run that function tomorrow, it will update the date to tomorrow's date. * `birthday` is also a date but it's hard-coded as a specific date. It's wrapped within the `as.Date()` function that tells R to interpret the character string you provide as a date rather than text. @@ -258,7 +258,7 @@ My name is `r name` and I am `r age` years old. It is `r birthday - today` days As if by magic, that slightly odd bit of text you copied and pasted now appears as a normal sentence with the values pulled in from the objects you created. -**My name is Emily and I am 38 years old. It is 271 days until my birthday.** +**My name is Emily and I am 38 years old. It is 268 days until my birthday.** We're not going to use this function very often in the rest of the course but hopefully you can see just how useful this would be when writing up a report with lots of numbers. R Markdown is an incredibly powerful and flexible format - this book was written using it! @@ -311,24 +311,24 @@ The glossary at the end of each chapter defines common jargon you might encounte - character - + [character](https://psyteachr.github.io/glossary/c.html#character){class="glossary" target="_blank"} + A data type representing strings of text. - IDE - + [ide](https://psyteachr.github.io/glossary/i.html#ide){class="glossary" target="_blank"} + Integrated Development Environment: a program that serves as a text editor, file manager, and provides functions to help you read and write code. RStudio is an IDE for R. - numeric - + [numeric](https://psyteachr.github.io/glossary/n.html#numeric){class="glossary" target="_blank"} + A data type representing a real decimal number or integer. - object - + [object](https://psyteachr.github.io/glossary/o.html#object){class="glossary" target="_blank"} + A word that identifies and stores the value of some data for later use. - panes - + [panes](https://psyteachr.github.io/glossary/p.html#panes){class="glossary" target="_blank"} + RStudio is arranged with four window "panes". diff --git a/docs/02-stroop.md b/docs/02-stroop.md index 26942cc..fcf8a48 100644 --- a/docs/02-stroop.md +++ b/docs/02-stroop.md @@ -112,36 +112,102 @@ The server will automatically unzip the files for you into your chosen folder an The zip file contains four files: * `stroop_stub1.Rmd` and `stroop_stub2.Rmd`: to help you out in the first semester, we'll provide pre-formatted Markdown files ("stub" files) that contain code chunks for each activity and spaces for you to take notes. Open `stroop_sub1.Rmd` by clicking on it in the Files tab and then edit the heading to add in your GUID and today's date. -* `participant_data.csv` is a data file that contains each participant's anonymous ID, age, and gender. This data is in wide-form which means that all of the observations about one subject are in the same row. There are 270 participants, so there are 270 rows of data. +* `participant_data.csv` is a data file that contains each participant's anonymous ID, age, and gender. This data is in wide-form which means that all of the observations about one subject are in the same row. There are 270 participants, so there are 270 rows of data.
-| participant_id|gender | age| -|--------------:|:------|---:| -| 1|Man | 20| -| 2|Man | 20| -| 3|Man | 27| -| 4|Man | 19| -| 5|Man | 23| -| 6|Man | 28| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
participant_id gender age
1 Man 20
2 Man 20
3 Man 27
4 Man 19
5 Man 23
6 Man 28
-* `experiment_data.csv` is a data file that contains each participant's anonymous ID, and mean reaction time for all the congruent and incongruent trials they completed. This data is in long-form where each observation is on a separate row so for the Stroop experiment, each participant has two rows because there are two observations (one for congruent trials and one for incongruent trials). So there are 270 participants, but 540 rows of data (270 * 2). +* `experiment_data.csv` is a data file that contains each participant's anonymous ID, and mean reaction time for all the congruent and incongruent trials they completed. This data is in long-form where each observation is on a separate row so for the Stroop experiment, each participant has two rows because there are two observations (one for congruent trials and one for incongruent trials). So there are 270 participants, but 540 rows of data (270 * 2). You may be less familiar with this way of organising data, but for many functions in R your data must be stored this way. This semester, we'll provide you with the data in the format it needs to be in and next semester we'll show you how to transform it yourself.
-| participant_id|condition | reaction_time| -|--------------:|:-----------|-------------:| -| 1|congruent | 847.0311| -| 1|incongruent | 910.3084| -| 2|congruent | 748.1366| -| 2|incongruent | 967.4626| -| 3|congruent | 786.2370| -| 3|incongruent | 975.7407| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
participant_id condition reaction_time
1 congruent 847.0311
1 incongruent 910.3084
2 congruent 748.1366
2 incongruent 967.4626
3 congruent 786.2370
3 incongruent 975.7407
@@ -149,11 +215,11 @@ Before we load in and work with the data files we need to explain a few more thi ## Packages and functions {#sec-packages} -When you install R you will have access to a range of functions including options for data wrangling and statistical analysis. The functions that are included in the default installation are typically referred to as base R and you can think of them like the default apps that come pre-loaded on your phone. +When you install R you will have access to a range of functions including options for data wrangling and statistical analysis. The functions that are included in the default installation are typically referred to as base R and you can think of them like the default apps that come pre-loaded on your phone. -One of the great things about R, however, is that it is **user extensible**: anyone can create a new add-on that extends its functionality. There are currently thousands of packages that R users have created to solve many different kinds of problems, or just simply to have fun. For example, there are packages for data visualisation, machine learning, interactive dashboards, web scraping, and playing games such as Sudoku. +One of the great things about R, however, is that it is **user extensible**: anyone can create a new add-on that extends its functionality. There are currently thousands of packages that R users have created to solve many different kinds of problems, or just simply to have fun. For example, there are packages for data visualisation, machine learning, interactive dashboards, web scraping, and playing games such as Sudoku. -Add-on packages are not included with base R, but have to be downloaded and installed from an archive, in the same way that you would, for instance, download and install PokemonGo on your smartphone. The main repository where packages reside is called CRAN, the Comprehensive R Archive Network. +Add-on packages are not included with base R, but have to be downloaded and installed from an archive, in the same way that you would, for instance, download and install PokemonGo on your smartphone. The main repository where packages reside is called CRAN, the Comprehensive R Archive Network. There is an important distinction between **installing** a package and **loading** a package. @@ -180,11 +246,15 @@ As an example, let's load the cowsay package which library(cowsay) ``` +``` +## Warning: package 'cowsay' was built under R version 4.3.1 +``` + You'll see `library(cowsay)` appear in the console. There's no warning messages or errors so it looks like it has loaded successfully. ### Using a function -Now you can use the function `say()`. A function is a name that refers to code that performs some sort of action. +Now you can use the function `say()`. A function is a name that refers to code that performs some sort of action. * In code chunk 2, write and run the below code to use the function `say()`. * If you get the error `could not find function` it means you have not loaded the package properly, try running `library(cowsay)` again and make sure everything is spelled exactly right. @@ -215,7 +285,7 @@ say() ## ``` -After the function name, there is a pair of parentheses, which contain zero or more arguments. These are options that you can set. If you don't give it any information, it will try and use the default arguments if it has them. `say()` has two main arguments with a default value: `what` the text says (default `Hello world`), and the animal the message is said `by` (default is a cat). +After the function name, there is a pair of parentheses, which contain zero or more arguments. These are options that you can set. If you don't give it any information, it will try and use the default arguments if it has them. `say()` has two main arguments with a default value: `what` the text says (default `Hello world`), and the animal the message is said `by` (default is a cat). To look up all the various options that you could use with `say()`, run the following code in the console: @@ -236,7 +306,7 @@ say(what = "Do or do not, there is no try", ### Function Help {#sec-function-help} -If you want more information about what a function does or how to use it, you can look at the help document. If a function is in base R or a package you have loaded, you can type `?function_name` in the console to access the help file. At the top of the help it will give you the function and package name. +If you want more information about what a function does or how to use it, you can look at the help document. If a function is in base R or a package you have loaded, you can type `?function_name` in the console to access the help file. At the top of the help it will give you the function and package name. If the package isn't loaded, use `?package_name::function_name`. When you aren't sure what package the function is in, use the shortcut `??function_name` which will give you a list of all possible options. @@ -257,7 +327,7 @@ If the package isn't loaded, use `?package_name::function_name`. When you aren't ??say ``` -Function help is always organised in the same way. For example, look at the help for `?cowsay::say`. At the top, it tells you the name of the function and its package in curly brackets, then a short description of the function, followed by a longer description. The **Usage** section shows the function with all of its arguments. If any of those arguments have default values, they will be shown like `function(arg = default)`. The **Arguments** section lists each argument with an explanation. There may be a **Details** section after this with even more detail about the functions. The **Examples** section is last, and shows examples that you can run in your console window to see how the function works. +Function help is always organised in the same way. For example, look at the help for `?cowsay::say`. At the top, it tells you the name of the function and its package in curly brackets, then a short description of the function, followed by a longer description. The **Usage** section shows the function with all of its arguments. If any of those arguments have default values, they will be shown like `function(arg = default)`. The **Arguments** section lists each argument with an explanation. There may be a **Details** section after this with even more detail about the functions. The **Examples** section is last, and shows examples that you can run in your console window to see how the function works. ::: {.callout-note .try style="clear: both;"} @@ -280,8 +350,8 @@ OK, let's get back to looking at our data. In order to load and work with our St - tibble, for tables - tidyr, for data tidying - dplyr, for data manipulation -- stringr, for strings -- forcats, for factors +- stringr, for strings +- forcats, for factors - purrr, for repeating things To use readr to import the data, we need to load the tidyverse. diff --git a/docs/03-stroop-analysis.md b/docs/03-stroop-analysis.md index 28be056..dbc228b 100644 --- a/docs/03-stroop-analysis.md +++ b/docs/03-stroop-analysis.md @@ -131,9 +131,18 @@ ppt_info %>%
-| n| -|---:| -| 270| + + + + + + + + + + + +
n
270
@@ -147,11 +156,28 @@ ppt_info %>%
-|gender | n| -|:----------|---:| -|Man | 100| -|Non-Binary | 50| -|Woman | 120| + + + + + + + + + + + + + + + + + + + + + +
gender n
Man 100
Non-Binary 50
Woman 120
@@ -176,9 +202,18 @@ ppt_info %>%
-| mean_age| -|--------:| -| 24.4037| + + + + + + + + + + + +
mean_age
24.4037
@@ -193,9 +228,20 @@ ppt_info %>%
-| mean_age| sd_age| -|--------:|--------:| -| 24.4037| 3.496677| + + + + + + + + + + + + + +
mean_age sd_age
24.4037 3.496677
@@ -251,11 +297,40 @@ ppt_info %>%
-|gender | mean_age| sd_age| median_age| group_size| -|:----------|--------:|--------:|----------:|----------:| -|Man | 24.25000| 3.382591| 24.0| 100| -|Non-Binary | 24.22000| 3.726847| 25.5| 50| -|Woman | 24.60833| 3.510598| 25.0| 120| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
gender mean_age sd_age median_age group_size
Man 24.25000 3.382591 24.0 100
Non-Binary 24.22000 3.726847 25.5 50
Woman 24.60833 3.510598 25.0 120
diff --git a/docs/05-corsi.md b/docs/05-corsi.md index 375b56e..9d17636 100644 --- a/docs/05-corsi.md +++ b/docs/05-corsi.md @@ -92,18 +92,58 @@ Once you've done all this, it's time to download the files we need and then uplo The zip file contains four files: * `corsi_stub1.Rmd` and `corsi_stub2.Rmd`, the stub files you'll complete for this chapter and the next one. Open `corsi_stub1.Rmd` by clicking on it in the Files tab and then edit the heading to add in your GUID and today's date. -* `demographic_data.csv` is a data file that contains each participant's anonymous ID, age, gender and which experimental condition they were in (8 hours sleep, 4 hours sleep, or sleep deprived). This data is in wide-form. There are 600 participants, so there are 600 rows of data. +* `demographic_data.csv` is a data file that contains each participant's anonymous ID, age, gender and which experimental condition they were in (8 hours sleep, 4 hours sleep, or sleep deprived). This data is in wide-form. There are 600 participants, so there are 600 rows of data.
-| Participant|Gender | Age|Condition | -|-----------:|:------|---:|:-------------| -| 1|Woman | 48|8 hours sleep | -| 2|Woman | 32|8 hours sleep | -| 3|Man | 31|8 hours sleep | -| 4|Man | 20|8 hours sleep | -| 5|Man | 59|8 hours sleep | -| 6|Man | 60|8 hours sleep | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Participant Gender Age Condition
1 Woman 48 8 hours sleep
2 Woman 32 8 hours sleep
3 Man 31 8 hours sleep
4 Man 20 8 hours sleep
5 Man 59 8 hours sleep
6 Man 60 8 hours sleep
@@ -243,7 +283,7 @@ If you get an error that says `object X not found`, double check you have spelle ## Activity 6: Joining the datasets -We want to compare the scores for each sleep condition, however, the column that says what condition a participant took part in is contained in a different dataset (`demographic_data`) to the column that has their scores (`score_data`). To fix this, we can perform a join.There are lots of different types of joins you can do, but the one we want is an inner-join which returns all the rows in one table that have a match in the other table. +We want to compare the scores for each sleep condition, however, the column that says what condition a participant took part in is contained in a different dataset (`demographic_data`) to the column that has their scores (`score_data`). To fix this, we can perform a join.There are lots of different types of joins you can do, but the one we want is an inner-join which returns all the rows in one table that have a match in the other table. Before you run the code, think about what the final output is going to look like. `demographic_data` has 4 columns, `score_data` has 2 columns, but the column `Participant` is the same column. diff --git a/docs/06-corsi-analysis.md b/docs/06-corsi-analysis.md index 308ab18..4a60085 100644 --- a/docs/06-corsi-analysis.md +++ b/docs/06-corsi-analysis.md @@ -206,7 +206,7 @@ age_control <- analysis_data %>% -How many participants are left in the sample after filtering for age? +How many participants are left in the sample after filtering for age? ## Activity 5: Summarise diff --git a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png index 61a5391..346ff17 100644 Binary files a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png and b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-17-1.png differ diff --git a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png index 4b10cb1..d704c0c 100644 Binary files a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png and b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png index d5783cf..836873d 100644 Binary files a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png and b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-19-1.png differ diff --git a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png index d578591..54780c5 100644 Binary files a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png and b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-20-1.png differ diff --git a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png index 62fe167..132c566 100644 Binary files a/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png and b/docs/06-corsi-analysis_files/figure-html/unnamed-chunk-25-1.png differ diff --git a/docs/07-belong.md b/docs/07-belong.md index e244818..eedf05b 100644 --- a/docs/07-belong.md +++ b/docs/07-belong.md @@ -163,7 +163,7 @@ Because `gender` is coded numerically, R has assumed that the data in this colum ::: {.info data-latex=""} -There are several different data types in R and when you load data in, R will do it's best to guess which one each variable is: +There are several different data types in R and when you load data in, R will do it's best to guess which one each variable is: * integer (whole numbers like 1L, -10L, 3000L) * double (numbers like -0.223, 10.324, 1e4) @@ -263,29 +263,93 @@ full_data %>%
-|gender_coded | n| -|:------------|---:| -|Man | 500| -|Woman | 400| -|Non-binary | 100| + + + + + + + + + + + + + + + + + + + + + +
gender_coded n
Man 500
Woman 400
Non-binary 100
-|level | n| -|:-----------|---:| -|First year | 920| -|Second year | 80| + + + + + + + + + + + + + + + + + +
level n
First year 920
Second year 80
-|level |gender_coded | n| -|:-----------|:------------|---:| -|First year |Man | 457| -|First year |Woman | 373| -|First year |Non-binary | 90| -|Second year |Man | 43| -|Second year |Woman | 27| -|Second year |Non-binary | 10| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
level gender_coded n
First year Man 457
First year Woman 373
First year Non-binary 90
Second year Man 43
Second year Woman 27
Second year Non-binary 10
diff --git a/docs/09-big5.md b/docs/09-big5.md index 211aaf1..260712c 100644 --- a/docs/09-big5.md +++ b/docs/09-big5.md @@ -30,12 +30,12 @@ For the next set of chapters we're going to use data from the most popular model * Finally, answer the following questions. Please note that your responses will not save in the browser - if you want to save them, make a note of them somewhere. 1. The trait 'Agreeableness' in the Big Five personality model refers to: -
+
2. In the context of the Big Five Personality model, which trait might be associated with a person who is diligent, efficient, and follows a schedule? -
+
3. Individuals who are often nervous, insecure, and easily upset, are considered to have high according to the Big Five Personality Model. @@ -43,7 +43,7 @@ For the next set of chapters we're going to use data from the most popular model 4. In the Big Five Personality Model, people who are outgoing, sociable, and assertive score high on the trait known as 5. Which of these traits in the Big Five Personality model is most closely associated with creativity and a preference for novelty? -
+
@@ -157,14 +157,36 @@ Before we go any further, let's explain what we mean by forward and reverse scor * Now type the number of one of the items where you think **disagreeing** with the item would mean the participant displayed a higher level of agreeableness - -|Q_No |Question | -|:----|:-----------------------------------------| -|Q 1 |Is compassionate, has a soft heart | -|Q 2 |Feels little sympathy for others | -|Q 3 |Is respectful, treats others with respect | -|Q 4 |Is polite, courteous to others | -|Q 5 |Starts arguments with others | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Q_No Question
Q 1 Is compassionate, has a soft heart
Q 2 Feels little sympathy for others
Q 3 Is respectful, treats others with respect
Q 4 Is polite, courteous to others
Q 5 Starts arguments with others
For those items where agreeing with the item means higher agreeableness, participants receive a score of 1 if they answer "disagree strongly" and a score of 5 if they answer "agree strongly". This is called **forward scoring**. For those items where disagreeing with the item means a higher agreeableness score, participants receive a score of 1 if they answer "agree strongly" and 5 if they answer "disagree strongly". This is know as **reverse coding**. @@ -216,18 +238,67 @@ In long-form, the `big5` dataset would look something like this:
-|ResponseId |question_name | answer| -|:-----------------|:-------------|------:| -|R_3O9fzdsGn9tEeOm |Q4_1 | 5| -|R_3O9fzdsGn9tEeOm |Q4_2 | 4| -|R_3O9fzdsGn9tEeOm |Q4_3 | 1| -|R_3O9fzdsGn9tEeOm |Q4_4 | 1| -|R_3O9fzdsGn9tEeOm |Q4_5 | 5| -|R_3O9fzdsGn9tEeOm |Q4_6 | 3| -|R_3O9fzdsGn9tEeOm |Q4_7 | 5| -|R_3O9fzdsGn9tEeOm |Q4_8 | 1| -|R_3O9fzdsGn9tEeOm |Q4_9 | 2| -|R_3O9fzdsGn9tEeOm |Q4_10 | 4| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ResponseId question_name answer
R_3O9fzdsGn9tEeOm Q4_1 5
R_3O9fzdsGn9tEeOm Q4_2 4
R_3O9fzdsGn9tEeOm Q4_3 1
R_3O9fzdsGn9tEeOm Q4_4 1
R_3O9fzdsGn9tEeOm Q4_5 5
R_3O9fzdsGn9tEeOm Q4_6 3
R_3O9fzdsGn9tEeOm Q4_7 5
R_3O9fzdsGn9tEeOm Q4_8 1
R_3O9fzdsGn9tEeOm Q4_9 2
R_3O9fzdsGn9tEeOm Q4_10 4
diff --git a/docs/10-big5-tidy.md b/docs/10-big5-tidy.md index 3aa0e44..79fb039 100644 --- a/docs/10-big5-tidy.md +++ b/docs/10-big5-tidy.md @@ -63,14 +63,96 @@ As noted in the last chapter, our Big Five data is currently in wide-form, with
-|ResponseId | Q4_1| Q4_2| Q4_3| Q4_4| Q4_5| Q4_6| Q4_7| Q4_8| Q4_9| -|:-----------------|----:|----:|----:|----:|----:|----:|----:|----:|----:| -|R_3O9fzdsGn9tEeOm | 5| 4| 1| 1| 5| 3| 5| 1| 2| -|R_12z0hyaE0u5KaRG | 4| 4| 5| 1| 5| 3| 5| 5| 1| -|R_2VmvNkJQ6RpY3PV | 3| 5| 4| 2| 2| 4| 4| 4| 2| -|R_eboWF1vMzPIVPi1 | 4| 2| 5| 1| 2| 5| 2| 5| 2| -|R_1jBz09Q5pO9alkq | 4| 5| 1| 2| 1| 3| 4| 4| 1| -|R_pui4ZWuxPsJ7vUt | 2| 5| 5| 2| 1| 3| 5| 1| 2| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ResponseId Q4_1 Q4_2 Q4_3 Q4_4 Q4_5 Q4_6 Q4_7 Q4_8 Q4_9
R_3O9fzdsGn9tEeOm 5 4 1 1 5 3 5 1 2
R_12z0hyaE0u5KaRG 4 4 5 1 5 3 5 5 1
R_2VmvNkJQ6RpY3PV 3 5 4 2 2 4 4 4 2
R_eboWF1vMzPIVPi1 4 2 5 1 2 5 2 5 2
R_1jBz09Q5pO9alkq 4 5 1 2 1 3 4 4 1
R_pui4ZWuxPsJ7vUt 2 5 5 2 1 3 5 1 2
@@ -138,14 +220,68 @@ If you look at `join1` you can see that this object now has all the original col
-|ResponseId |item | response|trait |facet |direction | -|:-----------------|:----|--------:|:-----------------|:---------------|:---------| -|R_3O9fzdsGn9tEeOm |Q4_1 | 5|extraversion |sociability |forward | -|R_3O9fzdsGn9tEeOm |Q4_2 | 4|agreeableness |compassion |forward | -|R_3O9fzdsGn9tEeOm |Q4_3 | 1|conscientiousness |organisation |reversed | -|R_3O9fzdsGn9tEeOm |Q4_4 | 1|neg_emotionality |anxiety |reversed | -|R_3O9fzdsGn9tEeOm |Q4_5 | 5|open_minded |aes_sensitivity |reversed | -|R_3O9fzdsGn9tEeOm |Q4_6 | 3|extraversion |assertiveness |forward | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ResponseId item response trait facet direction
R_3O9fzdsGn9tEeOm Q4_1 5 extraversion sociability forward
R_3O9fzdsGn9tEeOm Q4_2 4 agreeableness compassion forward
R_3O9fzdsGn9tEeOm Q4_3 1 conscientiousness organisation reversed
R_3O9fzdsGn9tEeOm Q4_4 1 neg_emotionality anxiety reversed
R_3O9fzdsGn9tEeOm Q4_5 5 open_minded aes_sensitivity reversed
R_3O9fzdsGn9tEeOm Q4_6 3 extraversion assertiveness forward
@@ -234,14 +370,61 @@ We can see that `trait_scores` has the average score on each trait for each part
-|ResponseId |trait | ppt_mean| ppt_sd| n| -|:-----------------|:-----------------|--------:|---------:|--:| -|R_00WKbbVigS4o2nD |agreeableness | 3.916667| 1.0836247| 12| -|R_00WKbbVigS4o2nD |conscientiousness | 3.333333| 1.0730867| 12| -|R_00WKbbVigS4o2nD |extraversion | 2.500000| 1.9306146| 12| -|R_00WKbbVigS4o2nD |neg_emotionality | 3.666667| 1.3026779| 12| -|R_00WKbbVigS4o2nD |open_minded | 4.833333| 0.5773503| 12| -|R_01bclyhvsvPyH0l |agreeableness | 4.500000| 0.9045340| 12| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ResponseId trait ppt_mean ppt_sd n
R_00WKbbVigS4o2nD agreeableness 3.916667 1.0836247 12
R_00WKbbVigS4o2nD conscientiousness 3.333333 1.0730867 12
R_00WKbbVigS4o2nD extraversion 2.500000 1.9306146 12
R_00WKbbVigS4o2nD neg_emotionality 3.666667 1.3026779 12
R_00WKbbVigS4o2nD open_minded 4.833333 0.5773503 12
R_01bclyhvsvPyH0l agreeableness 4.500000 0.9045340 12
@@ -316,13 +499,48 @@ trait_means <- trait_scores %>%
-|trait | trait_mean| trait_sd| n| -|:-----------------|----------:|---------:|----:| -|agreeableness | 3.666459| 0.6165711| 5605| -|conscientiousness | 3.253494| 0.7608749| 5605| -|extraversion | 3.134121| 0.7838352| 5605| -|neg_emotionality | 3.301784| 0.8500805| 5605| -|open_minded | 3.775379| 0.6470955| 5605| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
trait trait_mean trait_sd n
agreeableness 3.666459 0.6165711 5605
conscientiousness 3.253494 0.7608749 5605
extraversion 3.134121 0.7838352 5605
neg_emotionality 3.301784 0.8500805 5605
open_minded 3.775379 0.6470955 5605
diff --git a/docs/404.html b/docs/404.html index d5eb439..b3acd92 100644 --- a/docs/404.html +++ b/docs/404.html @@ -19,7 +19,7 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +