[R] suggestion for paired t-tests

Ben Bolker bolker at ufl.edu
Sun Jul 26 17:57:32 CEST 2009




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.




More information about the R-help mailing list