0

I guess this is a trivial concern but I can't figure it out... When performing an independent t-test I always get slightly different results for the mean of group 1 when comparing it to the calculated mean with the simple mean(x, ...) function. Is there a simple explanation for this?

Here's my code:

dummy=ifelse(df$age>=median(df$age,na.rm = TRUE),1,0)
t.test(Meaningfulness~dummy, var.equal=TRUE, na.rm=TRUE)

mean(Meaningfulness[df$age<=median(df$age,na.rm = TRUE)], na.rm = TRUE)

The mean for group 1 as in the output of the t-test is: 4.948307 When calculated with the mean function it is: 4.979567

Interestingly the mean for the second group doesn't differ between the t-test function and the mean function...

Also which mean should I report then? I assumed the mean from the t-test output as significance levels trace back to that one. On the other hand, when calculating effect size (Cohen's d) I use the mean from the mean function. So which number do you recommend to report in the tables and text?

Thanks in advance! :)

Newby
  • 1
  • 2
    The "dummy" flag splits age for the t-test using `age >= median`, but your call to `mean` uses `age <= median`. Could that be the difference? – jdobres Sep 01 '21 at 14:33
  • Good point! Unfortunately still not the solution... I just changed it to dummy=ifelse(df$age<=median .... Now the means for group 1 are equal but the means for group 2 are unequal (mean from mean function: 5.147837; mean from t-test: 5.135472) But this is an indicator that the error might lie in the dummy variable... mean for group 2 is calculated like this btw: mean(Meaningfulness[df$age>=22],na.rm=TRUE) – Newby Sep 01 '21 at 15:10
  • @Newby Can you provide your data with `dput()` – Vinícius Félix Sep 01 '21 at 16:07

0 Answers0