Week 9 Goals

  • Get someone to check my statistical analyses
  • Write up my recommendations
  • Knit my report into word
  • Don’t throw my computer at the wall

Challenges and successes

  • I can happily report that I have written up my recommendations, knitted my report into word and pdfm and even made them both into papaja template, and my computer is still intact!
  • I had quite a bit of trouble this week with my plots and my statistical analyses but I finally got somewhere thanks to both Jenny’s rpubs.
  • I worked out how to make variables based on more than one column of the same measure and then bind them together to create one datadset. I also worked out how to put my information into a pretty table, both uing gt() and apa_table() because gt() wouldn’t knit in word or PDF! Here’s what I got up to!
  • I also changed some of my plots from bar charts to boxplots upon Jenny Sloane’s recommendation:
# Make a subset of the original study 1 dataset to only include participant, 
# sex, and the disgust variables

data_1_DSxSex <- data_1_raw %>%
  select(participant, sex, DS1:DS7) %>% 
  filter(sex != '3') %>% # Remove 'other' as a gender category
  mutate(exp = 1) # Make a new variable based to identify the study it came from

# Make a subset of the original study 2 dataset to only include participant, 
# sex, and the disgust variables

data_2_DSxSex <- data_2 %>%
  select(participant, sex, DS1:DS7) %>% 
  filter(sex != '3') %>% # Remove 'other' as a gender category
  mutate(exp = 2) # Make a new variable based to identify the study it came from

# Make a subset of the original study 3 dataset to only include participant, 
#sex, and the disgust variables

data_3_DSxSex <- data_3 %>% 
  select(participant, sex, DS1:DS7) %>% 
  filter(sex != '3') %>% # Remove 'other' as a gender category
  mutate(exp = 3) # Make a new variable based to identify the study it came from

# Combine these 3 new datasets to a total dataset to analyse
Total_DSxSex <- rbind(data_1_DSxSex, data_2_DSxSex, data_3_DSxSex) 

# Make a new variable that is a combined average of all disgust variables
avgdisgust <- Total_DSxSex %>% 
  mutate(avg_DS = rowMeans(select(., DS1:DS7)))  %>%
  select(participant, avg_DS, sex) # Use a subset of the total dataset to 
# include only participant, the average disgust variable, and sex

Total_DSxSexSummary <- avgdisgust %>% # Make a summary table of descriptive 
  # statistics from the total data
  group_by(sex) %>%
  summarise (mean = mean(avg_DS),
             sd = sd(avg_DS),
             n = n(),
             se = sd/sqrt(n)
            )
apa_table(
  Total_DSxSexSummary,
  caption = "Descriptive statistics of Average Disgust by Sex")
(#tab:unnamed-chunk-1)
Descriptive statistics of Average Disgust by Sex
sex mean sd n se
1.00 4.46 1.05 972 0.03
2.00 4.81 1.08 856 0.04
# Plot sex (males and females) as a function of disgust in a box plot

# avgdisgust %>%
#   ggplot(aes(x = sex, y = avg_DS, fill = sex)) +
#   geom_boxplot(alpha = 0.5) +
#   stat_summary(fun = "mean") +
#     scale_x_discrete(name = "Sex", 
#                      labels = c("1" = "Males", "2" = "Females")) +
#     scale_y_continuous(name = 'Average Disgust') +
#     (easy_text_size(15))
  • For some reason this plot isn’t working anymore but here is what it looks like in my report!

  • I also used library(report) thanks to Jenny Richmond’s learning log to report my stats!
# Complete a t-test to compare the means between average disgust and sex

question1_ttest <- t.test(formula = avg_DS ~ sex, data = avgdisgust)

# Write the t-test findings in a sentence for a report

report(question1_ttest)

Effect sizes were labelled following Cohen’s (1988) recommendations.

The Welch Two Sample t-test testing the difference of avg_DS by sex (mean in group 1 = 4.46, mean in group 2 = 4.81) suggests that the effect is positive, statistically significant, and small (difference = 0.35, 95% CI [-0.45, -0.25], t(1784.16) = -7.02, p < .001; Cohen’s d = -0.33, 95% CI [-0.43, -0.24])

  • I used mutate() and case_when() to convert my age variable into groups to simplify my analysis~
# Making a new dataset from data 1 with participants, the Honesty-Humility 
# variables and age as the columns
  
data_1_HHxAge <- data_1_raw %>%
  select(participant, HH1:HH10, age) %>%
  na.omit() %>% # Remove any missing values
  mutate(exp = 1) # Make a new variable based to identify the study it came from

# Making a new dataset from data 2 with participants, the Honesty-Humility 
# variables and age as the columns

data_2_HHxAge <- data_2 %>%
  select(participant, HH1:HH10, age) %>%
  na.omit() %>% # Remove any missing values
  mutate(exp = 2) # Make a new variable based to identify the study it came from

# Combine these 3 new datasets to a total dataset to analyse

Total_HHxAge <- rbind(data_1_HHxAge, data_2_HHxAge) 

# Make a new dataset that combines two newly created variables: a combined 
# average of all honesty-humility variables and an age variable that separates 
# age into 5 groups

avghonestyhumility <- Total_HHxAge %>% 
  mutate(avg_HH = rowMeans(select(., HH1:HH10)))  %>%
  mutate(AgeGroup = case_when(age >= 18 & age <=29 ~ '18-29',
                              age >= 30 & age <= 39 ~ '30-39',
                              age >= 40 & age <= 49 ~ '40-49',
                              age >= 50 & age <= 59 ~ '50-59',
                              age >= 60 & age <= 79 ~ '60-73')
  ) %>%
  select(participant, avg_HH, AgeGroup) # Use a subset of the total dataset to 
# include only participant, the average contact comfort variable, and sex
  • Another very exciting thing that I worked out this week was how to cite in R using the package citr and a .bib file.

  • Finally, I converted my document to APA format using library(papaja)

  • Here is a link to my final report on RPubs and some screenshots of the PDF:

  • I had quite a few difficulties with knitting my report. I had to comment some of my figures out and provide screenshots instead. I also had to change all my tables from gt() to apa_table()