bartlett.test fail with formula col1~col2+col3
r, variance
Solution
This tutorial suggests that "With multiple independent variables, the `interaction` function must be used to collapse the IV's into a single variable with all combinations of the factors. If it is not used, then the will be the wrong degrees of freedom, and the p-value will be wrong.". Thus,
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
Problem
I wish to perform a `bartlett.test` with multiple independent grouping variables. However, an error is generated. Here is some data: ``` 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') ``` When I test the homogeneity of variance with one grouping variable only using formula V1 ~ V2, everything is perfect: ``` 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 ``` But when trying multiple independent variables, results in an error: ``` 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 ``` And yet I want to test homogeneity of variance with multi-column, that is, test V1 ~ V2 + V3, so any assistance is appreciated.