# R Script
# R version 4.1.1 (2021-08-10) -- "Kick Things"
# Copyright (C) 2021 The R Foundation for Statistical Computing
# Platform: x86_64-w64-mingw32/x64 (64-bit)

### ----- Data Preparation and Analysis for Study 2 ----- ####

# ----------- Creating Safe Environments ------------------- #

# 0) DATA PREPARATION
## a) Adjustment of single variable structures| Recode dependent variables
## [for anonymity reasons, we did not include all demographic variables in the open data and code]
# 1) DESCRIPTIVE ANALYSES
## a) Technical Data
## b) Sample Description
# 2) MOST EFFECTIVE ALARM SOUNDS
## a) Data preparation for mixed MANOVA 
## b) Descriptive Analysis
## c) Graphical Depiction of Results  
## d) Correlation Table
## e) Statistical analyses: Hypotheses 1 to 4
#### H1: repeated measures MANOVA
#### H2: paired t-tests
#### H3: paired t-tests
#### H4: paired t-tests

# setwd

### packages ####
## Install and load packages ####
# install.packages("readr")
library(readr)     # Read data
# install.packages("dplyr")
library(dplyr)     # Recode data
# install.packages("effectsize")
library(effectsize)
# install.packages("tidyverse")
library(tidyverse)
# install.packages("knitr")
library(knitr)
# install.packages("haven")
library(haven)
# install.packages("janitor")
library(janitor)
# install.packages("data.table")
library(data.table)
# install.packages("car")
library(car)  
# install.packages("psych")
library(psych) 
# install.packages("rtf")
library(rtf)       # Data export
# install.packages("tidyr")
library(tidyr)     # Merge columns
# install.packages("correlation")
library(correlation)



#### Read data ####

daten <- read_delim("Alarm_Sounds_Study2_Data.csv", delim = ";", 
                   escape_double = FALSE, trim_ws = TRUE)


