Create the RAM specification of a structural equation model.
specifyModel(file="", text, exog.variances=FALSE, endog.variances=TRUE, covs,
suffix="", quiet=FALSE)specifyEquations(file="", text, ...)
cfa(file="", text, covs=paste(factors, collapse=","),
reference.indicators=TRUE, raw=FALSE,
subscript=c("name", "number"), ...)
multigroupModel(..., groups=names(models), allEqual=FALSE)
classifyVariables(model)
removeRedundantPaths(model, warn=TRUE)
# S3 method for semmod
combineModels(..., warn=TRUE)
# S3 method for semmod
update(object, file = "", text, ...)
# S3 method for semmod
edit(name, ...)
# S3 method for semmod
print(x, ...)
# S3 method for semmodList
print(x, ...)
specifyModel
, specifyEquations
, cfa
, removeRedundantPaths
, combineModels
,
update
, and edit
return an object of class semmod
, suitable as input for sem
.
multigroupModel
returns an object of class semmodList
, also suitable as input for sem
.
classifyVariables
returns a list with two character vectors: endogenous
, containing the names of endogenous
variables in the model; and exogenous
, containing the names of exogenous variables.
The (quoted) file from which to read the model specification,
including the path to the file if it is not in the current directory. If
""
(the default) and the text
argument is not supplied,
then the specification is read from the standard
input stream, and is terminated by a blank line.
The model specification given as a character string, as an alternative
to specifying the ]file
argument or reading the model specification from
the input stream --- e.g., when the session is not interactive and there is no
standard input.
If TRUE
(the default is FALSE
), free variance
parameters are added for the exogenous variables that lack them.
If TRUE
(the default), free error-variance parameters
are added for the endogenous variables that lack them.
optional: a character vector of one or more elements, with each element
giving a string of variable names, separated by commas. Variances and covariances
among all variables in each such string are added to the model. For confirmatory
factor analysis models specified via cfa
, covs
defaults to all of
the factors in the model, thus specifying all variances and covariances among these factors.
Warning: covs="x1, x2"
and covs=c("x1", "x2")
are not
equivalent: covs="x1, x2"
specifies the variance of x1
, the variance
of x2
, and their covariance, while covs=c("x1", "x2")
specifies
the variance of x1
and the variance of x2
but not their covariance.
a character string (defaulting to an empty string) to be appended to each parameter name; this can be convenient for specifying multiple-group models.
if FALSE
, the default, variances of factors are
set to 1 by cfa
; if TRUE
, variances of factors are free parameters
to estimate from the data, and instead the first factor loading for each factor is set
to 1 to identify the model.
if TRUE
(the default is FALSE
), a path from Intercept
to each
observed variable is added to the model, and the raw second moment for Intercept
is
fixed to 1
. The sem
function should then be called with raw=TRUE
, and either
supplied with a data set (via the data
argument) or a raw-moment matrix (via the S
argument).
The “subscripts” to be appended to lam
to name factor-loading parameters,
either "name"
(the default) to use the names of observed variables, or "number"
to
number the parameters serially within each factor. Using "number"
produces shorter parameter
names.
if FALSE
, the default, then the number of input lines is reported and
a message is printed suggesting that specifyEquations
or cfa
be used.
An object of class semmod
or semmodList
, as produced by
specifyModel
or multigroupModel
.
print a warning if redundant paths are detected.
For multigroupModel
, one or more optionally named arguments each of
which is a semmod
object produced, e.g., by specifyModel
, specifyEquations
,
or cfa
; if only one such model is given, then it will be used for all groups defined by
the groups
argument. If parameters have the same name in different groups, then they will
be constrained to be equal.
For specifyEquations
and cfa
, arguments (such as covs
,
in the case of specifyEquations
) to be
passed to specifyModel
; for combineModels
, sem
objects;
ignored in the update
and print
methods.
a character vector of names for the groups in a multigroup model; taken by default from
the names of the ...
arguments.
if FALSE
(the default), then if only one model object is given for
a multigroup model, all corresponding parameters in the groups will be distinct; if TRUE
,
all corresponding parameters will be constrained to be equal.
John Fox jfox@mcmaster.ca and Jarrett Byrnes
The principal functions for model specification are specifyModel
,
to specify a model in RAM (path) format via single- and double-headed arrows;
specifyEquations
, to specify a model in equation format, which is then
translated by the function into RAM format; and cfa
, for compact
specification of simple confirmatory factor analysis models.
specifyModel
:
Each line of the RAM specification for specifyModel
consists of three (unquoted) entries,
separated by commas:
This is a simple formula, of the form
A -> B
or, equivalently, B <- A
for a regression
coefficient (i.e., a single-headed or directional arrow);
A <-> A
for a variance or A <-> B
for a covariance
(i.e., a double-headed or bidirectional arrow). Here, A
and
B
are variable names in the model. If a name does not correspond
to an observed variable, then it is assumed to be a latent variable.
Spaces can appear freely in an arrow specification, and
there can be any number of hyphens in the arrows, including zero: Thus,
e.g., A->B
, A --> B
, and A>B
are all legitimate
and equivalent.
The name of the regression coefficient, variance,
or covariance specified by the arrow. Assigning the same name to two or
more arrows results in an equality constraint. Specifying the parameter name
as NA
produces a fixed parameter.
start value for a free parameter or value of a fixed parameter.
If given as NA
(or simply omitted), sem
will compute the start value.
Lines may end in a comment following #
.
specifyEquations
:
For specifyEquations
, each input line is either a regression equation or the specification
of a variance or covariance. Regression equations are of the form
y = par1*x1 + par2*x2 + ... + park*xk
where y
and the x
s are variables in the model (either observed or latent),
and the par
s are parameters. If a parameter is given as a numeric value (e.g.,
1
) then it is treated as fixed. Note that no “error” variable is included in
the equation; “error variances” are specified via either the covs
argument,
via V(y) = par
(see immediately below), or are added automatically to the model
when, as by default, endog.variances=TRUE
. A regression equation may be split over more
than one input by breaking at a +
, so that +
is either the last non-blank character
on a line or the first non-blank character on the subsequent line.
Variances are specified in the form V(var) = par
and covariances in the form
C(var1, var2) = par
, where the var
s are variables (observed or unobserved) in
the model. The symbols V
and C
may be in either lower- or upper-case. If par
is a numeric value (e.g., 1
) then it is treated as fixed. In conformity with the RAM model,
a variance or covariance for an endogenous variable in the model is an “error” variance or
covariance.
Warning: If the covs
argument to specifyEquations
is used to specify
variances and covariances, please be aware that
covs="x1, x2"
and covs=c("x1", "x2")
are not
equivalent: covs="x1, x2"
specifies the variance of x1
, the variance
of x2
, and their covariance, while covs=c("x1", "x2")
specifies
the variance of x1
and the variance of x2
but not their covariance.
To set a start value for a free parameter, enclose the numeric start value in parentheses after the
parameter name, as parameter(value)
.
cfa
:
For cfa
, each input line includes the names of the variables, separated by commas,
that load on the corresponding factor; the name of the factor is given optionally at the beginning
of the line, followed by a colon. If necessary, the variables that load on a factor may be continued
across two or more input lines; in this case, each such line but the last must end in a comma. A
variable may load on more than one factor (as long as the resulting model is identified, of course),
but each factor may appear in only one input line (or set of input lines, if the variable list
is continued onto the next line).
Equality constraints for factor loadings can be set by using equal-signs (=
) rather than commas
to separate observed variable names. For example, fac1: x1=x2=x3, x4=x5
sets the loadings
for x1
, x2
, and x3
equal to each other, and the loadings for x4
and x5
equal to each other.
Equality constraints among error variances can similarly be specified by using var:
or variance:
at the beginning of a line (actually, any character string beginning with var
will do, and thus
no factor name may begin with the characters var
). For example, var: x1=x2=x3, x4=x5
sets the
error variances for x1
, x2
, and x3
equal to each other, and the
error variances for x4
and x5
equal to each other. There may be several lines beginning with
var:
.
If the argument reference.indicators=FALSE
, the default,
cfa
will fix the variance of each factor to 1, and by
default include covariances (i.e., correlations) among all pairs of factors. Alternatively,
if reference.indicators=TRUE
, then the factor variances are free parameters to be estimated
from the data, and the first loading for each factor is set to 1 to identify the model. These two
approaches produce equivalent models, with the same fit to the data, but alternative parametrizations.
Specifying the argument covs=NULL
implicitly fixes the factor intercorrelations to 0.
See sem
and the examples for further details on model specification.
Other Functions:
classifyVariables
classifies the variables in a model as endogenous or exogenous.
combineModels
and removeRedundantPaths
take semmod
objects as arguments and do what their names imply.
The file
input argument to the update
method for semmod
objects, which by default comes from
standard input, is a set of update directives, one per line. There are five kinds of directives. In each case
the directive begins with the directive name, followed by one or more fields separated by commas.
Remove a path from the model. Example: delete, RSES -> FGenAsp
Add a path to the model. Example (the NA
for the start value is optional): add, RSES -> FGenAsp, gam14, NA
Replace every occurrence of the first string with the second in the variables and
parameters of the model. This directive may be used, for example, to change one variable to
another or to rename a parameter. Example: replace, gam, gamma
, substitutes the string "gamma"
for "gam"
wherever the latter appears, presumably in parameter names.
Fix a parameter that was formerly free. Example: fix, RGenAsp -> REdAsp, 1
Free a parameter that was formerly fixed. Example (the NA
for the start value is optional):
free, RGenAsp -> ROccAsp, lam11, NA
The edit
method for semmod
objects opens the model in the R editor.
sem