Next: ffdesign2() Up: Design Macros Help File Previous: confound3()   Contents

# ems()

Usage:
 ```ems(Model,randomvars[,marg:T] [,restrict:F] [,nonhier:T] [,keep:T]\ [,print:T]), CHARACTER scalar model, CHARACTER vector randomvars ```

Keywords: ANOVA, analysis, factorial
```ems(Model,Randomvars) computes the expected mean squares for the terms
in the ANOVA for the model given in CHARACTER scalar Model.  Randomvars
is a CHARACTER vector specifying the names of factors in the model which
are random.  Randomvars can also be REAL with integer elements
specifying the index of a factor in the model.  If there are no random
factors, Randomvars should be NULL.

In this default use, ems() computes sequential (Type I) sums of squares
for the the restricted (mixed effects add to zero across fixed factors)
model, prints these expected means squares for each term, and returns no
value.  Contributions from random terms are shown as multiples of the
variance component (for example, 16V(a.b)); contributions from fixed
terms are shown as a multiple of a quadratic function for the term, for
example, 32Q(c).  In a balanced design, the Q() function is the sum of
the squared coefficients divided by degrees of freedom, for example,
sum(c^2)/(K-1).  In an unbalanced situation, Q(c) is a more complicated
quantity defined using matrix algebra.

See below for the use of keywords to change the action of ems().

ems() works only for factors -- no variates are allowed in the model.

ems() works for both balanced and unbalanced data.

ems() assumes that if a factor first appears in an interaction, then that
factor is nested in the other terms of the interaction.  For example, if
the first appearance of factor c is in the term a.b.c, then c is assumed
nested in the a.b combinations.  This nesting is assumed in the
remainder of the model.  That is, continuing the example, if there is a
later term c.d, it will be interpreted as a.b.c.d even though a.b.c.d is
not specifically in the model.

When a term contains the first appearance in the model of more than one
factor, ems() assumes that the new factors are merged to make a single
factor, whose number of levels is the product of the numbers of levels
in the factors being merged.  For example, if the first appearance of
factors b and c with 5 and 3 levels, respectively is in the term a.b.c,
then b and c together are considered a single factor with 15 levels.
This grouping is assumed in the remainder of the model.  That is,
continuing the example, if there is a later term c.d, it will be
interpreted as b.c.d even though b.c.d is not specifically in the model.
This grouped factor is interpreted as random if any of the factors in
the group is random.

ems() uses the "synthesis" method of Hartley, as explained in 10.5.2 of
R. R. Hocking (1985), The Analysis of Linear Models, Brooks/Cole,
Belmont, CA.

The examples below are based on balanced two factor and three factor
models with a total of 64 responses.  All factors have 2 levels so two
factor and three factor models have 16 and 8 replications, respectively.
In some examples, one of the responses is set to MISSING to destroy
balance.

A fully nested model, with c fixed and both d and e random.
Cmd> ems("y=c/d/e",vector("d","e"))
EMS(CONSTANT) = V(ERROR1) + 8V(c.d.e) + 16V(c.d) + 64Q(CONSTANT)
EMS(c) = V(ERROR1) + 8V(c.d.e) + 16V(c.d) + 32Q(c)
EMS(c.d) = V(ERROR1) + 8V(c.d.e) + 16V(c.d)
EMS(c.d.e) = V(ERROR1) + 8V(c.d.e)
EMS(ERROR1) = V(ERROR1)

A 3 factor crossed model, with c and d fixed, e random.
Cmd> ems("y=c*d*e",3) # e is factor 3
EMS(CONSTANT) = V(ERROR1) + 32V(e) + 64Q(CONSTANT)
EMS(c) = V(ERROR1) + 16V(c.e) + 32Q(c)
EMS(d) = V(ERROR1) + 16V(d.e) + 32Q(d)
EMS(c.d) = V(ERROR1) + 8V(c.d.e) + 16Q(c.d)
EMS(e) = V(ERROR1) + 32V(e)
EMS(c.e) = V(ERROR1) + 16V(c.e)
EMS(d.e) = V(ERROR1) + 16V(d.e)
EMS(c.d.e) = V(ERROR1) + 8V(c.d.e)
EMS(ERROR1) = V(ERROR1)

A 2 factor crossed model with unbalanced data, c fixed and d random
Cmd> y1 <- y[1]; y[1] <- ? # make data unbalanced

Cmd> ems("y=c*d",2) # d is factor 2
EMS(CONSTANT) = V(ERROR1) + 0.0080645V(c.d) + 31.508V(d) +
0.0079365Q(c) + 63Q(CONSTANT)
EMS(c) = V(ERROR1) + 15.746V(c.d) + 0.0081925V(d) + 31.492Q(c)
EMS(d) = V(ERROR1) + 0.0042316V(c.d) + 31.484V(d)
EMS(c.d) = V(ERROR1) + 15.742V(c.d)
EMS(ERROR1) = V(ERROR1)

Use of Keywords to change the action of ems().
ems(Model,Randomvars,keep:T) suppresses printed output but returns a
structure (described below) containing the results.  If you want the
printed output too, use keep:T,print:T.

ems(Model,Randomvars,marg:T) computes expected mean squares based on
adjusted (Type III) sums of squares.

ems(Model,Randomvars,restrict:F) computes expected mean squares assuming
no marginal restrictions on any random effects in the model that have
two or more dimensions.  Thus, for example, when the model is
"y=c+D+c.D", where c is fixed and D is random, it is not assumed that
the c.D effects sum to zero for each level of D.

ems(Model,Randomvars,nonhier:T) computes expected mean squares for an
analysis of variance that does not enforce the usual MacAnova hierarchy
assumptions.  That is, for example, model "y=a+b+c+a.b.c" does not imply
that the two-way interaction degrees of freedom are part of the "a.b.c"
term.  You cannot use anova() to compute such an analysis although it
can be done (if you know how) using swp().

These keywords can be used together.  For example, ems(Model,Randomvars,
marg:T,restrict:F) provides answers equivalent to the EMS in SAS PROC
GLM.

More examples, still with y[1] MISSING:
Cmd> ems("y=c*d",2,marg:T) # crossed with d random
EMS(CONSTANT) = V(ERROR1) + 31.475V(d) + 62.951Q(CONSTANT)
EMS(c) = V(ERROR1) + 15.742V(c.d) + 31.475Q(c)
EMS(d) = V(ERROR1) + 31.475V(d)
EMS(c.d) = V(ERROR1) + 15.742V(c.d)
EMS(ERROR1) = V(ERROR1)

Cmd> ems("y=c*d",2,restrict:F) # crossed with d random
EMS(CONSTANT) = V(ERROR1) + 15.762V(c.d) + 31.508V(d) + 0.0079365Q(c)
+ 63Q(CONSTANT)
EMS(c) = V(ERROR1) + 15.754V(c.d) + 0.0081925V(d) + 31.492Q(c)
EMS(d) = V(ERROR1) + 15.746V(c.d) + 31.484V(d)
EMS(c.d) = V(ERROR1) + 15.738V(c.d)
EMS(ERROR1) = V(ERROR1)

Cmd> ems("y=c*d",2,marg:T,restrict:F) # same as SAS PROC GLM
EMS(CONSTANT) = V(ERROR1) + 15.738V(c.d) + 31.475V(d) + 62.951Q(CONSTANT)
EMS(c) = V(ERROR1) + 15.738V(c.d) + 31.475Q(c)
EMS(d) = V(ERROR1) + 15.738V(c.d) + 31.475V(d)
EMS(c.d) = V(ERROR1) + 15.738V(c.d)
EMS(ERROR1) = V(ERROR1)

Cmd> y[1] <- y1 # restore value for y[1] to regain balance

Cmd> ems("y=c*d+e+c.d.e",3)
EMS(CONSTANT) = V(ERROR1) + 32V(e) + 64Q(CONSTANT)
EMS(c) = V(ERROR1) + 8V(c.d.e) + 32Q(c)
EMS(d) = V(ERROR1) + 8V(c.d.e) + 32Q(d)
EMS(c.d) = V(ERROR1) + 8V(c.d.e) + 16Q(c.d)
EMS(e) = V(ERROR1) + 32V(e)
EMS(c.d.e) = V(ERROR1) + 8V(c.d.e)
EMS(ERROR1) = V(ERROR1)

Cmd> ems("y=c*d+e+c.d.e",3,nonhier:T)
EMS(CONSTANT) = V(ERROR1) + 32V(e) + 64Q(CONSTANT)
EMS(c) = V(ERROR1) + 32Q(c)
EMS(d) = V(ERROR1) + 32Q(d)
EMS(c.d) = V(ERROR1) + 8V(c.d.e) + 16Q(c.d)
EMS(e) = V(ERROR1) + 32V(e)
EMS(c.d.e) = V(ERROR1) + 8V(c.d.e)
EMS(ERROR1) = V(ERROR1)

Note that 'nonhier:T' makes the c.d.e term disappear from the EMS for
the fixed terms; compare with the default hierarchical model that
precedes it.

Structure returned with keep:T
When 'keep:T' is an argument, the structure returned has components
'df', 'ss', 'termnames', 'coefs', and 'rterms'.
Component   Description
df         REAL Vector of degrees of freedom for all terms in model
ss         REAL Vector of sums of squares for all terms in model
termnames  CHARACTER vector of labels for each term
coefs      REAL matrix with coefs[i,j] the coefficient for term j in
the EMS of term i
rterms     LOGICAL vector with T indicating that a term is random.

Components ss and df are just those computed from a MacAnova anova()
command (possibly with marg:T as needed), and may not be in conformance
with the model as used by ems() for the following reasons:
1. anova() computes only hierarchical models, while you may specify
nonhierarchical models in ems() by using nonhier:T.
2. ems() enforces nesting and grouping.  If b first appears in a.b then b
is nested in a and any appearance of b in a later term implies the
presence of a.  anova() does no such enforcing.  For example, in
"y=a+a.b+c+b.c", b.c would be interpreted by ems() as a.b.c while
anova() would not include a.b.c in the model.  If b and c first
appear together, then "y=b.c+d+c.d" is interpreted in ems() as
"y=b.c+d+b.c.d".

More examples, with 2^2 design in 16 replicates:
Cmd> ems("y=c*d",2)
EMS(CONSTANT) = V(ERROR1) + 32V(d) + 64Q(CONSTANT)
EMS(c) = V(ERROR1) + 16V(c.d) + 32Q(c)
EMS(d) = V(ERROR1) + 32V(d)
EMS(c.d) = V(ERROR1) + 16V(c.d)
EMS(ERROR1) = V(ERROR1)

Cmd> ems("y=c*d",2,keep:T)
component: df
(1)          1          1          1          1         60
component: ss
(1)    0.76155   0.036871    0.31116      1.623     56.318
component: termnames
(1) "CONSTANT"
(2) "c"
(3) "d"
(4) "c.d"
(5) "ERROR1"
component: coefs
(1,1)         64          0         32          0          1
(2,1)          0         32          0         16          1
(3,1)          0          0         32          0          1
(4,1)          0          0          0         16          1
(5,1)          0          0          0          0          1
component: rterms
(1) F       F       T       T
```

Gary Oehlert 2003-01-15