This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# Set seed for reproducibility
set.seed(123)
# Sample size (mirroring Rind & Bordia's ~200 observations)
n <- 200
# Simulate experimental conditions
condition <- sample(c("smiley", "no_smiley"), n, replace = TRUE)
server_sex <- sample(c("male", "female"), n, replace = TRUE)
# Simulate tip percentages based on condition and server sex
tip_pct <- ifelse(condition == "smiley" & server_sex == "female",
rnorm(n, mean = 23, sd = 5), # female + smiley: higher tips
ifelse(condition == "smiley" & server_sex == "male",
rnorm(n, mean = 15, sd = 5), # male + smiley: lower tips
ifelse(condition == "no_smiley" & server_sex == "female",
rnorm(n, mean = 18, sd = 5), # female, no smiley: baseline
rnorm(n, mean = 18, sd = 5) # male, no smiley: baseline
)))
# Build the data frame
tip_data <- data.frame(condition, server_sex, tip_pct)
# View first few rows
head(tip_data)
## condition server_sex tip_pct
## 1 smiley female 33.99405
## 2 smiley female 29.56206
## 3 smiley female 21.67427
## 4 no_smiley male 23.76468
## 5 smiley female 20.92830
## 6 no_smiley female 16.94633
# --- ANALYSIS ---
# Overall t-test: smiley vs no smiley
t.test(tip_pct ~ condition, data = tip_data)
##
## Welch Two Sample t-test
##
## data: tip_pct by condition
## t = -0.90548, df = 197.87, p-value = 0.3663
## alternative hypothesis: true difference in means between group no_smiley and group smiley is not equal to 0
## 95 percent confidence interval:
## -2.3338092 0.8650277
## sample estimates:
## mean in group no_smiley mean in group smiley
## 18.69360 19.42799
# Split by server sex
female_data <- subset(tip_data, server_sex == "female")
male_data <- subset(tip_data, server_sex == "male")
t.test(tip_pct ~ condition, data = female_data)
##
## Welch Two Sample t-test
##
## data: tip_pct by condition
## t = -3.6498, df = 74.566, p-value = 0.0004843
## alternative hypothesis: true difference in means between group no_smiley and group smiley is not equal to 0
## 95 percent confidence interval:
## -6.457843 -1.897129
## sample estimates:
## mean in group no_smiley mean in group smiley
## 18.82456 23.00205
t.test(tip_pct ~ condition, data = male_data)
##
## Welch Two Sample t-test
##
## data: tip_pct by condition
## t = 3.3723, df = 105.32, p-value = 0.001044
## alternative hypothesis: true difference in means between group no_smiley and group smiley is not equal to 0
## 95 percent confidence interval:
## 1.285608 4.954426
## sample estimates:
## mean in group no_smiley mean in group smiley
## 18.60926 15.48924
# --- VISUALIZATION ---
library(ggplot2)
ggplot(tip_data, aes(x = condition, y = tip_pct, fill = condition)) +
geom_boxplot() +
facet_wrap(~ server_sex) +
labs(title = "Tip % by Smiley Face Condition and Server Sex",
x = "Condition", y = "Tip Percentage") +
theme_minimal()