There's a funny inconsistency in how t.test handles paired=T or paired=F. If x and y parameters are lists, paired=F works, but paired=T doesn't.> lg=read.csv("my.csv") > a = subset(lg, condition=="a")["score"] > b = subset(lg, condition=="b")["score"] > t.test(a,b) > t.test(a,b, paired=TRUE)Error in `[.data.frame`(y, yok) : undefined columns selected But this works> a=a[,1] > b=b[,1] > t.test(a,b, paired=TRUE)...
Hi Jack,
Maybe this helps.
# make some data
set.seed(123)
condition <- factor(rep(c("a","b"), each = 5))
score <- rnorm(10);
lg <- data.frame(condition, score)
# Carry out commands
a <- subset(lg,condition=="a")["score"]
b <- subset(lg,condition=="b")["score"]
t.test(a,b,paired=TRUE)
#Error in `[.data.frame`(y, yok) : undefined columns selected
# a and b are still data frames
#So this works. We must refer to score, which is being compared.
t.test(a$score,b$score,paired=TRUE)
a=a[,1]
b=b[,1]
# This now works because a and b are vectors
# so we don't need $ to access score
t.test(a,b, paired=TRUE)
Regards,
Juliet
jacktanner wrote:> > There's a funny inconsistency in how t.test handles paired=T or paired=F. > If x > and y parameters are lists, paired=F works, but paired=T doesn't. > >> lg=read.csv("my.csv") >> a = subset(lg, condition=="a")["score"] >> b = subset(lg, condition=="b")["score"] >> t.test(a,b) >> t.test(a,b, paired=TRUE) > Error in `[.data.frame`(y, yok) : undefined columns selected > > But this works >> a=a[,1] >> b=b[,1] >> t.test(a,b, paired=TRUE) > ... > >It's sort of an accident that this works for the unpaired case. You can follow what happens via debug(stats:::t.test.default) ... there is some code if (paired) xok <- yok <- complete.cases(x, y) else { yok <- !is.na(y) xok <- !is.na(x) } if paired is FALSE, !is.na(y) and !is.na(x) happen to convert x and y into matrices, whence they can be used for the rest of the computations. If paired is TRUE, x and y remain data frames. Bottom line: a data frame with a single column in it really isn't the same as a vector ... -- View this message in context: http://www.nabble.com/suggestion-for-paired-t-tests-tp24651851p24668046.html Sent from the R help mailing list archive at Nabble.com.