%nests% {MIfuns}R Documentation

Test for Nested Factors (beta)

Description

Various Tests for Nested Factors.

Usage

a %nests% b
a %nested.in% b
crosses(a,b)
constant(x,within)

Arguments

a A list of equal length factors, or one factor.
b A list of factors, or one factor, same length as a.
x An object like a, or a dataframe.
within An object like b, or just column names in x for the data.frame version.

Details

nests tests whether the factor(s) on the right are nested within the factor(s) on the left: i.e. b implies a. nested.in tests the opposite: i.e., for unique interaction-wise levels of a, is there exactly one interaction-wise corresponding level in b (a implies b)? constant, by default, tests whether within implies x.

crosses is the basis for all other functions. For each level in b, it checks for corresponding levels of a, returning FALSE for the first and TRUE for any others, in which cases a crosses b, or b is crossed on (not nested in) a.

Value

Logical vector for crosses; atomic logical for all others.

Note

All these functions are NA-safe; i.e., they treat NA as a distinct level.

Author(s)

Tim Bergsma

Examples

CO2[,c("Type","Treatment")] %nests% CO2$Plant #TRUE
CO2$Plant %nested.in% CO2$Type #TRUE
with(CO2,constant(list(Type,Treatment),within=Plant)) #TRUE
with(ChickWeight,constant(Diet,within=Chick)) #TRUE
with(ChickWeight,constant(weight,within=list(Chick,Time))) #TRUE
crosses(c(1,1,1,NA,NA,4),c(2,3,3,NA,5,5)) #FALSE FALSE FALSE FALSE FALSE TRUE

[Package MIfuns version 3.2.9 Index]