Description Usage Arguments Details Value Methods (by class) Examples
modelMeans
is a generic function for computing adjusted or unadjusted
cell means in ANOVA designs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | modelMeans(...)
## Default S3 method:
modelMeans(
.arraydat,
factordef,
bwdat = NULL,
term = NULL,
adjusted = FALSE,
...
)
## S3 method for class 'arrayAnova'
modelMeans(model = NULL, term = NULL, adjusted = FALSE, ...)
## S3 method for class 'tanova'
modelMeans(model = NULL, term = NULL, adjusted = FALSE, ...)
|
... |
not used yet |
.arraydat |
a numeric array with named dimnames containing the EEG (or other) data. Missing values are not allowed. |
factordef |
a named list of factor definitions, containing the following elements:
|
bwdat |
a data.frame which contains the identification codes (factordef$w_id) and all subject-level variables (usually factors) listed in 'factordef$between'. Missing values are not allowed. |
term |
a character vector of model terms; a separate array of cell means is returned for each term. The default is NULL, in which case all terms (that is, the means corresponding to all main effects and interactions) are returned. For custom terms, note that interaction terms must be given as "factorA*factorB" and not as "factorA:factorB". |
adjusted |
a logical value if the cell means should be adjusted for unbalanced data (default: FALSE). See Details. |
model |
an object returned by |
If 'adjusted' is set to FALSE (the default), modelMeans
fits
separate models for each model term and computes the model-based predictions
for a reference grid which contains the mean and the 1SD value for continuous
covariates, and all levels of the factor variables in the design. If
'adjusted' is set to TRUE, the means are simply the marginal means of the
predicted means of the highest-order interaction term. This is equivalent to
the so-called LS means (least-squares means) in the SAS terminology.
This distinction is only relevant if the design is unbalanced, that is, the
sample sizes in a between-subject design are unequal (note that the input
array may not contain missing values, therefore the within subject part of
the design is always balanced). For such datasets the lower order
interaction or main effect means can substantially differ from the averages
of the corresponding higher-order means if 'adjusted' is FALSE.
The function returns a named list of arrays; the names are the model terms.
default
: Default method
arrayAnova
: Method for arrayAnova
objects
tanova
: Method for tanova
objects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # example data
data(erps)
dat_id <- attr(erps, "id") # to get group memberships
# make the dataset unbalanced to illustrate the difference between adjusted
# and unadjusted means
erps <- subsetArray(erps, list(id = 2:20))
dat_id <- dat_id[2:20, ]
# compute the means for the group*stimclass*pairtype interaction and all
# other lower-order terms
fdef <- list(between = "group",
within = c("stimclass", "pairtype"))
means <- modelMeans(erps, fdef, bwdat = dat_id)
# the same for the least-squares means
means_adj <- modelMeans(erps, fdef, bwdat = dat_id, adjusted = TRUE)
# this is an unbalanced dataset, so the means for the highest order
# interaction are identical, but the marginal means are not
stopifnot(identical(
TRUE,
all.equal(means$`group*stimclass*pairtype`,
means_adj$`group*stimclass*pairtype`))
)
stopifnot(!identical(
TRUE,
all.equal(means$`stimclass*pairtype`,
means_adj$`stimclass*pairtype`))
)
# simple means for the Fz channel at time 200, for identical pairs in the
# "A" stimulus class, separately for the two reading groups
simple_means <- sapply(c("control", "dl"), function(g)
mean(subsetArray(erps,
list(chan = "Fz", time = "200",
stimclass = "A", pairtype = "ident",
id = dat_id$group == g)))
)
stopifnot(identical(
TRUE,
all.equal(means$`group*stimclass*pairtype`["Fz", "200", , "A", "ident"],
simple_means))
)
# the same ignoring the groups
simple_mean_nogroup <- mean(subsetArray(erps,
list(chan = "Fz", time = "200",
stimclass = "A", pairtype = "ident")))
stopifnot(identical(
TRUE,
all.equal(means$`stimclass*pairtype`["Fz", "200", "A", "ident"],
simple_mean_nogroup))
)
stopifnot(identical(
TRUE,
all.equal(means_adj$`stimclass*pairtype`["Fz", "200", "A", "ident"],
mean(simple_means)))
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.