# load packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(papaja)
## Loading required package: tinylabels
library(glue)
library(knitr)
library(gridExtra)
##
## Attaching package: 'gridExtra'
##
## The following object is masked from 'package:dplyr':
##
## combine
# read in data being used
study_1 <- read_csv(file = "study_1_data.csv")
## Rows: 467 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Gender, Age
## dbl (13): Participant ID, LETHAVERAGE.T1, LETHAVERAGE.T2, LethDiff, SCAVERAG...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(study_1)
## Rows: 467
## Columns: 15
## $ `Participant ID` <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16…
## $ Gender <chr> "Woman", "Woman", "Man", "Man", "Woman", "Woman", "Wo…
## $ Age <chr> "25", "20", "23", "26", "19", "22", "20", "22", "22",…
## $ LETHAVERAGE.T1 <dbl> 4.800000, 3.400000, 1.800000, 1.200000, 1.900000, 5.1…
## $ LETHAVERAGE.T2 <dbl> 5.7, 5.0, 2.4, 5.4, 3.8, 5.8, 2.8, 3.1, 4.4, 1.1, 5.4…
## $ LethDiff <dbl> 0.9000000, 1.6000000, 0.6000000, 4.2000000, 1.9000000…
## $ SCAVERAGE.T1 <dbl> 3.21053, 4.00000, 4.94737, 4.47368, 3.68421, 1.84211,…
## $ SCAVERAGE.T2 <dbl> 2.94737, 4.47368, 4.00000, 2.36842, 3.84211, 2.21053,…
## $ SCdiff <dbl> -0.26316, 0.47368, -0.94737, -2.10526, 0.15790, 0.368…
## $ EXTRAVERSION <dbl> 6.25000, 5.25000, 4.25000, 2.66667, 2.91667, 4.16667,…
## $ SPANE.P <dbl> 8, 18, 18, 17, 18, 16, 27, 18, 17, 24, 16, 20, 25, 28…
## $ SPANE.N <dbl> 27, 20, 15, 25, 15, 26, 15, 23, 16, 18, 24, 18, 12, 1…
## $ SPANE.B <dbl> -19, -2, 3, -8, 3, -10, 12, -5, 1, 6, -8, 2, 13, 13, …
## $ SocialDistancing <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ SixFeet <dbl> 0, 3, 0, 3, 2, 0, 1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0,…
study_2 <- read_csv(file = "study_2_data.csv")
## Rows: 336 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Gender, Ethnicity, Country
## dbl (14): Participant_ID, Age, T1Extraversion, T1SWLS, T2SWLS, SWLS_Diff, T1...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(study_2)
## Rows: 336
## Columns: 17
## $ Participant_ID <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16…
## $ Gender <chr> "Male", "Female", "Female", "Male", "Male", "Female",…
## $ Age <dbl> 23, 19, 20, 19, 22, 21, 20, 26, 37, 41, 34, 30, 23, 2…
## $ Ethnicity <chr> "White", "Hispanic", "White", "White", "White", "Whit…
## $ Country <chr> "Canada", "Mexico", "UK", "USA", "UK", "UK", "USA", "…
## $ T1Extraversion <dbl> 4.750000, 3.833333, 4.000000, 3.916667, 4.250000, 4.3…
## $ T1SWLS <dbl> 4.8, 4.4, 5.8, 5.4, 5.6, 4.6, 4.0, 5.6, 1.0, 1.8, 4.2…
## $ T2SWLS <dbl> 5.0, 3.2, 4.0, 6.0, 5.4, 4.2, 3.4, 5.6, 1.0, 1.0, 4.8…
## $ SWLS_Diff <dbl> 0.2, -1.2, -1.8, 0.6, -0.2, -0.4, -0.6, 0.0, 0.0, -0.…
## $ T1Lonely <dbl> 1.421053, 3.157895, 2.684211, 1.421053, 1.421053, 1.8…
## $ T2Lonely <dbl> 1.473684, 2.894737, 2.736842, 2.210526, 1.105263, 1.8…
## $ Lonely_Diff <dbl> 0.05263158, -0.26315789, 0.05263158, 0.78947368, -0.3…
## $ T1BMPN <dbl> 5.166667, 3.000000, 5.166667, 6.000000, 6.500000, 5.0…
## $ T2BMPN <dbl> 5.500000, 1.666667, 3.833333, 5.333333, 6.166667, 3.5…
## $ BMPN_Diff <dbl> 0.3333333, -1.3333333, -1.3333333, -0.6666667, -0.333…
## $ SocialDistancing <dbl> 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ SixFeet <dbl> 0, 4, 0, 4, 2, 0, 0, 2, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0,…
#STUDY 1
#Age is a character value so need to change to numeric
study_1 <- transform(study_1, Age = as.numeric(Age))
## Warning in eval(substitute(list(...)), `_data`, parent.frame()): NAs introduced
## by coercion
# Ignore NA values
mean_age1 <- round(mean(study_1$Age, na.rm=TRUE), 2)
sd_age1 <- round(sd(study_1$Age, na.rm=TRUE), 2)
gender_percent1 <- round(sum(study_1$Gender=='Woman')/nrow(study_1) * 100, 0)
cat("age:", "M =", mean_age1, ", SD =", sd_age1, ";", gender_percent1,"% women")
## age: M = 20.89 , SD = 3.03 ; 77 % women
#STUDY 2
# Recruited sample data is not available, Final sample data only
mean_age2 <- round(mean(study_2$Age, na.rm=TRUE), 2)
sd_age2 <- round(sd(study_2$Age, na.rm=TRUE), 2)
gender_percent2 <- round(sum(study_2$Gender=='Male')/nrow(study_2) * 100, 0)
ethnicity_percent2 <- round(sum(study_2$Ethnicity=='White')/nrow(study_2) * 100, 0)
# Single or married data not present in data file
US_percent2 <- round(sum(study_2$Country=='USA')/nrow(study_2) * 100, 0)
UK_percent2 <- round(sum(study_2$Country=='UK')/nrow(study_2) * 100, 0)
cat("age: M =", mean_age2, ", SD =", sd_age2, ";", gender_percent2, "% Male;", ethnicity_percent2, "% White;", US_percent2, "% U.S.;", UK_percent2, "% U.K.")
## age: M = 32.03 , SD = 11.94 ; 55 % Male; 80 % White; 31 % U.S.; 27 % U.K.