R Markdown

Rationale

In framing theory, a media message consumer’s response – like an attitude, judgment or action – depends at least partly upon exposure to cues embedded in the media message. A cue prompts the message consumer to apply a particular interpretive frame to the message, and this frame application leads to the response.

Considering what the theory says, a cue embedded in an advertisement could influence consumer judgments about the product being advertised. Specifically, the physique of the actor in a fast-food sandwich ad might influence viewer estimates of how many calories the advertised sandwich contains.

Hypothesis

On average, sandwich ad viewers will provide different estimates of the sandwich’s calories, depending on whether the ad’s actor is fit or overweight.

Variables & method

The dependent variable in the analysis was a continuous measure of how many calories ad viewers guessed were in the advertised sandwich. The categorical independent variable indicated whether each viewer had watched an ad featuring a “buff” actor or an ad featuring an actor with a “dad bod.”

A sample of 100 subjects were divided randomly into two groups of 50. Each group then viewed either one ad or the other. After viewing the ad, subjects completed a questionnaire asking, among other things, how many calories they thought were in the advertised sandwich.

An independent-samples t-test was used to test for a statistically significant difference between the average calorie estimates among the “buff” and “dad bod” ad viewers.

Results & discussion

The graph below contrasts the group distributions and averages, and the table shows the results of the t-test.

Independent Samples t-Test Results
Welch's t-test (unequal variances assumed)
Group 1 Group 2 Mean (Group 1) Mean (Group 2) t Statistic Degrees of Freedom p-value 95% CI (Lower) 95% CI (Upper)
Buff Dad bod 584.26 656.28 −2.671 97.069 0.009 −125.53 −18.51

Group distributions appeared normal, and the calorie estimates averaged higher among the “dad bod” ad viewers than among the “buff” ad viewers. The t-test found the difference statistically significant. These results supported the hypothesis.

Code

# ------------------------------
# Setup
# ------------------------------
if (!require("dplyr")) install.packages("dplyr")
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("gt")) install.packages("gt")
if (!require("gtExtras")) install.packages("gtExtras")

library(dplyr)
library(ggplot2)
library(gt)
library(gtExtras)

options(scipen = 999)

# ------------------------------
# Load Data
# ------------------------------
mydata <- read.csv("SandwichAd.csv") # TYPE YOUR DATA FILE'S NAME

mydata <- mydata %>%
  mutate(
    DV = Calories, # TYPE YOUR DEPENDENT VARIABLE'S NAME
    IV = Actor  # TYPE YOUR INDEPENDENT VARIABLE'S NAME
  )

# ------------------------------
# Histograms of DV per IV group with group means
# ------------------------------

# Calculate group means
group_means <- mydata %>%
  group_by(IV) %>%
  summarise(mean_DV = mean(DV, na.rm = TRUE), .groups = "drop")

Graphic <- ggplot(mydata, aes(x = DV)) +
  geom_histogram(binwidth = diff(range(mydata$DV, na.rm = TRUE)) / 30,
                 color = "black", fill = "#1f78b4", alpha = 0.7) +
  # Add group-specific mean lines
  geom_vline(data = group_means, aes(xintercept = mean_DV),
             color = "red", linetype = "dashed", linewidth = 1) +
  facet_grid(IV ~ .) +  # one histogram per group, stacked vertically
  labs(
    title = "DV Distributions by IV Group",
    x = "Dependent Variable",
    y = "Count"
  ) +
  theme_minimal()

# Show graphic
Graphic

# ------------------------------
# Descriptive Statistics
# ------------------------------
mydata %>%
  group_by(IV) %>%
  summarise(
    count = n(),
    mean  = mean(DV, na.rm = TRUE),
    sd    = sd(DV, na.rm = TRUE),
    min   = min(DV, na.rm = TRUE),
    max   = max(DV, na.rm = TRUE)
  )

# ------------------------------
# Normality Check (Shapiro-Wilk)
# ------------------------------
mydata %>%
  group_by(IV) %>%
  summarise(
    W_statistic = shapiro.test(DV)$statistic,
    p_value     = shapiro.test(DV)$p.value
  )

# ------------------------------
# Inferential Tests
# ------------------------------
# Run Welch's t-test (default for two groups)
t_res <- t.test(DV ~ IV, data = mydata, var.equal = FALSE)

# Run Wilcoxon rank-sum test if group sizes < 40 and 
# distributions are non-normal
wilcox.test(mydata$DV ~ mydata$IV)

# Create a tidy summary of results
t_summary <- tibble(
  Group1 = levels(as.factor(mydata$IV))[1],
  Group2 = levels(as.factor(mydata$IV))[2],
  Mean1  = t_res$estimate[1],
  Mean2  = t_res$estimate[2],
  t      = t_res$statistic,
  df     = t_res$parameter,
  p      = t_res$p.value,
  CI_low = t_res$conf.int[1],
  CI_high= t_res$conf.int[2]
)

# ------------------------------
# Present Results as a gt Table (APA style)
# ------------------------------
Table <- t_summary %>%
  gt() %>%
  # Round group means and CI to 2 decimals
  fmt_number(columns = c(Mean1, Mean2, CI_low, CI_high), decimals = 2) %>%
  # Round test statistics, df, and p-value to 3 decimals
  fmt_number(columns = c(t, df, p), decimals = 3) %>%
  tab_header(
    title = "Independent Samples t-Test Results",
    subtitle = "Welch's t-test (unequal variances assumed)"
  ) %>%
  cols_label(
    Group1 = "Group 1",
    Group2 = "Group 2",
    Mean1  = "Mean (Group 1)", 
    Mean2  = "Mean (Group 2)",
    t      = "t Statistic",
    df     = "Degrees of Freedom",
    p      = "p-value",
    CI_low = "95% CI (Lower)",
    CI_high= "95% CI (Upper)"
  )

# ------------------------------
# Visual output
# ------------------------------

# Show the graphic
Graphic

# Show the table
Table