Skip to contents

Multiple factors in a dataframe are said to be connected if a model matrix based on those factors is full rank.

This function provides a formula interface to the lfe::compfactor() function to check for connectedness of the factors.

Usage

con_check(data = NULL, formula = NULL, WW = TRUE, dropNA = TRUE)

Arguments

data

A dataframe

formula

A formula with multiple factor names in the dataframe, like y ~ f1 + f2 + f3

WW

Pass-through argument to compfactor

dropNA

If TRUE, observed data that are NA will be dropped.

Value

A vector with integers representing the group membership of each observation.

References

None

Author

Kevin Wright

Examples

# In the data_eccleston dataframe, each pair of factors is connected.
con_check(data_eccleston, ~ row + trt)
#>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> Levels: 1
con_check(data_eccleston, ~ col + trt)
#>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> Levels: 1
con_check(data_eccleston, ~ row + col)
#>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> Levels: 1
# But all three factors are COMPLETELY disconnected into 16 groups.
con_check(data_eccleston, ~ row + col + trt)
#>  [1] 16 1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
#> Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16