Can raw means and estimated marginal means be the same ? And when?

63 Views Asked by At

I have read a lot about calculating raw (standard) means and EMM. First are data based (descriptive stats), the latter are model based. I try to learn how to calculate both of them. In my example both results are equal. Variables Message and Relevance are factors with two levels.
What did I do wrong ?

Here is my code:

affect_data1 <- structure(list(Message = c(
  "Happy", "Happy", "Happy", "Happy",
  "Happy", "Dull", "Dull", "Dull", "Dull", "Dull", "Happy", "Happy",
  "Happy", "Happy", "Happy", "Dull", "Dull", "Dull", "Dull", "Dull"
), Relevance = c(
  "Low", "Low", "Low", "Low", "Low", "Low", "Low",
  "Low", "Low", "Low", "High", "High", "High", "High", "High",
  "High", "High", "High", "High", "High"
), PositiveAffect = c(
  10,
  12, 8, 11, 16, 15, 7, 8, 12, 9, 33, 44, 33, 35, 38, 2, 4.56,
  5, 9.5, 8.5
), Combined = structure(c(
  1L, 1L, 1L, 1L, 1L, 2L,
  2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L
), levels = c(
  "HL",
  "DL", "HH", "DH"
), class = "factor", contrasts = structure(c(
  1,
  -1, 0, 0, 0, 0, 1, -1, -0.5, -0.5, 0.5, 0.5
), dim = 4:3, dimnames = list(
  c("HL", "DL", "HH", "DH"), c("c1", "c2", "")
)))), row.names = c(
  NA,
  -20L
), class = c("tbl_df", "tbl", "data.frame"))

library(emmeans)
# Fit a linear model to the data including interactions
modelar <- lm(PositiveAffect ~ Message * Relevance, data = affect_data1)

emmeans_valueses <- emmeans(modelar, specs = ~ Message * Relevance)

# Display the estimated marginal means
summary(emmeans_valueses)

Message Relevance emmean   SE df lower.CL upper.CL
 Dull    High        5.91 1.58 16     2.55     9.27
 Happy   High       36.60 1.58 16    33.24    39.96
 Dull    Low        10.20 1.58 16     6.84    13.56
 Happy   Low        11.40 1.58 16     8.04    14.76

# Now calculating just raw means, calculating means for Message and Relevance variables together:
combined_means <- affect_data1 %>%
  group_by(Message, Relevance) %>%
  summarize(Mean_Positive_Affect = mean(PositiveAffect), .groups="keep")

Message Relevance Mean_Positive_Affect
  <chr>   <chr>                    <dbl>
1 Dull    High                      5.91
2 Dull    Low                      10.2 
3 Happy   High                     36.6 
4 Happy   Low                      11.4 

Both methods give the same results. Is it OK ?
I used emmeans package, but if other ways exist feel free to show it, please.
I would be grateful for explanation regarding this matter, thank you.

0

There are 0 best solutions below