Description Usage Arguments Details Value See Also Examples
View source: R/nauf_trms_fr_x_z.R
nauf_model.frame creates a model frame which employs
nauf_contrasts for unordered factors.
1 2 3 |
formula, data, subset, ... |
See |
na.action, drop.unused.levels, xlev, contrasts |
Changes from default values for these arguments are ignored with a warning. |
ncs_scale |
A positive number passed as the |
First, the default method for model.frame is called.
Then any variable in the resulting model frame that is not an unordered
factor but has only two unique non-NA values is coerced to an
unordered factor. Unordered factors are then assigned contrasts with
named_contr_sum, passing ncs_scale as the
function's scale argument. Then, necessary contrast changes in
interaction terms and random effects slopes are determined as described in
nauf_contrasts.
The recommended usage is to first standardize the
regression variables, and then use the formula and data
elements in the resulting standardized object as arguments to
nauf_model.frame. When this is done, ncs_scale is obtained
from the standardized.scale attribute of the formula, unless
ncs_scale is specified as a value which does not match the
standardized scale, in which case the explicitly specified
ncs_scale argument is used with a warning. If
standardize is not used prior to calling
nauf_model.frame, then ncs_scale defaults to 1 unless
explicitly specified in the function call, in which case the specified value
is used.
Changes from the following default values are ignored with a warning:
This default value is required in order for
NA values to be treated as defined in
nauf_contrasts.
This default value is set because
nauf_model.frame assumes that data is not new data. To
create a nauf.frame with new data, the terms
attribute of an already existing nauf.frame (which
has class nauf.terms) can be used as the
formula argument to model.frame.
This default is necessary for the same reasons as the
default value for drop.unused.levels.
For unordered factors, contrasts are automatically
created with named_contr_sum, as sum contrasts
are necessary to implement nauf_contrasts. To specify
custom contrasts for ordered factors, the custom contrasts should be
explicitly assigned to the ordered factor in data (this is
automatically done if standardize is used
first as recommended).
A model frame with second class attribute nauf.frame. Its
formula attribute has class nauf.formula and its terms
attribute has class nauf.terms.
nauf_contrasts for a description of the contrasts
applied to unordered factors, nauf_model.matrix for obtaining
a fixed effects model matrix, and nauf_glFormula for
obtaining both fixed effects and random effects model matrices.
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 | dat <- plosives
dat$spont[dat$dialect == "Valladolid"] <- NA
form <- intdiff ~ voicing * dialect * spont +
(1 + voicing * spont | speaker) + (1 + dialect | item)
## default behavior when standardize is not used
# defaults to ncs_scale = 1
mf <- nauf_model.frame(form, dat)
# uses specified ncs_scale = 0.5
mf_0.5 <- nauf_model.frame(form, dat, ncs_scale = 0.5)
## standardize first (recommended use)
sobj <- standardize(form, dat)
sobj_0.5 <- standardize(form, dat, scale = 0.5)
# uses ncs_scale = 1 from attr(sobj$formula, "standardized.scale")
mf_sobj <- nauf_model.frame(sobj$formula, sobj$data)
# uses ncs_scale = 0.5 from attr(sobj_0.5$formula, "standardized.scale")
mf_sobj_0.5 <- nauf_model.frame(sobj_0.5$formula, sobj_0.5$data)
## Not run:
## not recommended
# uses specified ncs_scale = 0.5 and issues a warning since
# attr(sobj$formula, "standardized.scale") = 1
mf_warning <- nauf_model.frame(sobj$formula, sobj$data, ncs_scale = 0.5)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.