| fac.multinested | R Documentation |
Creates several factors, one for each level of nesting.fac; the levels of each new factor are obtained using the different values of the nested.fac within its level of the nesting.fac by either (i) numbering the different values from 1 to the number of different values or (ii) copying the different values. In both cases, for the values of nested.fac not equal to the level of the values of nested.fac for which a nested factor is being created, the levels are set to outlevel and labelled using outlabel. A factor is not created for a level of nesting.fac with label equal to outlabel. The names of the factors are equal to the levels of nesting.fac; optionally fac.prefix is added to the beginning of the names of the factors. The function is used to split up a nested term into separate terms for each level of nesting.fac.
fac.multinested(nesting.fac, nested.fac = NULL,
fac.prefix = NULL, fac.levs, fac.suffix = NULL,
nested.levs = NA, nested.labs = NA,
outlevel = 0, outlabel = "rest", ...)
nesting.fac |
The |
nested.fac |
The |
fac.prefix |
The prefix to be added to a level in naming a nested |
fac.levs |
The levels to be used in naming the nested |
fac.suffix |
The suffix to be added to a level in naming a nested |
nested.levs |
Optional |
nested.labs |
Optional |
outlevel |
The level to use in the new |
outlabel |
The label to use the |
... |
Further arguments passed to the |
A data.frame containing a factor
for each level of nesting.fac.
The levels of nesting.fac do not have to be equally replicated.
Chris Brien
fac.gen, fac.nested in package dae, factor.
lay <- data.frame(A = factor(rep(c(1:3), c(3,6,4)), labels = letters[1:3]))
lay$B <-fac.nested(lay$A)
#Add factors for B within each level of A
lay2 <- cbind(lay, fac.multinested(lay$A))
canon2 <- designAnatomy(list(~A/(a+b+c)), data = lay2)
summary(canon2)
#Add factors for B within each level of A, but with levels and outlabel given
lay2 <- cbind(lay, fac.multinested(lay$A, nested.levs = seq(10,60,10), outlabel = "other"))
canon2 <- designAnatomy(list(~A/(a+b+c)), data = lay2)
summary(canon2)
#Replicate the combinations of A and B three times and index them with the factor sample
lay3 <- rbind(lay,lay,lay)
lay3$sample <- with(lay3, fac.nested(fac.combine(list(A,B))))
#Add factors for B within each level of A
lay4 <- cbind(lay3, fac.multinested(nesting.fac = lay$A, nested.fac = lay$B))
canon4 <- designAnatomy(list(~(A/(a+b+c))/sample), data = lay4)
summary(canon4)
#Add factors for sample within each combination of A and B
lay5 <- with(lay4, cbind(lay4,
fac.multinested(nesting.fac = a, fac.prefix = "a"),
fac.multinested(nesting.fac = b, fac.prefix = "b"),
fac.multinested(nesting.fac = c, fac.prefix = "c")))
canon5 <- designAnatomy(list(~A/(a/(a1+a2+a3)+b/(b1+b2+b3+b4+b5+b6)+c/(c1+c2+c3))), data = lay5)
summary(canon5)
#Add factors for sample within each level of A
lay6 <- cbind(lay4,
fac.multinested(nesting.fac = lay4$A, nested.fac = lay$sample, fac.prefix = "samp"))
canon6 <- designAnatomy(list(~A/(a/sampa+b/sampb+c/sampc)), data = lay6)
summary(canon6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.