Description Usage Arguments Details Value Note Author(s) References Examples
Various Tests for Nested Factors.
1 2 3 4 5 6 7 |
a |
a factor, something coercible to a factor, or a list of such having equal lengths (e.g. data.frame) |
b |
like |
all |
whether to include first instances: see details |
x |
an object like |
within |
An object like |
... |
extra arguments passed to other methods |
We propose an idiom pertaining to two factors (or interactions) of equal length, in which either a crosses b, or b nests a. Equivalently, in the former case we could say b is crossed on/by a; in the latter we could say a is nested in b. In the case that b nests a, it must be true that b is constant within a. For example, if treatment nests replicate, then for multiple observations of a single level of replicate, all observations of treatment must be the same. The value of replicate implies the value of treatment (though the reverse need not be true).
Formally, a crosses b if any level of a is associated with more than one level of b.
In this case, b is not constant within a. If you are wondering why
!constant(x,y)
, examine crosses(y,x)
.
crosses()
is the basis for all other functions, and is useful for determining
positions at which crossing occurs (or nesting fails). For each level of a, it returns
FALSE for the first unique value of b, and TRUE for any others. If all
is TRUE,
however, it returns TRUE for the first unique value of b when there are others.
For the following equivalency table, all assertions in a row are true if any of them is true.
crosses | crossed.on | nests | nested.in | constant |
a %crosses% b | b %crossed.on% a | !b %nests% a | !a %nested.in% b | !constant(b,within = a) |
b %crosses% a | a %crossed.on% b | !a %nests% b | !b %nested.in% a | !constant(a,within = b) |
!a %crosses% b | !b %crossed.on% a | b %nests% a | a %nested.in% b | constant(b,within = a) |
!b %crosses% a | !a %crossed.on% b | a %nests% b | b %nested.in% a | constant(a,within = b) |
Logical vector for crosses()
; scalar logical for all others.
All these functions are NA-safe; i.e., they treat NA
as a distinct level.
Tim Bergsma
http://metrumrg.googlecode.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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),c(1,2,3)) # FALSE TRUE TRUE
crosses(c(1,1,1),c(1,2,2)) # FALSE TRUE TRUE
crosses(c(1,1,1),c(2,2,1)) # FALSE FALSE TRUE
crosses(c(1,1,1),c(1,2,3), all=TRUE) # TRUE TRUE TRUE
crosses(c(1,2,3),c(1,1,1)) # FALSE FALSE FALSE
crosses(c(NA,2,3),c(NA,NA,NA)) # FALSE FALSE FALSE
constant(Theoph$Wt,within=Theoph$Subject)#TRUE
trt <- c('a','a','a','b')
rep <- c(1,1,2,3)
trt %crosses% rep # TRUE
rep %nests% trt # FALSE
trt %nests% rep # TRUE
rep %nested.in% trt # TRUE
rep %crosses% trt # FALSE
trt %crossed.on% rep #FALSE
constant(trt,within=rep) # TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.