balancedGrouped.Rd
Create a groupedData
object from a data matrix. This function
can be used only with balanced data. The opposite conversion, from a
groupedData
object to a matrix
, is done with asTable
.
balancedGrouped(form, data, labels=NULL, units=NULL)
A formula of the form y ~ x | g
giving the name of
the response, the primary covariate, and the grouping factor.
A matrix or data frame containing the values of the
response grouped according to the levels of the grouping factor
(rows) and the distinct levels of the primary covariate (columns).
The dimnames
of the matrix are used to construct the levels of
the grouping factor and the primary covariate.
an optional list of character strings giving labels for
the response and the primary covariate. The label for the primary
covariate is named x
and that for the response is named
y
. Either label can be omitted.
an optional list of character strings giving the units for
the response and the primary covariate. The units string for the
primary covariate is named x
and that for the response is
named y
. Either units string can be omitted.
A balanced groupedData
object.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
OrthoMat <- asTable( Orthodont )
Orth2 <- balancedGrouped(distance ~ age | Subject, data = OrthoMat,
labels = list(x = "Age",
y = "Distance from pituitary to pterygomaxillary fissure"),
units = list(x = "(yr)", y = "(mm)"))
Orth2[ 1:10, ] ## check the first few entries
#> Grouped Data: distance ~ age | Subject
#> <environment: 0x55c546f8f780>
#> age Subject distance
#> 1 8 M16 22.0
#> 2 10 M16 21.5
#> 3 12 M16 23.5
#> 4 14 M16 25.0
#> 5 8 M05 20.0
#> 6 10 M05 23.5
#> 7 12 M05 22.5
#> 8 14 M05 26.0
#> 9 8 M02 21.5
#> 10 10 M02 22.5
# Pinheiro and Bates, p. 109
ergoStool.mat <- asTable(ergoStool)
balancedGrouped(effort~Type|Subject,
data=ergoStool.mat)
#> Grouped Data: effort ~ Type | Subject
#> <environment: 0x55c546f8f780>
#> Type Subject effort
#> 1 T1 8 7
#> 2 T2 8 11
#> 3 T3 8 8
#> 4 T4 8 7
#> 5 T1 5 8
#> 6 T2 5 11
#> 7 T3 5 8
#> 8 T4 5 7
#> 9 T1 4 7
#> 10 T2 4 11
#> 11 T3 4 10
#> 12 T4 4 9
#> 13 T1 9 9
#> 14 T2 9 13
#> 15 T3 9 10
#> 16 T4 9 8
#> 17 T1 6 9
#> 18 T2 6 11
#> 19 T3 6 11
#> 20 T4 6 10
#> 21 T1 3 7
#> 22 T2 3 14
#> 23 T3 3 13
#> 24 T4 3 9
#> 25 T1 7 8
#> 26 T2 7 12
#> 27 T3 7 12
#> 28 T4 7 11
#> 29 T1 1 12
#> 30 T2 1 15
#> 31 T3 1 12
#> 32 T4 1 10
#> 33 T1 2 10
#> 34 T2 2 14
#> 35 T3 2 13
#> 36 T4 2 12