2014-07-03 62 views
0

我希望執行帶有多個獨立分組變量的bartlett.test。但是,會產生錯誤。bartlett.test通過公式col1〜col2 + col3失敗

下面是一些數據:

d=read.table(text=' 
1 w e 
2 w e 
3 w r 
3 e r 
4 e r 
5 e e 
4 w r 
6 e e') 

當我測試方差齊性有一個分組變量只能用公式V1〜V2,一切都是完美的:

bartlett.test(V1 ~ V2, data = d) 

    Bartlett test of homogeneity of variances 

data: V1 by V2 
Bartlett's K-squared = 0, df = 1, p-value = 1 

但是,試圖多個獨立的時變量,導致錯誤:

bartlett.test(V1 ~ V2 + V3, data = d) 
Error in bartlett.test.formula(V1 ~ V2 + V3, data = d) : 
    'formula' should be of the form response ~ group 

然而我想測試homoge與多列方差齊性,即測試V1〜V2 + V3,所以對此有所幫助。

回答

0

This tutorial表明「使用多個獨立變量時,必須使用interaction函數將IV合併爲一個具有所有因素組合的單個變量,如果未使用,則這將是錯誤的自由度,而p值將是錯誤的。「因此,

bartlett.test(V1 ~ interaction(V2, V3), data = d) 
# Bartlett test of homogeneity of variances 
# 
# data: V1 by interaction(V2, V3) 
# Bartlett's K-squared = 0, df = 3, p-value = 1 
相關問題