0
$\begingroup$

I have data that looks like this for repeated measures for the same subjects. Note, the flag column is something I just added to indicate whether there is an increase or decrease in pre vs. post for a given subject.

dput(df)
structure(list(id = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 
6L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L, 
13L, 13L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 
19L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L, 
26L, 26L, 27L, 27L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L, 32L, 
32L, 33L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L, 38L, 38L, 
39L, 39L, 40L, 40L, 41L, 41L, 42L, 42L, 43L, 43L, 44L, 44L, 45L, 
45L, 46L, 46L, 47L, 47L, 48L, 48L, 49L, 49L, 50L, 50L, 51L, 51L, 
52L, 52L, 53L, 53L, 54L, 54L, 55L, 55L, 56L, 56L, 57L, 57L, 58L, 
58L, 59L, 59L, 60L, 60L, 61L, 61L), condition = c("post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre", "post", "pre", "post", "pre", "post", "pre", 
"post", "pre", "post", "pre", "post", "pre", "post", "pre", "post", 
"pre", "post", "pre"), value = c(0.1525, 4.8535, 0.3775, 2.94, 
4.184, 4.827, 3.6445, 1.834, 5.0555, 0.4, 4.771, 3.0745, 0.735, 
5.545, -0.2245, 4.401, 2.221, 5.2995, 4.5405, -0.7275, 2.9745, 
3.57, -0.742, 3.719, 5.903, 3.7465, -0.0595, 3.243, 4.915, 3.8225, 
5.9095, 3.4785, 0.795, 4.9405, 2.736, 4.3145, 4.095, 3.2685, 
-0.4275, 5.111, 3.075, 4.5725, -0.1, 5.024, 1.052, 4.4635, 5.951, 
3.1015, 3.411, 1.806, 1.4345, 4.531, 4.8635, 2.0875, 5.4165, 
4.5985, 5.8595, 5.035, 6.6375, -0.8055, -1.477, 3.1985, -0.004, 
3.7325, 5.285, 2.442, -0.8175, 0.806, -0.08, 0.43, 3.067, 0.6525, 
6.825, 1.9775, 1.5785, -0.376, 3.9845, 3.888, 0.5985, 4.174, 
6.651, 6.228, 4.681, 5.0015, -0.241, 3.9425, 1.7565, 3.643, 0.678, 
0.5905, 5.1105, 1.805, -0.0875, 3.741, 4.1125, 4.69, 5.1755, 
-0.162, 1.897, 3.8855, 5.583, 3.881, -0.343, 4.233, 4.8735, 1.2265, 
-1.1375, 4.131, 6.092, 4.646, -1.317, 3.0335, -0.074, 0.2205, 
4.235, 4.681, 5.3105, 4.238, 5.7515, 3.236, -0.5775, 2.652), 
    flag = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
    TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, 
    TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, 
    FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, 
    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, 
    FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, 
    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, 
    TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
    TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, 
    FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, 
    TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 
    TRUE, TRUE, TRUE, FALSE, FALSE)), class = "data.frame", .Names = c("id", 
"condition", "value", "flag"), row.names = c(NA, -122L))

When I run a paired t-test, the effect is not there. Can't reject null hypothesis that the mean of the differences in value is not different from zero.

t.test(value ~ condition, data = df, paired = TRUE)

    Paired t-test

data:  value by type
t = -1.2077, df = 60, p-value = 0.2319
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -1.3192944  0.3259502
sample estimates:
mean of the differences 
             -0.4966721 

But, when I plot the data, there is a clear pattern of what appears to be 'opposite effect' in two sub groups.

ggplot(df, aes(x = condition, y = value, col = flag, group = id)) + geom_point() + geom_line() + theme_bw() + theme(legend.position = 'none')

A couple of questions:

1) What technique besides paired t-test is appropriate to use in such cases?

2) What criteria can one use to isolate true sub groups vs. just random variation in the data when the evidence is not as stark as in this case?

$\endgroup$
3
$\begingroup$

At first I though there was an interaction between the variables flag and type, but in fact you created flag using the values (according to the sign of the difference).

The classical way to look at such data is a scatter plot:

plot( df$value[ df$type == "A" ], df$value[ df$type == "B" ], 
      asp = 1, xlab = "A", ylab = "B" )
abline(0, 1, lty = 2)

Scatter plot

There’s no clear pattern here. You might argue that there’s a negative correlation (what you called an "opposite effect"), but it’s far from being significant:

> cor( df$value[ df$type == "A" ], df$value[ df$type == "B" ])
[1] -0.08704618
> cor.test( df$value[ df$type == "A" ], df$value[ df$type == "B" ])

    Pearson's product-moment correlation

data:  df$value[df$type == "A"] and df$value[df$type == "B"]
t = -0.67116, df = 59, p-value = 0.5047
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.3315983  0.1684674
sample estimates:
        cor 
-0.08704618 
$\endgroup$
  • $\begingroup$ So, the flag column is something I just created indicating whether there is increase / decrease (pre / post) to be able to plot with color contrast. It is not a variable in original data. But, in that sense, I am also looking for whether there is 'significance' for such opposite effect. $\endgroup$ – user3949008 May 24 '16 at 15:30
  • $\begingroup$ Oh. Then the "clear pattern" you claim to see doesn’t exist. The right way to visualize these data is a scatter plot. I’ll edit my answer. $\endgroup$ – Elvis May 24 '16 at 15:35
  • $\begingroup$ I am sorry, if I am failing to frame my problem right, but, the reason I am using a slope graph to visualize is because it is paired data. Type A values are from 'before' and Type B values are from 'after'. The id column is identifying the same subject. So, some subjects saw increase in value, some saw decrease in value. $\endgroup$ – user3949008 May 24 '16 at 15:49
  • $\begingroup$ Well, yes, the scatter plot allows to see that too, and — I think — in a much better way (some points are above the dotted line : increase in value, others are below : decrease in value). $\endgroup$ – Elvis May 24 '16 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.