,因爲你得到至少一個子組,獨特的地位值對所有得分的你會得到一個錯誤。
這會重現錯誤,所有分數的狀態都是唯一的(等於1)。
dx = read.table(text=' score status
1 1 1
2 2 1
3 3 1 ')
t.test(score ~ status, data = dx)
Error in t.test.formula(score ~ status, data = dx) :
grouping factor must have exactly 2 levels
這個正確的問題,但與t.test
創建另一個已知的問題,你應該有足夠的意見(我想> = 2):
dx = read.table(text=' score status
1 1 1
2 2 1
3 3 2 ')
t.test(score ~ status, data = dx)
Error in t.test.default(x = 1:2, y = 3L) : not enough 'y' observations
最後這個正確的所有問題:
dx = read.table(text=' score status
1 1 1
2 2 1
3 3 2
4 4 2')
t.test(score ~ status, data = dx)
Welch Two Sample t-test
data: score by status
t = -2.8284, df = 2, p-value = 0.1056
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-5.042435 1.042435
sample estimates:
mean in group 1 mean in group 2
1.5 3.5
編輯我沒有給出解決方案就解釋了問題,因爲您沒有提供可重複的示例。
一個解決方案是唯一的好做組計算:
ddply(df, c("freq","snpsincluded"), function(x)
{
if(length(unique(x$status)==2)
pval=t.test(score~status,data=x)$p.value
})
感謝您的快速答覆!我不確定自己理解「你對所有分數都有獨特的地位價值」,但我對這兩種情況和控制都有大約700行。另外,我還要補充一點,爲了清楚起見,我省略了一些其他因素,但這些是我不喜歡對每個組合的數據子集進行t檢驗的原因。如果我對整個數據集進行ttest(不考慮因素),它就可以工作。再次感謝您的幫助。 – madieke
@madieke我添加一些評論來澄清這一點。最好看我的例子。 – agstudy