#### Adjustment of single variable structures ####
# Recode arousal | Arousal rekodieren  
daten$L205.r <- car::recode(daten$L205, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$L505.r <- car::recode(daten$L505, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$L605.r <- car::recode(daten$L605, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$L705.r <- car::recode(daten$L705, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")

daten$W205.r <- car::recode(daten$W205, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$W505.r <- car::recode(daten$W505, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$W605.r <- car::recode(daten$W605, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$W705.r <- car::recode(daten$W705, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")

daten$M205.r <- car::recode(daten$M205, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$M505.r <- car::recode(daten$M505, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$M605.r <- car::recode(daten$M605, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")
daten$M705.r <- car::recode(daten$M705, "1=5; 2=4; 3=3; 4=2; 5=1; -9=-9")

# ------------------------------------------------------------------------------- #

#### Descriptives and Scales for the Final Sample (N = 206) ###
#    Deskriptive Statistiken, Skalen, (Gesamtstichprobe)      #


# Sample description (whole final sample), Demographics, voluntary work, hearing | 
# Stichprobenbeschreibung (Gesamtstichprobe), Demografie + Ehrenamt + Hoeren ####

describe(daten$age)

table(daten$gender)
round(prop.table(table(daten$gender)), 4)*100


# ---------------------------------------------------------------------------- #

# Technische Variablen # 

# Provider | Anbieter 
# E201_PRV 
table(daten$E201_PRV)     
round(prop.table(table(daten$E201_PRV )), 4)

# Operating System | Betriebssystem
# E201_OS
table(daten$E201_OS)     
round(prop.table(table(daten$E201_OS)), 4)

# Browser
# E201_BNM
table(daten$E201_BNM)     
round(prop.table(table(daten$E201_BNM)), 4)

# Format (Computer vs. Smartphone etc.)
# E201_FmF
table(daten$E201_FmF)     
round(prop.table(table(daten$E201_FmF)), 4)

# Screen width (pixels) | Bildschirmbreite (Pixel)
# E201_ScW
describe(daten$E201_ScW)

# Screen height (pixels) | Bildschirmhoehe (Pixel)
# E201_ScH
describe(daten$E201_ScH)

# ------------------------------------------------------------------------------------------------------- # 
#### Data Preparation for repeated measures MANOVA + Descriptive Analyses for the Dependent Variables| ####
###  AVs so sortieren, dass eine repeated Measures ANOVA damit gerechnet werden kann + ###
###  Korrelationen und deskriptive Daten berechnen fuer die AVs ###

# Long data set for repeated measures MANOVA

# 1)  One row for each sound rating per participant and sound | 
#     Fuer jedes Soundrating pro Person und Ton eine Zeile erstellen
daten1 <- daten %>% 
  pivot_longer(
    c("L203", "L503", "L603", "L703", 
      "L204", "L504", "L604", "L704",
      "L205.r", "L505.r", "L605.r", "L705.r",
      "L206", "L506", "L606", "L706",
      "L207", "L507", "L607", "L707",
      "L208", "L508", "L608", "L708",
      "L209", "L509", "L609", "L709",
      "L210", "L510", "L610", "L710",
      
      "W203", "W503", "W603", "W703",
      "W204", "W504", "W604", "W704",
      "W205.r", "W505.r", "W605.r", "W705.r",
      "W206", "W506", "W606", "W706",
      "W207", "W507", "W607", "W707",
      "W208", "W508", "W608", "W708",
      "W209", "W509", "W609", "W709",
      "W210", "W510", "W610", "W710",
      
      
      "M203", "M503", "M603", "M703",
      "M204", "M504", "M604", "M704",
      "M205.r", "M505.r", "M605.r", "M705.r",
      "M206", "M506", "M606", "M706",
      "M207", "M507", "M607", "M707",
      "M208", "M508", "M608", "M708",
      "M209", "M509", "M609", "M709",
      "M210", "M510", "M610", "M710"),
    names_to = "sound_dv", 
    values_to = "sound_rating", 
    values_drop_na = TRUE
  )

# Split variables in with male/with female/without voice alert, and sound (sounds 2,5,6,7), and in the dependent variables |
# Variablen aufspalten in maennl./weibl./keine Stimme, welcher Ton genutzt wurde, 
# und in die abhaengigen Variablen
daten1 <- daten1 %>% 
  separate(sound_dv, c("voice", "sound"), 1) 

# Split the sound variable in "sound" and the dependents variable "sound_dv" |
# Aufspalten der Soundvariable in Sound und abhaengige Variable (sound_dv)
daten1 <- daten1 %>% 
  separate(sound, c("sound", "sound_dv"), 1) 

# Rename the dependent variables | Umbenennen der Bewertungsvariablen
daten1$sound_dv[daten1$sound_dv == "03"] <- 3
daten1$sound_dv[daten1$sound_dv == "04"] <- 4
daten1$sound_dv[daten1$sound_dv == "05.r"] <- 5
daten1$sound_dv[daten1$sound_dv == "06"] <- 6
daten1$sound_dv[daten1$sound_dv == "07"] <- 7
daten1$sound_dv[daten1$sound_dv == "08"] <- 8
daten1$sound_dv[daten1$sound_dv == "09"] <- 9
daten1$sound_dv[daten1$sound_dv == "10"] <- 10

daten1$sound_dv[daten1$sound_dv == "3"]  <- "typicality"
daten1$sound_dv[daten1$sound_dv == "4"]  <- "valence"
daten1$sound_dv[daten1$sound_dv == "5"]  <- "arousal"
daten1$sound_dv[daten1$sound_dv == "6"]  <- "dominance"
daten1$sound_dv[daten1$sound_dv == "7"]  <- "motivation"
daten1$sound_dv[daten1$sound_dv == "8"]  <- "intention"
daten1$sound_dv[daten1$sound_dv == "9"]  <- "distinctiveness"
daten1$sound_dv[daten1$sound_dv == "10"] <- "ambiguity"


# Create columns for the different dependent variables (valence, arousal, etc.) |
# Spalten fuer die verschiedenen Bewertungsdimensionen erstellen (valence, arousal usw.)
daten1 <- daten1 %>% 
  pivot_wider(names_from = sound_dv, values_from = sound_rating)

# Create sub-dataset for rm MANOVA
soundrating <- daten1 %>% 
  distinct(CASE, sound, voice, age, gender, typicality, valence, arousal, dominance, 
           motivation, intention, distinctiveness, ambiguity) 

# Descriptive Analyses separated by sound and group |
# Deskriptive Statistiken nach Toenen und Gruppen getrennt
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(typicality, na.rm=T), sd=sd(typicality, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(valence, na.rm=T), sd=sd(valence, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(arousal, na.rm=T), sd=sd(arousal, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(dominance, na.rm=T), sd=sd(dominance, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(motivation, na.rm=T), sd=sd(motivation, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(intention, na.rm=T), sd=sd(intention, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(distinctiveness, na.rm=T), sd=sd(distinctiveness, na.rm = T))
daten1 %>%  group_by(voice, sound) %>% summarize(mean=mean(ambiguity, na.rm=T), sd=sd(ambiguity, na.rm = T))

# Descriptive Analyses separated by sound |
# Deskriptive Statistiken nach Toenen gentrennt, ueber Gruppen hinweg
daten1 %>%  group_by(sound) %>% summarize(mean=mean(typicality, na.rm=T), sd=sd(typicality, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(valence, na.rm=T), sd=sd(valence, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(arousal, na.rm=T), sd=sd(arousal, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(dominance, na.rm=T), sd=sd(dominance, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(motivation, na.rm=T), sd=sd(motivation, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(intention, na.rm=T), sd=sd(intention, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(distinctiveness, na.rm=T), sd=sd(distinctiveness, na.rm = T))
daten1 %>%  group_by(sound) %>% summarize(mean=mean(ambiguity, na.rm=T), sd=sd(ambiguity, na.rm = T))

# Descriptives: Alarm preference (with or without voice alert, "BS07") | 
# Alarmierungspraeferenz (BS07) (mit oder ohne Sprachansage)
table(daten$BS07)
# 1 (with voice alert | mit Sprachansage):     157
# 2 (without voice alert | ohne Sprachansage): 32
# 3 (indifferent | egal):                      17
hist(daten$BS07)
round(prop.table(table(daten$BS07)), 4)*100

# Male or female voice alert (one item: "BS08") |
# Art der Sprachansage (mit maennl./weibl. Sprachansage)
table(daten$BS08)
# 1 (maennliche Sprachansage): 70
# 2 (weibliche Sprachansage): 55
# 3 (egal): 81
hist(daten$BS08)
round(prop.table(table(daten$BS08)), 4)*100


# ---------------------------------------------------------------------------- #

#### -------------------- Statistical Analyses ---------------------------- ####

soundrating$gender_f<-factor(soundrating$gender)
soundrating$voice_f<-factor(soundrating$voice)
soundrating$sound_f<-factor(soundrating$sound)
soundrating$CASE_f<-factor(soundrating$CASE)

#### Descriptive graphic depiction of differences ####

# Plots erstellen fuer alle abhaengigen Variablen
long_2<-soundrating %>%
  dplyr::select(voice:ambiguity) %>%
  tidyr::pivot_longer(.,typicality:ambiguity, names_to = "variable")

ggplot(long_2, aes(x=sound, y=value, col=voice, group = voice)) +
  stat_summary(fun.data = mean_cl_boot, position = position_jitter(height=0, width=0.2)) +
  facet_wrap(~variable)

# Capitalisation of variables
long_2$variable[long_2$variable == 
                  "arousal"] <- "Arousal"
long_2$variable[long_2$variable == 
                  "dominance"] <- "Dominance"
long_2$variable[long_2$variable == 
                  "familiarity"] <- "Familiarity"
long_2$variable[long_2$variable == 
                  "typicality"] <- "Typicality"
long_2$variable[long_2$variable == 
                  "valence"] <- "Valence"
long_2$variable[long_2$variable == 
                  "ambiguity"] <- "Ambiguity Reduction"
long_2$variable[long_2$variable == 
                  "distinctiveness"] <- "Distinctiveness"
long_2$variable[long_2$variable == 
                  "intention"] <- "Intention"
long_2$variable[long_2$variable == 
                  "motivation"] <- "Motivation"

ggplot(long_2, aes(x=sound, y=value, col=voice, group = voice)) +
  stat_summary(fun.data = mean_cl_boot, position = position_jitter(height=0, width=0.2)) +
  facet_wrap(~variable)

# Format plot differently and change labels
last_plot() + xlab("Sound") 
last_plot() + ylab("Value")
last_plot() + scale_colour_discrete(name="Voice", breaks=c("L", "M","W"), labels= c("no voice alert", "male voice alert","female voice alert"))
last_plot() + scale_x_discrete(breaks = c("2", "5", "6", "7"), labels = c("S2", "S5","S6","S7"))

# --------------------------------------------------------------------- #
#### Intercorrelations between variables ####

# Data set only with relevant variables | Datensatz nur mit relevanten Variablen
soundrating_cor <- daten1 %>% 
  distinct(age, typicality, valence, arousal, dominance, 
           motivation, intention, distinctiveness, ambiguity) 

# Correlation table in APA-format | Korrelationstabelle in APA-Format erstellen
apaTables::apa.cor.table(soundrating_cor, filename = "tab_1_correlation.doc",table.number = 1,show.conf.interval = TRUE)

# Problem: package shows only **, not ***
# -> check, if ** is actually *** 

cor.test(soundrating$age, soundrating$typicality) 
cor.test(soundrating$age, soundrating$motivation) 
cor.test(soundrating$age, soundrating$ambiguity) 
cor.test(soundrating$typicality, soundrating$valence) 
cor.test(soundrating$typicality, soundrating$arousal) 
cor.test(soundrating$typicality, soundrating$dominance) 
cor.test(soundrating$typicality, soundrating$motivation)
cor.test(soundrating$typicality, soundrating$intention)
cor.test(soundrating$typicality, soundrating$distinctiveness)
cor.test(soundrating$typicality, soundrating$ambiguity) 
cor.test(soundrating$valence, soundrating$arousal) 
cor.test(soundrating$valence, soundrating$dominance)
cor.test(soundrating$arousal, soundrating$dominance)
cor.test(soundrating$arousal, soundrating$motivation)
cor.test(soundrating$arousal, soundrating$intention)
cor.test(soundrating$arousal, soundrating$distinctiveness)
cor.test(soundrating$arousal, soundrating$ambiguity)
cor.test(soundrating$dominance, soundrating$motivation)
cor.test(soundrating$dominance, soundrating$intention)
cor.test(soundrating$dominance, soundrating$distinctiveness)
cor.test(soundrating$dominance, soundrating$ambiguity)
cor.test(soundrating$motivation, soundrating$intention)
cor.test(soundrating$motivation, soundrating$distinctiveness)
cor.test(soundrating$motivation, soundrating$ambiguity)
cor.test(soundrating$intention, soundrating$distinctiveness)
cor.test(soundrating$intention, soundrating$ambiguity)
cor.test(soundrating$ambiguity, soundrating$distinctiveness)


#### -------------------- Hypothesis Testing ----------------------- ####

### H1: Alarm sounds combined with a voice alarm are more effective than alarm sounds without voice alarm.
### Repeated Measures MANOVA ###
# MANOVA with Error-Term (within subjects): Within subjects factors voice and sound
# MANOVA: Package {stats}
H11<-manova(cbind(typicality, valence, arousal, dominance, motivation,
                  intention, distinctiveness, ambiguity) 
            ~ voice * sound + Error(factor(CASE)), data = soundrating)
summary(H11) 
H11

# Calculate the effectsize
# Package {effectsize}
F_to_omega2(f = 28.5766, df = 24, df_error = 6750) # sound
F_to_omega2(f = 10.8612, df = 16, df_error = 4498)   # voice alert

### H2: Alarm sounds combined with a voice alarm have a positive influence on ambiguity reduction, ###
# on action motivation and action intention. #
# Influence of the sound with vs. without voice alert | Einfluss von mit vs. ohne Voice Alert #
# H2: Compute 3 t-tests #

### H2.1: Ambiguity reduction (voice as predictor | Voice als Praediktor) ###
as.data.frame(soundrating)
# Prepare dataset for t-tests | Daten fuer t-tests vorbereiten
# Create dataset with columns for sound, and values for ambiguity reduction to compute comparisons between 
# the different experimental conditions with (male/female) and without voice alert |
# Datensatz mit Spalten fuer Sound, und Werte fuer Ambiguity reduction fuer 
# die verschiedenen Versuchsbedingungen mit maennlicher, weiblicher und ohne Sprachansage
wide_amb<-soundrating %>%
  dplyr::select(CASE, voice, sound, ambiguity) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = ambiguity)
# Combined column for male and female voice alert | 
# Kombinierte Spalte von maennlichem und weiblichem Voice Alarm
wide_amb$WM <- (wide_amb$"M"+wide_amb$"W")/2
# Compute t-test for comparison with and without voice alert |
# t-Test durchfuehren fuer den Vergleich von mit und ohne Voice Alert
t.test(wide_amb$WM, wide_amb$L, alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_amb$WM, wide_amb$L, alternative = "two.sided", paired = TRUE))


### H2.2: Motivation (voice as predictor | Voice als Praediktor)
# Prepare dataset for t-tests | Daten fuer t-tests vorbereiten
# Create dataset with columns for sound, and values for motivation to compute comparisons between 
# the different experimental conditions with (male/female) and without voice alert |
# Datensatz mit Spalten fuer Sound, und Werte fuer Motivation fuer 
# die verschiedenen Versuchsbedingungen mit maennnlicher, weiblicher und ohne Sprachansage
wide_mot<-soundrating %>%
  dplyr::select(CASE, voice, sound, motivation) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = motivation)
# Combined column for male and female voice alert | 
# Kombinierte Spalte von maennlichem und weiblichem Voice Alarm
wide_mot$WM <- (wide_mot$"M"+wide_mot$"W")/2
# Compute t-test for comparison with and without voice alert |
# t-Test durchfuehren fuer den Vergleich von mit und ohne Voice Alert
t.test(wide_mot$WM, wide_mot$L, alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_mot$WM, wide_mot$L, alternative = "two.sided", paired = TRUE))

### H2.3: Intention (voice as predictor | Voice als Praediktor)
# Prepare dataset for t-tests | Daten fuer t-tests vorbereiten
# Create dataset with columns for sound, and values for motivation to compute comparisons between 
# the different experimental conditions with (male/female) and without voice alert |
# Datensatz mit Spalten fuer Sound und Werte fuer Action Intention fuer 
# die verschiedenen Versuchsbedingungen mit maennnlicher, weiblicher und ohne Sprachansage
wide_int<-soundrating %>%
  dplyr::select(CASE, voice, sound, intention) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = intention)
# Combined column for male and female voice alert | 
# Kombinierte Spalte von maennlichem und weiblichem Voice Alarm
wide_int$WM <- (wide_int$"M"+wide_int$"W")/2
# Compute t-test for comparison with and without voice alert |
# t-Test durchfuehren fuer den Vergleich von mit und ohne Voice Alert
t.test(wide_int$WM, wide_int$L, alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_int$WM, wide_int$L, alternative = "two.sided", paired = TRUE))


### H3: Alarm sounds with a female voice alarm are more effective than alarm sounds with a male voice alarm ###
# Female vs. male voice alert | Weibliche vs. maennliche Stimme
# H3: t-tests 

### H3.1: Typicality: male vs. female voice alert ###
wide_typ<-soundrating %>%
  dplyr::select(CASE, voice, sound, typicality) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = typicality)
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_typ$M, wide_typ$W, alternative = "two.sided", paired = TRUE)
# data:  wide_typ$M and wide_typ$W
# Effectsize
effectsize(t.test(wide_typ$M, wide_typ$W, alternative = "two.sided", paired = TRUE))


### H3.2: Arousal: male vs. female voice alert ###
wide_arous<-soundrating %>%
  dplyr::select(CASE, voice, sound, arousal) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = arousal)
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_arous$M, wide_arous$W, alternative = "two.sided", paired = TRUE)
# (not significant)
effectsize(t.test(wide_arous$M, wide_arous$W, alternative = "two.sided", paired = TRUE))


### H3.3: Valence: male vs. female voice alert ###
wide_val<-soundrating %>%
  dplyr::select(CASE, voice, sound, valence) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = valence)
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_val$M, wide_val$W, alternative = "two.sided", paired = TRUE)
# (not significant)
effectsize(t.test(wide_val$M, wide_val$W, alternative = "two.sided", paired = TRUE))


### H3.4: Dominance: male vs. female voice alert ###
wide_dom<-soundrating %>%
  dplyr::select(CASE, voice, sound, dominance) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = dominance)
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_dom$M, wide_dom$W, alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_dom$M, wide_dom$W, alternative = "two.sided", paired = TRUE))

### H3.5: Distinctiveness: male vs. female voice alert ###
wide_dist<-soundrating %>%
  dplyr::select(CASE, voice, sound, distinctiveness) %>%
  tidyr::pivot_wider(.,names_from = voice,
                     values_from = distinctiveness)
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_dist$M, wide_dist$W, alternative = "two.sided", paired = TRUE)
# (not significant)
effectsize(t.test(wide_dist$M, wide_dist$W, alternative = "two.sided", paired = TRUE))


### H3.6: Ambiguity reduction: male vs. female voice alert ###
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_amb$M, wide_amb$W, alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_amb$M, wide_amb$W, alternative = "two.sided", paired = TRUE))


### H3.7: Motivation: male vs. female voice alert ###
# Compute t-test for the comparison of male vs. female voice alert |
# t-Test durchfuehren fuer den Vergleich von maennl. vs. weibl. Voice Alert
t.test(wide_mot$M, wide_typ$W, alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_mot$M, wide_mot$W, alternative = "two.sided", paired = TRUE))


#### H3.8: Action intention: male vs. female voice alert ###
t.test(wide_int$M, wide_int$W, alternative = "two.sided", paired = TRUE)
# (not significant)
effectsize(t.test(wide_int$M, wide_int$W, alternative = "two.sided", paired = TRUE))



### H4: As our prior study showed evidence for the effectiveness of alarm sounds with siren-like changing patterns, we assume that those alarm sounds will be ###
# most effective again                                                                                                                                        ###
# Siren-like sounds (5, 6, 7) are more effective than sound 2 | Sirenenartige Toene (5, 6, 7) schneiden besser ab als Ton 2
# 1) Create new variable (5, 6, 7 vs. 2) | neue Variable (5,6,7 vs. 2)
# 2) Compute t-test
# Welch-test (R standard) if variances are inhomogene

### H4.1: Typicality ###
wide_typ_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, typicality) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = typicality)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_typ_h4$siren <- (wide_typ_h4$"5" + wide_typ_h4$"6" + wide_typ_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_typ_h4$"siren", wide_typ_h4$"2", alternative = "two.sided", paired = TRUE)
# data:  wide_typ_h4$siren and wide_typ_h4$"2"
# Effectsize
effectsize(t.test(wide_typ_h4$"siren", wide_typ_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.2: Arousal ###
wide_arous_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, arousal) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = arousal)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_arous_h4$siren <- (wide_arous_h4$"5" + wide_arous_h4$"6" + wide_arous_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_arous_h4$"siren", wide_arous_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_arous_h4$"siren", wide_arous_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.3: Valence ###
wide_val_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, valence) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = valence)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_val_h4$siren <- (wide_val_h4$"5" + wide_val_h4$"6" + wide_val_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_val_h4$"siren", wide_val_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_val_h4$"siren", wide_val_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.4: Dominance ###
wide_dom_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, dominance) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = dominance)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_dom_h4$siren <- (wide_dom_h4$"5" + wide_dom_h4$"6" + wide_dom_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_dom_h4$"siren", wide_dom_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_dom_h4$"siren", wide_dom_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.5: Distinctiveness ###
wide_dist_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, distinctiveness) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = distinctiveness)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_dist_h4$siren <- (wide_dist_h4$"5" + wide_dist_h4$"6" + wide_dist_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_dist_h4$"siren", wide_dist_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_dist_h4$"siren", wide_dist_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.6: Ambiguity Reduction ###
wide_amb_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, ambiguity) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = ambiguity)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_amb_h4$siren <- (wide_amb_h4$"5" + wide_amb_h4$"6" + wide_amb_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_amb_h4$"siren", wide_amb_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_amb_h4$"siren", wide_amb_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.7: Motivation ###
wide_mot_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, motivation) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = motivation)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_mot_h4$siren <- (wide_mot_h4$"5" + wide_mot_h4$"6" + wide_mot_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_mot_h4$"siren", wide_mot_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_mot_h4$"siren", wide_mot_h4$"2", alternative = "two.sided", paired = TRUE))


### H4.8:  Action Intention ###
wide_int_h4<-soundrating %>%
  dplyr::select(CASE, voice, sound, intention) %>%
  tidyr::pivot_wider(.,names_from = sound,
                     values_from = intention)
# Combined column with all siren-like sounds | Kombinierte Spalte aller sirenenartigen Toene
wide_int_h4$siren <- (wide_int_h4$"5" + wide_int_h4$"6" + wide_int_h4$"7")/3
# Group comparisons | Gruppenvergleiche
t.test(wide_int_h4$"siren", wide_int_h4$"2", alternative = "two.sided", paired = TRUE)
# Effectsize
effectsize(t.test(wide_int_h4$"siren", wide_int_h4$"2", alternative = "two.sided", paired = TRUE))
