Hello List, I'm trying to do a paired t-test, and I'm wondering if it's consistent with equations. I have a dataset that has a response and two treatments (here's an example):
ID trt order resp 17 1 0 1 0.0037513592 18 2 0 1 0.0118723051 19 4 0 1 0.0002610251 20 5 0 1 -0.0077951450 21 6 0 1 0.0022339952 22 7 0 2 0.0235195453 The subjects were randomized and assigned to receive either the treatment or the placebo first, then the other. I know I'll eventually have to move on to a GLM or something that incorporates the order, but for now I wanted to start with a simple t.test. My problem is that, if I get the responses into two vectors x and y (sorted by ID) and do a t.test, and then compare that to a formula t.test, they aren't the same. > t.test(x,y,paired=TRUE) Paired t-test data: x and y t = -0.3492, df = 15, p-value = 0.7318 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.010446921 0.007505966 sample estimates: mean of the differences -0.001470477 > t.test(resp~trt,data=dat1[[3]],paired=TRUE) Paired t-test data: resp by trt t = -0.3182, df = 15, p-value = 0.7547 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.007096678 0.005253173 sample estimates: mean of the differences -0.0009217521 What I'm assuming is that the equation isn't retaining the inherent order of the dataset, so the pairing isn't matching up (even though the dataset is ordered by ID). Is there a way to make the t.test retain the correct ordering? Thanks, Sam ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.