pair t test Error in complete.cases(x, y) : not all arguments have the same length
The problem is that you are trying to use the t test for paired samples it is necessary that you have the same number of subjects before and after the measurement, at its output you see that it has 180 of type 0 and 57 for 1, it should have the same amount of 0 and 1.
noch4 = data.frame(Diarrhea = as.numeric(rpois(237,50)), Max_by_90_H2SPos_12 = as.numeric(c(rep(0,180),rep(1,57))))
table(noch4$Max_by_90_H2SPos_12)
str(noch4$Diarrhea)
str(noch4$Max_by_90_H2SPos_12)
t.test(Diarrhea ~ Max_by_90_H2SPos_12, data = noch4, paired=T)
Notice how I do a filter to get the same number of subjects
noch = noch4[124:237,]
table(noch$Max_by_90_H2SPos_12)
0 1
57 57
t.test(Diarrhea ~ Max_by_90_H2SPos_12, data = noch, paired=T)
Paired t-test
data: Diarrhea by Max_by_90_H2SPos_12
t = 0.99629, df = 56, p-value = 0.3234
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1.134814 3.380428
sample estimates:
mean of the differences
1.122807
The logical thing is that if you have for example 200 sujestos and measured the variable Diarrhea, (preTest) and then I apply some reagent and re-measured the variable Diarrhea (posTest), the number of subjects is 200, that is, do not change.
Comments
-
lxcfuji almost 2 years
Sorry I'm asking silly question...
I have a simple dataset and want to do paired T.test, because the measurements are from same subjects
heres my code:
t.test(Diarrhea ~ Max_by_90_H2SPos_12, data = noch4, paired=T)
and it gives me error:Error in complete.cases(x, y) : not all arguments have the same length
There is no missing value in these 2 variables, I don't understand. Here's my data look like:
table(noch4$Max_by_90_H2SPos_12) 0 1 180 57
str(noch4$Diarrhea) num [1:237] 27 60 44 1 43 28 57 11 2 58 ... str(noch4$Max_by_90_H2SPos_12) num [1:237] 0 0 0 0 0 0 0 0 0 0 ...
Thank you for any help.
-
emilliman5 about 6 yearsWhat does
table(noch4$Max_by_90_H2SPos_12, noch4$Diarrhea, useNA="ifany")
produce? -
IRTFM about 6 yearsI'm guessing you are confused about the statistic that should be used. My guess is that you want to consider the degree of association of a numeric value's distribution in categories of the 1/0 value (perhaps a disease or other binary feature.)
-
lxcfuji about 6 years@42- yes, your are correct. I shouldn't use paired option, as I had wrong concept on it.
-
-
lxcfuji about 6 yearsOh, yeah! thats totally make sense! thank you so much.
-
IRTFM about 6 yearsThis is so wrong. You should not continue to follow the questioner's misguided effort to use
paired=TRUE
. Wrong. Wrong. Wrong!