找回密码
 注册
查看: 787|回复: 0

R语言 sem包 sem()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-30 00:48:59 | 显示全部楼层 |阅读模式
sem(sem)
sem()所属R语言包:sem

                                        General Structural Equation Models
                                         一般结构方程模型

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

sem fits general structural equation models (with both observed and unobserved variables). Observed variables are also called indicators or  manifest variables; unobserved variables are also called factors or latent variables. Normally, the generic function (sem) is called directly with a semmod first argument produced by specifyModel, specifyEquations, or cfa, invoking the sem.semmod method, which in turn sets up a call to the sem.default method; thus, the user may wish to specify arguments accepted by the semmod and default methods. Similarly, for a multigroup model, sem would normally be called with a semmodList object produced by multigroupModel as its first argument, and would then generate a call to the code msemmod method.
sem适合一般的结构方程模型(与观察到的和不可观测的变量)。也被称为观测变量指标或明显的变量,也被称为不可观测的变量因素或潜在的变量。通常情况下,通用的功能(sem)一个semmod产生的第一个参数specifyModel,specifyEquations或cfa直接调用,调用<X >方法,这反过来又设置了呼叫sem.semmod方法,因此,用户可能希望指定由sem.default和semmod方法接受的参数。同样,对于多种群模型,default通常被称为一个semsemmodList作为第一个参数的对象,然后生成一个调用的代码multigroupModel的方法。


用法----------Usage----------


## S3 method for class 'semmod'
sem(model, S, N, data, raw=FALSE, obs.variables=rownames(S),
                fixed.x=NULL, formula= ~ ., robust=!missing(data), debug=FALSE, ...)
   
## Default S3 method:[默认方法]
sem(model, S, N, data=NULL, raw=FALSE, param.names,
                var.names, fixed.x=NULL, robust=!is.null(data), semmod=NULL, debug=FALSE,
                analytic.gradient=TRUE, warn=FALSE, maxiter=1000,
                par.size=c("ones", "startvalues"), start.tol=1E-6,
                optimizer=optimizerSem, objective=objectiveML, ...)
               
## S3 method for class 'semmodList'
sem(model, S, N, data, raw=FALSE, fixed.x=NULL,
                robust=!missing(data), formula, group="Group", debug=FALSE, ...)
               
## S3 method for class 'msemmod'
sem(model, S, N, group="Group", groups=names(model), raw=FALSE, fixed.x,
                param.names, var.names, debug=FALSE, analytic.gradient=TRUE, warn=FALSE,
                maxiter=5000, par.size = c("ones", "startvalues"), start.tol = 1e-06,
                startvalues=c("initial.fit", "startvalues"), initial.maxiter=1000,
                optimizer = optimizerMsem, objective = msemObjectiveML, ...)
   
startvalues(S, ram, debug=FALSE, tol=1E-6)

## S3 method for class 'sem'
coef(object, standardized=FALSE, ...)
## S3 method for class 'msem'
coef(object, ...)
## S3 method for class 'sem'
vcov(object, robust=FALSE,
        analytic=inherits(object, "objectiveML") &amp;&amp; object$t &lt;= 500, ...)
## S3 method for class 'msem'
vcov(object, robust=FALSE, analytic=inherits(object, "msemObjectiveML") &amp;&amp; object$t &lt;= 500, ...)
## S3 method for class 'sem'
df.residual(object, ...)
## S3 method for class 'msem'
df.residual(object, ...)



参数----------Arguments----------

参数:model
RAM specification, which is a simple encoding of the path diagram for the model. The model may be given either in symbolic  form (as a semmod object, as returned by the specifyModel,   specifyEquations, or cfa function, or as a character matrix), invoking sem.semmod, which calls sem.default  after setting up the model, or (less conveniently) in numeric form, invoking sem.default directly, which is not recommended (see Details below). The model argument may also be a multigroup-model specification, as produced by multigroupModel.
RAM说明书中,这是一个简单的编码模型的路径图。该模型可以以符号的形式(如一个semmod对象,返回的specifyModel,specifyEquations或cfa功能,或作为一个字符矩阵),调用sem.semmod,这就要求sem.default后以数字形式建立模型,或者不太方便,调用sem.default直接,这是不推荐(详见下文)。 modelmultigroupModel参数,也可以是多组型号规格,生产。


参数:S
covariance matrix among observed variables; may be input as a symmetric matrix, or as a lower- or upper-triangular matrix. S may also be a raw (i.e., &ldquo;uncorrected&rdquo;) moment matrix &mdash; that is, a sum-of-squares-and-products matrix divided by N. This form of input is useful for fitting models with intercepts, in which case the moment matrix should include the mean square and cross-products for a unit variable all of whose entries are 1; of course, the raw mean square for the unit variable is 1. Raw-moment matrices may be computed by rawMoments. If the ram argument is given in symbolic form, then the observed-variable covariance or raw-moment matrix may contain variables that do not appear in the model, in which case a warning is printed. S may also be a list of covariance or moment matrices for each group in a multigroup model. As an alternative to specifying S the user may supply a data frame containing the data for the model (see the argument data).
观察到的变量之间的协方差矩阵;可被输入作为一个对称矩阵,或作为一个低或上三角矩阵。 S也可能是原始矩矩阵(即“裸眼”), - 这是一个总和的平方和产品矩阵除以N。这种形式的输入是用于拟合模型与拦截,在这种情况下,矩矩阵应包括的单元变量的均方和交叉产品的所有的输入为1;当然,原料均方为单元可变1。原始矩矩阵,可以计算由rawMoments。如果ram参数,以符号的形式,然后观察变量的协方差或原始时刻矩阵可以包含变量没有出现在模型中,在这种情况下,一个警告被打印。 S也可能是多种群模型的协方差或力矩矩阵中的每个组的列表。作为一种替代方法,以指定S包含模型的数据,用户可以提供一个数据框(见的论点data)。


参数:N
number of observations on which the covariance matrix is based; for a multigroup model, a vector of group Ns.
观测的协方差矩阵是基于多种群模型,一个向量组N的。


参数:data
As a generally preferable alternative to specifying S and  N, the user may supply a data frame containing the data to which the model is to be fit. In a multigroup model, the data argument may be a list of data frames or a single data frame; in the later event, the factor given as the group argument is used to split the data into groups.
作为一个一般优选的替代指定S和N中,用户可以提供一个数据框包含的数据,该模型是定为适宜。在多组模型,data参数可以是一个列表的数据框或单个数据框,在以后的事件,group参数是用来将数据分割成组的因素。


参数:raw
TRUE if S is a raw moment matrix or if a raw moment matrix &mdash;  as opposed to a covariance matrix &mdash; is to be computed from data; the default is FALSE.
TRUE如果S是一个原始的时刻矩阵或原始矩矩阵 - 而不是协方差矩阵 - 要计算从data;默认的是FALSE 。


参数:obs.variables
names of observed variables, by default taken from the row names of the covariance or moment matrix S, which may be given directly or generated according to the data and formula arguments.
观察到的变量的名称,在默认情况下的协方差矩阵或力矩S,其可以直接给出的行名取自或生成data和formula论据。


参数:fixed.x
names (if the ram matrix is given in symbolic form) or indices  (if it is in numeric form) of fixed exogenous variables. Specifying these obviates the necessity of having to fix the variances and covariances among these  variables (and produces correct degrees of freedom for the model chisquare).
名称(如果ram矩阵符号形式)或指数(如果它是在数字形式)固定的外生变量。指定这些省却的必要性,要解决这些变量之间的方差和协方差(并产生正确的自由度模型的卡方)。


参数:formula
a one-sided formula, to be applied to data to generate the variables for which covariances or raw moments are computed. The default formula is ~., i.e., all of the variables in the data, including an implied intercept; if a covariance matrix is to be computed, the constant is suppressed. In a multigroup model, alternatively a list one one-sided formulas as be given, to be applied individually to the groups.
一个片面的式中,要施加到data生成的变量的协方差或原料的时刻计算。默认公式是~.,即所有的变量中的数据,包括一个隐含的拦截,如果要计算协方差矩阵,不断的被抑制。在多种群模型的列表,或者一个片面的公式得到,单独应用的团体。


参数:robust
In sem: if TRUE, then quantities are calculated that can be used to compute robust estimates of coefficient standard errors and robust tests when the model is fit by multinormal maximum likelihood; the default is TRUE when the data argument is TRUE, and this option is only available when the data argument is given. In vcov: if TRUE, return a robust coefficient covariance matrix (if object contains the requisite information).
在sem如果TRUE,然后量计算,可用于计算健壮系数的标准误差和健壮的测试模型时,适合multinormal最大似然估计,默认为TRUE中data参数是TRUE,与此选项仅当data给定参数。在vcov如果TRUE,返回一个强大的系数,协方差矩阵(object如果包含必要的信息)。


参数:semmod
a semmod object containing the description of the model; optional, and normally supplied not directly by the user but via the semmod method for sem.
semmod对象,它包含的描述模型;可选的,通常不是由用户直接提供,但通过semmod方法sem。


参数:debug
if TRUE, some information is printed to help you debug the symbolic model specification; for example, if a variable name is misspelled, sem will assume that the variable is a (new) latent variable. Information about the optimization will also be printed, but details will vary with the optimizer employed.  The default is FALSE.
如果TRUE,打印一些信息来帮助你调试的符号模型规范,例如,如果一个变量的名字拼错了,sem假设变量是一个(新的)潜在的变量。优化信息也将被打印出来,但具体细节将随采用的优化。默认的FALSE。


参数:...
arguments to be passed down, including from sem.default to the  optimizer.
参数传递,包括从sem.default的优化。


参数:param.names
names of the t free parameters, given in their numerical order; default names are Param1, ..., Paramt. Note: Should not be specified when the model is given in symbolic form.
t自由参数,在他们的数字顺序,默认的名称的名称是Param1,,Param吨。注:如果不指定模型时,以符号的形式。


参数:var.names
names of the m entries of the v vector (typically the observed and latent variables &mdash; see below), given in their numerical order; default names are Var1, ..., Varm. Note: Should not be specified when the model is given in symbolic form.
mv向量(通常观察到的和潜在的变量 - 见下面)项,在他们的数字顺序,默认的名称的名称是Var1,..., Var米。注:如果不指定模型时,以符号的形式。


参数:analytic.gradient
if TRUE (the default), then analytic first derivatives are used in the maximization of the likelihood if the optimzer employed will accept them;  otherwise numeric derivatives are used, again if the optimizer will compute them.
如果TRUE(默认值),然后分析的一阶导数的可能性最大化,如果optimzer将接受他们,否则数字的衍生工具,如果优化器将计算。


参数:warn
if TRUE, warnings produced by the optimization function will be printed. This should generally not be necessary, since sem prints its own warning, and saves information about convergence. The default is FALSE.
如果TRUE,产生的警告的优化功能将被打印。这一般不应该是必要的,因为sem打印自己的警告,并保存信息衔接。默认的FALSE。


参数:maxiter
the maximum number of iterations for the optimization of the objective function, to be passed to the optimizer.
的最大数目,要传递给优化的目标函数优化的迭代。


参数:par.size
the anticipated size of the free parameters; if "ones", a vector of ones is used; if "startvalues", taken from the start values. You can try changing this argument if you encounter convergence problems. The default is "startvalues" if the largest input variance is at least 100 times the smallest, and "ones" otherwise. Whether this argument is actually used depends upon the optimizer employed.
预期规模的自由参数,如果"ones",一个向量的使用; "startvalues",从一开始就值。您可以尝试更改这个参数,如果你遇到收敛问题。默认值是"startvalues",如果输入方差最大的是至少100倍最小,"ones"否则。无论这种说法实际上是取决于采用的优化。


参数:start.tol, tol
if the magnitude of an automatic start value is less than start.tol, then it is set to start.tol; defaults to 1E-6.
如果自动启动值的大小是小于start.tol,然后它被设置为start.tol;默认至1E-6。


参数:optimizer
a function to be used to minimize the objective function; the default for single-group models is  optimizerSem. Alternatives are nlm, which employs the standard R optimizer nlm; optimizerOptim, which employs optim; and optimizerNlminb, which uses nlminb &mdash; or the user can supply an optimizer. For multigroup model, the default is optimizerMsem, and msemOptimizerNlm, based on nlm, is provided as an alternative.
一个函数被用来最小化目标函数;单组模型的默认值是optimizerSem。替代品nlm,它采用了标准的R优化nlm,“optimizerOptim,它采用optim和optimizerNlminb,使用nlminb - 用户可以提供一个优化。多组模型,默认的是optimizerMsem和msemOptimizerNlm,根据nlm,作为一种替代。


参数:objective
An objective function to be minimized, sometimes called a &ldquo;fit&rdquo; function  in the SEM literature. The default for single-group models is objectiveML, which produces maximum-likelihood estimates assuming multinormality. An alternative is  objectiveGLS, which produced generalized least squares estimates &mdash; or the user can supply an objective function to be minimzed. For multigroup models, the default is available is msemObjectiveML for ML estimates and an alternative is msemObjectiveGLS for GLS estiamtes.
以最小化的目标函数,有时也被称为“合适”功能在SEM文献。默认情况下,单组模型是objectiveML,产生最大似然估计,假设multinormality。另一种方法是objectiveGLS,广义最小二乘估计 - 或者用户也可以提供一个客观的功能,minimzed。多组模型,默认的是msemObjectiveML ML估计和替代的是msemObjectiveGLSGLS estiamtes的。


参数:ram
numeric RAM matrix.
数字RAM矩阵。


参数:object
an object of class "sem" or "msem", returned by sem.
类的一个对象"sem"或"msem",返回sem。


参数:standardized
if TRUE, return standardized coefficients.
如果TRUE,返回标准化系数。


参数:analytic
return an analytic (as opposed to numeric) estimate of the coefficient covariance matrix; at present only available for the objectiveML objective function. The default is FALSE for this objective function if there are no more than 100 parameters and FALSE otherwise.
返回一个分析系数的协方差矩阵的估计值(而不是数字),目前仅可用于objectiveML目标函数。默认值是FALSE这一目标的功能,如果有不超过100个参数,FALSE否则。


参数:group
for a multigroup model, the quoted name of the group variable; if the data argument is given, snd is a single data frame, then this should be a factor in the data set or a variable coercible to a factor, to be used to split the data into groups; otherwise, the name is arbitrary.
多种群模型,组变量的引用名称;如果data参数,SND是一个单一的数据框,那么这应该是一个因素的数据集或变量强制转换的一个因素,可用于将数据分割成团,否则,这个名字是任意的。


参数:groups
a character vector giving the names of the groups; will be ignored if group is a factor in data.
group是一个因素,在data字符向量给出的组名,将被忽略。


参数:startvalues
if "initial.fit" (the default), start values  for a multi-group model are computed by first fitting the intra-group models separately by group; if "startvalues", then start values are computed as for a single-group model. In some cases, the intra-group models may not be identified even if the multi-group model is, and then startvalues="initial.fit" should be used.
如果"initial.fit"(默认值),启动多组模型的数值计算第一配件的集团内部模型分别由组;如果"startvalues",然后开始计算值作为一个单模型组。在某些情况下,可能无法被识别的帧内组模型,即使多组模型,然后startvalues="initial.fit"应使用。


参数:initial.maxiter
if startvalues="initial.fit" for a multi-group model, then initial.maxiter gives the maximum number of iterations for each initial intra-group fit.
如果startvalues="initial.fit"多组模型,然后initial.maxiter给出了最大的迭代次数为每个初始的集团内公司间的契合。


Details

详细信息----------Details----------

The model is set up using either RAM (&ldquo;reticular action model&rdquo; &ndash; don't ask!)  notation &ndash; a simple format for specifying general structural equation models by coding the &ldquo;arrows&rdquo; in the path diagram for the model (see, e.g., McArdle and McDonald, 1984) &ndash; typically using the specifyModel function; in equation format using the specifyEquations function; or, for a simple confirmatory factor analysis model, via the cfa function. In any case, the model is represented internally in RAM format.
可以使用RAM(的“网状行动模式” - 不要问!) - 一个简单的格式符号指定编码的路径图中的“箭头”的模型的一般结构方程模型,该模型成立(见,例如,麦卡德尔和麦当劳,1984年) - 通常使用specifyModel函数方程格式specifyEquations函数,或者一个简单的验证性因素分析模型,通过cfa 函数。在任何情况下,该模型是在RAM格式内部表示。

The variables in the v vector in the model (typically, the observed and unobserved variables, but not error variables) are numbered from 1 to m.   the RAM matrix contains one row for each (free or constrained) parameter of the model, and may be specified either in symbolic format or in numeric format.
编号从1到vm向量在模型中(通常情况下,所观察到的和不可观测的变量,但不是错误的变量)中的变量。 RAM矩阵包含一个行的每个(免费或约束)的模型的参数,并且可以被指定符号格式或以数字格式。

A symbolic ram matrix consists of three columns, as follows:
一个象征性的ram矩阵由三列,如下所示:




1. Arrow specification: 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
1。箭头规格:这是一个简单的公式,形式"A -> B"或等价地,"B <- A"的回归系数(即单头或方向箭头);"A <-> A"方差或"A <-> B"的协方差(即,一个双头或双向箭头)。在这里,A和B是在模型中的变量名。如果一个名字不对应于所观察到的变量,然后它被假定为是的潜变量。空间可以自由箭头规范的出现,也可以是任意数量的箭头的连字符,包括零,因此,例如,"A->B","A --> B"和"A>B"这些都是合法的




2. Parameter name: 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
2。参数名:箭头所指定的回归系数,方差,协方差的名称。分配相同的名字以两个或更多的箭头在等式约束的结果。指定的参数名称




3. Value: start value for a free parameter or value of a fixed parameter.
3。值:启动一个自由参数的值或值的一个固定的参数。

It is simplest to construct the RAM matrix with the specifyModel, specifyEquations, or cfa function, all of which return an object of class semmod, and also incorporate some model-specification convenience shortcuts. This process is illustrated in the examples below.
这是最简单的specifyModel,specifyEquations或cfa功能,所有这一切都返回一个对象,的类semmod,也包括一些模型构建RAM矩阵规格方便快捷。在下面的实施例中说明了这个过程。

A numeric ram matrix consists of five columns, as follows:
一个数字ram矩阵由五列,如下所示:




1. Number of arrow heads: 1 (directed arrow) or 2 (covariance).
1。箭头头数:1(指示箭头)或2(协方差)。




2. Arrow to: index of the variable at the head of a directional arrow, or at one end of a bidirectional arrow. Observed variables should be assigned the numbers 1 to n, where n is the number of rows/columns in the covariance matrix S, with the indices corresponding to the variables' positions in S.
2。箭头以:在定向箭头的头部的变量的指数,或在一个双向箭头的一端。观测变量应分配的数字1 n,n是多少的行/列的协方差矩阵S,对应的指标变量的位置在S。




3. Arrow from: the index of the variable at the tail of
3。箭从指数的变量的尾部




4. Parameter number: free parameters are numbered from 1 to t, but do not necessarily appear in consecutive order. Fixed parameters are given the number 0. Equality contraints are specified by assigning two or more
4。参数编号:自由参数,编号从1到t,但不一定出现在连续的顺序。固定参数中给出的数量为0。平等约束上所指定的分配两个或更多个




5. Value: start value for a free parameter, or value of a fixed parameter. If given as NA, the program will compute a start value, by a slight modification of the method described by McDonald and Hartmann (1992). Note: In some circumstances, some start values are selected randomly; this might produce small differences in
5。值:起始值为一个自由参数,或一个固定的参数值。如果NA,该计划将计算了初始值,麦当劳和哈特曼(1992)描述的方法稍作修改。注:在某些情况下,一些开始随机选择,这可能会产生小的差异。

The numeric ram matrix is normally generated automatically, not specified directly by the user.
数字ram矩阵通常是自动生成的,而不是由用户直接指定。

For specifyEquations, each input line is either a regression equation or the specification of a variance or covariance. Regression equations are of the form
对于specifyEquations,每个输入行的回归方程或规范的方差或协方差。回归方程的形式

y = par1*x1 + par2*x2 + ... + park*xk
y = par1*x1 + par2*x2 + ... + park*xk

where y and the xs are variables in the model (either observed or latent), and the pars are parameters. If a parameter is given as a numeric value (e.g., 1) then it is treated as fixed. Note that no &ldquo;error&rdquo; variable is included in the equation; &ldquo;error variances&rdquo; 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.
其中y和xs是在模型中的变量(任何观察或潜伏的),和pars是参数。如果参数是给出一个数值(例如,1),那么它被视为固定。请注意,没有“错误”的公式中的变量包括“误差方差”是通过指定的covs参数,通过V(y) = par(见下面),或自动添加到模型的时,默认情况下,“endog.variances=TRUE。

Variances are specified in the form V(var) = par and covariances in the form C(var1, var2) = par, where the vars 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 &ldquo;error&rdquo; variance or covariance.
差异中指定的形式V(var) = par和协方差的形式C(var1, var2) = par,其中varS模型中的变量(观察或不可观察的)。的符号V和C可能会在无论是低或大写。如果par是一个数值(例如,1),那么它被视为固定。在符合RAM模型,模型中的一个内生变量的方差协方差矩阵是一个“错误”的方差和协方差。

To set a start value for a free parameter, enclose the numeric start value in parentheses after the parameter name, as parameter(value).
要设置一个自由参数的初始值,在参数名称后的括号括起来的数字开始值,作为parameter(value)。

sem fits the model by calling the optimizer specified in the optimizer argument to minimize the objective function specified in the objective argument. If the optimization fails to converge, a warning message is printed.
sem适合的模型通过调用optimizer参数中指定的objective参数中指定的最小化目标函数的优化。如果优化不收敛,警告信息被打印出来。

The RAM formulation of the general structural equation model is given by the basic equation
RAM制定的一般结构方程模型的基本方程

where v and u are vectors of random variables (observed or unobserved), and the parameter matrix A contains regression coefficients, symbolized by single-headed arrows in a path diagram. Another parameter matrix,
v和u是随机变量(观察或不可观察的),和参数矩阵向量A的路径图中的单箭头,象征着回归系数。另一个参数矩阵,

contains covariances among the elements of u (assuming that the elements of u have zero means). Usually v contains endogenous and exogenous observed and unobserved variables, but not error variables (see the examples below).
的元素包含u(假设的元素的协方差之间,u零装置)。通常是v包含内源性和外源性观察到的和不可观测的变量,但不是错误的变量(见下面的例子)。

The startvalues function may be called directly, but is usually called by sem.default.
startvalues功能可能被直接调用,但通常被称为sem.default。


值----------Value----------

sem returns an object of class c(objective, "sem"), where objective is the name of the objective function that was optimized (e.g., "objectiveML"), with the following elements:
sem返回一个类的对象c(客观, "sem"),目标是进行了优化的目标函数名称(例如,"objectiveML"),包含下列元素:


参数:var.names
vector of variable names.
向量的变量名。


参数:ram
RAM matrix, including any rows generated for covariances among fixed exogenous variables; column 5 includes computed start values.
RAM矩阵,包括固定的外生变量之间的协方差产生的任何行5列,包括计算开始值。


参数:S
observed covariance matrix.
观察协方差矩阵。


参数:J
RAM selection matrix, J, which picks out observed variables.
RAM选择矩阵,J,观测变量。


参数:n.fix
number of fixed exogenous variables.
一些固定的外生变量。


参数:n
number of observed variables.
观测变量的数量。


参数:N
number of observations.
若干意见。


参数:m
number of variables (observed plus unobserved).
数变量(实测值加上未观察到)。


参数:t
number of free parameters.
自由参数的数量。


参数:raw
TRUE if the model is fit to a raw moment matrix, FALSE otherwise.
TRUE,如果该模型是适合原始的时刻矩阵,FALSE的否则。


参数:data
the observed-variable data matrix, or NULL if data are not supplied.
所观察到的变量数据矩阵或NULL如果不提供数据。


参数:semmod
the semmod specification object for the model, if one was supplied; otherwise NULL.
semmod规范对象的模型,如果一个人提供的,否则NULL。


参数:optimizer
the optimizer function.
优化功能。


参数:objective
the objective function.
目标函数。


参数:coeff
estimates of free parameters.
自由参数的估计。


参数:vcov
estimated asymptotic covariance matrix of parameter estimates, based on a numeric Hessian, if supplied by the optimizer; otherwise NULL.
估计参数估计的渐近协方差矩阵,基于一个数字黑森州,如果所提供的优化程序,否则NULL。


参数:par.posn
indices of free parameters.
自由参数指标。


参数:convergence
TRUE or FALSE, depending upon whether the optimization apparently converged.
TRUE或FALSE,取决于是否优化显然融合。


参数:iterations
number of iterations performed.
执行的迭代次数。


参数:criterion
value of the objective function at the minimum.
在最小的目标函数的值。


参数:C
model-reproduced covariance matrix.
模型再生的协方差矩阵。


参数:A
RAM A matrix.
RAM A矩阵。


参数:P
RAM P matrix.
RAM P矩阵。


参数:adj.obj
robust adjusted value of the objective function; NULL if robust is FALSE.
强大的调整值的目标函数,“NULL如果robust是FALSE。


参数:robust.vcov
robust estimated coefficient covariance matrix; NULL if robust is FALSE.
强大的估计系数的协方差矩阵; NULL如果robust是FALSE。

For multigroup models, sem returns an object of class c("msemObjectiveML", "msem").
对于多组模型,sem返回一个对象类c("msemObjectiveML", "msem")。


警告----------Warning----------

A common error is to fail to specify variance or covariance terms in the model, which are denoted  by double-headed arrows, <->.
一个常见的错误是没有指定方差和协方差的模式,这双箭头表示,<->。

In general, every observed or latent variable in the model should be associated  with a variance or error variance.  This may be a free parameter to estimate or a fixed constant (as in the case of a latent exogenous  variable for which you wish to fix the variance, e.g., to 1). Again in general, there will be an error variance associated with each  endogenous variable in the model (i.e., each variable to which at least one single-headed arrow points &mdash; including observed indicators of latent variables),  and a variance associated with each exogenous variable (i.e., each variable that appears only at the tail of single-headed arrows, never at the head).
在一般情况下,应与变异或误差方差模型中的每一个观察到的或潜在的变量。这可能是一个自由参数估计或固定不变的情况下,一个潜在的外生变量,你想修复的差异,例如,1。再次在一般情况下,将有一个相关联的误差方差与每个内源性在模型中的变量(即,每个变量,其中至少一个单箭头点 - 包括潜变量的观察指标),和外源与每个相关联的方差变量(即,每个变量只出现在单箭头的尾巴,从来没有在头)。

To my knowledge, the only apparent exception to this rule is for observed variables that  are declared to be fixed exogenous variables. In this case, the program generates the necessary (fixed-constant) variances and covariances automatically.
据我所知,唯一明显的例外是被宣布为是固定的外生变量的观测变量。在这种情况下,该程序自动生成必要的(固定的常数)方差和协方差。

If there are missing variances, a warning message will be printed, and estimation will almost surely  fail in some manner. Missing variances might well indicate that there are missing covariances too, but it is not possible  to deduce this in a mechanical manner. The specifyModel funciton will by default supply error-variance parameters if these are missing.
如果有遗漏的差异,一个警告消息将被打印出来,估计几乎肯定会以某种方式失败。丢失的方差可能指示有丢失的协方差太,但它是不可能在一个机械的方式推断此。 specifyModel功能可按默认情况下提供误差方差参数,如果这些人失踪。


(作者)----------Author(s)----------


John Fox <a href="mailto:jfox@mcmaster.ca">jfox@mcmaster.ca</a> and Jarrett Byrnes



参考文献----------References----------

Structural equation modeling with the sem package in R. Structural Equation Modeling  13:465&ndash;486.
Structural Equations With Latent Variables. Wiley.
Testing Structural Equation Models, Sage.
Latent growth curves within developmental structural equation models. Child Development 58, 110&ndash;133.
Some algebraic properties of the reticular action model. British Journal of Mathematical and Statistical Psychology 37, 234&ndash;251.
A procedure for obtaining initial values of parameters in the RAM model. Multivariate Behavioral Research 27, 57&ndash;76.
Bayesian model selection in structural equation models. In Bollen, K. A. and Long, J. S. (eds.) Testing Structural Equation Models, Sage.
Bayesian model selection in social research (with discussion). Sociological Methodology 25, 111&ndash;196.
Scaled and adjusted restricted tests in multi-sample analysis of moment structures.  pp. 233&ndash;247 in Heijmans, R.D.H., Pollock, D.S.G. &amp; Satorra, A. (eds.) Innovations in Multivariate Statistical Analysis. A Festschrift for Heinz Neudecker , Kluwer.

参见----------See Also----------

rawMoments, startvalues,  objectiveML, objectiveGLS,   optimizerNlm, optimizerOptim, optimizerNlminb, nlm, optim, nlminb, specifyModel, specifyEquations, cfa
rawMoments,startvalues,objectiveML,objectiveGLS,optimizerNlm,optimizerOptim,optimizerNlminb,nlm,<所述>,optim,nlminb,specifyModel,specifyEquations


实例----------Examples----------



# Note: The first set of examples can't be run via example() because the default file[注:第一组的例子可以不通过实例运行(),因为默认的文件]
#  argument of specifyModel() and readMoments() requires that the model [的specifyModel()和readMoments的()的参数要求,该模型]
#  specification and covariances, correlations, or raw moments be entered[输入规格和协方差,相关性,或原始的时刻]
#  at the command prompt. The examples can be copied and run in the R console,[在命令提示符下。这些例子可以被复制和R控制台中运行,]
#  however. See ?specifyModel and ?readMoments for further information.[然而。看到了吗?specifyModel?readMoments的进一步信息。]
#  These examples are repeated below using file input to specifyModel() and[这些实施例下面,使用文件输入到specifyModel()和重复]
#  readMoments(). The second version of the examples may be executed through example().[readMoments()。实施例的第二个版本,可以执行通过例如()。]

    ## Not run: [#不运行:]

# ------------- Duncan, Haller and Portes peer-influences model ----------------------[-------------邓肯,Haller和波特斯同侪的影响模型----------------------]
# A nonrecursive SEM with unobserved endogenous variables and fixed exogenous variables[未观测到的内生变量和外生变量固定的非递归SEM]

R.DHP <- readMoments(diag=FALSE, names=c("ROccAsp", "REdAsp", "FOccAsp",
                "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp"))
    .6247     
    .3269  .3669      
    .4216  .3275  .6404
    .2137  .2742  .1124  .0839
    .4105  .4043  .2903  .2598  .1839
    .3240  .4047  .3054  .2786  .0489  .2220
    .2930  .2407  .4105  .3607  .0186  .1861  .2707
    .2995  .2863  .5191  .5007  .0782  .3355  .2302  .2950
    .0760  .0702  .2784  .1988  .1147  .1021  .0931 -.0438  .2087
            
# Fit the model using a symbolic ram specification[使用符号的RAM规范的拟合模型]

model.dhp <- specifyModel()
    RParAsp  -> RGenAsp, gam11,  NA
    RIQ      -> RGenAsp, gam12,  NA
    RSES     -> RGenAsp, gam13,  NA
    FSES     -> RGenAsp, gam14,  NA
    RSES     -> FGenAsp, gam23,  NA
    FSES     -> FGenAsp, gam24,  NA
    FIQ      -> FGenAsp, gam25,  NA
    FParAsp  -> FGenAsp, gam26,  NA
    FGenAsp  -> RGenAsp, beta12, NA
    RGenAsp  -> FGenAsp, beta21, NA
    RGenAsp  -> ROccAsp,  NA,     1
    RGenAsp  -> REdAsp,  lam21,  NA
    FGenAsp  -> FOccAsp,  NA,     1
    FGenAsp  -> FEdAsp,  lam42,  NA
    RGenAsp <-> RGenAsp, ps11,   NA
    FGenAsp <-> FGenAsp, ps22,   NA
    RGenAsp <-> FGenAsp, ps12,   NA
    ROccAsp <-> ROccAsp, theta1, NA
    REdAsp  <-> REdAsp,  theta2, NA
    FOccAsp <-> FOccAsp, theta3, NA
    FEdAsp  <-> FEdAsp,  theta4, NA
   
# an equivalent specification, allowing specifyModel() to generate[等效的说明书中,允许specifyModel()来生成]
#  variance parameters for endogenous variables (and suppressing the[为内生变量的方差参数(和抑制]
#  unnecessary NAs):[不必要NAS):]

model.dhp <- specifyModel()
RParAsp  -> RGenAsp, gam11
RIQ      -> RGenAsp, gam12
RSES     -> RGenAsp, gam13
FSES     -> RGenAsp, gam14
RSES     -> FGenAsp, gam23
FSES     -> FGenAsp, gam24
FIQ      -> FGenAsp, gam25
FParAsp  -> FGenAsp, gam26
FGenAsp  -> RGenAsp, beta12
RGenAsp  -> FGenAsp, beta21
RGenAsp  -> ROccAsp,  NA,     1
RGenAsp  -> REdAsp,  lam21
FGenAsp  -> FOccAsp,  NA,     1
FGenAsp  -> FEdAsp,  lam42
RGenAsp <-> FGenAsp, ps12

# Another equivalent specification, telling specifyModel to add paths for [另一种同等规格,告诉specifyModel添加路径]
#   variances and covariance of RGenAsp and FGenAsp:[方差和方差的RGenAsp和FGenAsp:]

model.dhp <- specifyModel(covs="RGenAsp, FGenAsp")
RParAsp  -> RGenAsp, gam11
RIQ      -> RGenAsp, gam12
RSES     -> RGenAsp, gam13
FSES     -> RGenAsp, gam14
RSES     -> FGenAsp, gam23
FSES     -> FGenAsp, gam24
FIQ      -> FGenAsp, gam25
FParAsp  -> FGenAsp, gam26
FGenAsp  -> RGenAsp, beta12
RGenAsp  -> FGenAsp, beta21
RGenAsp  -> ROccAsp,  NA,     1
RGenAsp  -> REdAsp,  lam21
FGenAsp  -> FOccAsp,  NA,     1
FGenAsp  -> FEdAsp,  lam42

# Yet another equivalent specification using specifyEquations():[然而,其他同等规格使用specifyEquations():]

model.dhp.1 <- specifyEquations(covs="RGenAsp, FGenAsp")
RGenAsp = gam11*RParAsp + gam12*RIQ + gam13*RSES + gam14*FSES + beta12*FGenAsp
FGenAsp = gam23*RSES + gam24*FSES + gam25*FIQ + gam26*FParAsp + beta21*RGenAsp
ROccAsp = 1*RGenAsp
REdAsp = lam21(1)*RGenAsp  # to illustrate setting start values[说明设置启动值]
FOccAsp = 1*FGenAsp
FEdAsp = lam42(1)*FGenAsp

sem.dhp.1 <- sem(model.dhp, R.DHP, 329,
    fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
summary(sem.dhp.1)

# Fit the model using a numerical ram specification (not recommended!)[适合的模型,用数值RAM规范(不推荐!)]

ram.dhp <- matrix(c(
#               heads   to      from    param  start[头从参数开始]
                1,       1,     11,      0,     1,
                1,       2,     11,      1,     NA, # lam21[lam21]
                1,       3,     12,      0,     1,
                1,       4,     12,      2,     NA, # lam42[lam42]
                1,      11,      5,      3,     NA, # gam11[gam11]
                1,      11,      6,      4,     NA, # gam12[gam12]
                1,      11,      7,      5,     NA, # gam13[gam13]
                1,      11,      8,      6,     NA, # gam14[gam14]
                1,      12,      7,      7,     NA, # gam23[gam23]
                1,      12,      8,      8,     NA, # gam24[gam24]
                1,      12,      9,      9,     NA, # gam25[gam25]
                1,      12,     10,     10,     NA, # gam26[gam26]
                1,      11,     12,     11,     NA, # beta12[beta12]
                1,      12,     11,     12,     NA, # beta21[beta21]
                2,       1,      1,     13,     NA, # theta1[THETA1]
                2,       2,      2,     14,     NA, # theta2[theta2]
                2,       3,      3,     15,     NA, # theta3[theta3]
                2,       4,      4,     16,     NA, # theta4[theta4]
                2,      11,     11,     17,     NA, # psi11[PSI11]
                2,      12,     12,     18,     NA, # psi22[psi22]
                2,      11,     12,     19,     NA  # psi12[psi12]
                ), ncol=5, byrow=TRUE)

params.dhp <- c('lam21', 'lam42', 'gam11', 'gam12', 'gam13', 'gam14',
                 'gam23',  'gam24',  'gam25',  'gam26',
                 'beta12', 'beta21', 'theta1', 'theta2', 'theta3', 'theta4',
                 'psi11', 'psi22', 'psi12')
                 
vars.dhp <- c('ROccAsp', 'REdAsp', 'FOccAsp', 'FEdAsp', 'RParAsp', 'RIQ',
                'RSES', 'FSES', 'FIQ', 'FParAsp', 'RGenAsp', 'FGenAsp')
               
sem.dhp.2 <- sem(ram.dhp, R.DHP, 329, param.names=params.dhp, var.names=vars.dhp,
        fixed.x=5:10)
summary(sem.dhp.2)


# -------------------- Wheaton et al. alienation data ----------------------[-------------------- Wheaton等人。异化的数据----------------------]
   

S.wh <- readMoments(names=c('Anomia67','Powerless67','Anomia71',
                                    'Powerless71','Education','SEI'))
   11.834                                    
    6.947    9.364                           
    6.819    5.091   12.532                    
    4.783    5.028    7.495    9.986            
   -3.839   -3.889   -3.841   -3.625   9.610     
  -21.899  -18.831  -21.748  -18.775  35.522  450.288

# This is the model in the SAS manual for PROC CALIS: A Recursive SEM with[这是该型号的SAS PROC CALIS手册:一个递归SEM]
# latent endogenous and exogenous variables.[潜在的内生和外生变量。]
# Curiously, both factor loadings for two of the latent variables are fixed.[奇怪的是,两个潜变量的两个因素负荷量是固定的。]

model.wh.1 <- specifyModel()
    Alienation67   ->  Anomia67,      NA,     1
    Alienation67   ->  Powerless67,   NA,     0.833
    Alienation71   ->  Anomia71,      NA,     1
    Alienation71   ->  Powerless71,   NA,     0.833
    SES            ->  Education,     NA,     1     
    SES            ->  SEI,           lamb,   NA
    SES            ->  Alienation67,  gam1,   NA
    Alienation67   ->  Alienation71,  beta,   NA
    SES            ->  Alienation71,  gam2,   NA
    Anomia67       <-> Anomia67,      the1,   NA
    Anomia71       <-> Anomia71,      the1,   NA
    Powerless67    <-> Powerless67,   the2,   NA
    Powerless71    <-> Powerless71,   the2,   NA
    Education      <-> Education,     the3,   NA
    SEI            <-> SEI,           the4,   NA
    Anomia67       <-> Anomia71,      the5,   NA
    Powerless67    <-> Powerless71,   the5,   NA
    Alienation67   <-> Alienation67,  psi1,   NA
    Alienation71   <-> Alienation71,  psi2,   NA
    SES            <-> SES,           phi,    NA
                           
sem.wh.1 <- sem(model.wh.1, S.wh, 932)
summary(sem.wh.1)

# The same model in equation format:[同样的模型方程格式:]

model.wh.1 <- specifyEquations()
Anomia67 = 1*Alienation67
Powerless67 = 0.833*Alienation67
Anomia71 = 1*Alienation71
Powerless71 = 0.833*Alienation71
Education = 1*SES
SEI = lamb*SES
Alienation67 = gam1*SES
Alienation71 = gam2*SES + beta*Alienation67
V(Anomia67) = the1
V(Anomia71) = the1
V(Powerless67) = the2
V(Powerless71) = the2
V(SES) = phi
C(Anomia67, Anomia71) = the5
C(Powerless67, Powerless71) = the5

# The same model, but treating one loading for each latent variable as free[同样的模式,但将每个潜变量作为一个装载]
# (and equal to each other).[(及彼此相等)。]

model.wh.2 <- specifyModel()
    Alienation67   ->  Anomia67,      NA,        1
    Alienation67   ->  Powerless67,   lamby,    NA
    Alienation71   ->  Anomia71,      NA,        1
    Alienation71   ->  Powerless71,   lamby,    NA
    SES            ->  Education,     NA,        1     
    SES            ->  SEI,           lambx,    NA
    SES            ->  Alienation67,  gam1,     NA
    Alienation67   ->  Alienation71,  beta,     NA
    SES            ->  Alienation71,  gam2,     NA
    Anomia67       <-> Anomia67,      the1,     NA
    Anomia71       <-> Anomia71,      the1,     NA
    Powerless67    <-> Powerless67,   the2,     NA
    Powerless71    <-> Powerless71,   the2,     NA
    Education      <-> Education,     the3,     NA
    SEI            <-> SEI,           the4,     NA
    Anomia67       <-> Anomia71,      the5,     NA
    Powerless67    <-> Powerless71,   the5,     NA
    Alienation67   <-> Alienation67,  psi1,     NA
    Alienation71   <-> Alienation71,  psi2,     NA
    SES            <-> SES,           phi,      NA


sem.wh.2 <- sem(model.wh.2, S.wh, 932)
summary(sem.wh.2)

# And again, in equation format:[并再次,在等式格式:]

model.wh <- specifyEquations()
Anomia67 = 1*Alienation67
Powerless67 = lamby*Alienation67
Anomia71 = 1*Alienation71
Powerless71 = lamby*Alienation71
Education = 1*SES
SEI = lambx*SES
Alienation67 = gam1*SES
Alienation71 = gam2*SES + beta*Alienation67
V(Anomia67) = the1
V(Anomia71) = the1
V(Powerless67) = the2
V(Powerless71) = the2
V(SES) = phi
C(Anomia67, Anomia71) = the5
C(Powerless67, Powerless71) = the5


# Compare the two models by a likelihood-ratio test:[比较两个模型的似然比检验:]

anova(sem.wh.1, sem.wh.2)


# ----------------------- Thurstone data ---------------------------------------[-----------------------瑟斯顿数据------------------------- --------------]
#  Second-order confirmatory factor analysis, from the SAS manual for PROC CALIS[二阶验证性因素分析,从SAS PROC CALIS手册]

R.thur <- readMoments(diag=FALSE, names=c('Sentences','Vocabulary',
        'Sent.Completion','First.Letters','4.Letter.Words','Suffixes',
        'Letter.Series','Pedigrees', 'Letter.Group'))
    .828                                             
    .776   .779                                       
    .439   .493    .46                                 
    .432   .464    .425   .674                           
    .447   .489    .443   .59    .541                    
    .447   .432    .401   .381    .402   .288              
    .541   .537    .534   .35    .367   .32   .555        
    .38   .358    .359   .424    .446   .325   .598   .452  
            
model.thur <- specifyModel()
    F1 -> Sentences,                      lam11
    F1 -> Vocabulary,                     lam21
    F1 -> Sent.Completion,                lam31
    F2 -> First.Letters,                  lam42
    F2 -> 4.Letter.Words,                 lam52
    F2 -> Suffixes,                       lam62
    F3 -> Letter.Series,                  lam73
    F3 -> Pedigrees,                      lam83
    F3 -> Letter.Group,                   lam93
    F4 -> F1,                             gam1
    F4 -> F2,                             gam2
    F4 -> F3,                             gam3
    F1 <-> F1,                            NA,     1
    F2 <-> F2,                            NA,     1
    F3 <-> F3,                            NA,     1
    F4 <-> F4,                            NA,     1

sem.thur <- sem(model.thur, R.thur, 213)
summary(sem.thur)

# The model in equation format:[方程格式中的模型:]

model.thur <- specifyEquations()
Sentences = lam11*F1
Vocabulary = lam21*F1
Sent.Completion = lam31*F1
First.Letters = lam42*F2
4.Letter.Words = lam52*F2
Suffixes = lam62*F2
Letter.Series = lam73*F3
Pedigrees = lam83*F3
Letter.Group = lam93*F3
F1 = gam1*F4
F2 = gam2*F4
F3 = gam3*F4
V(F1) = 1
V(F2) = 1
V(F3) = 1
V(F4) = 1


#------------------------- Kerchoff/Kenney path analysis ---------------------[,------------------------- Kerchoff /肯尼路径分析-------------------- - ]
# An observed-variable recursive SEM from the LISREL manual[一个可观察的变量递归扫描电镜从LISREL手册]

R.kerch <- readMoments(diag=FALSE, names=c('Intelligence','Siblings',
                        'FatherEd','FatherOcc','Grades','EducExp','OccupAsp'))
    -.100                                
     .277  -.152                          
     .250  -.108  .611                     
     .572  -.105  .294   .248               
     .489  -.213  .446   .410   .597         
     .335  -.153  .303   .331   .478   .651   
   
model.kerch <- specifyModel()
    Intelligence -> Grades,       gam51
    Siblings -> Grades,           gam52
    FatherEd -> Grades,           gam53
    FatherOcc -> Grades,          gam54
    Intelligence -> EducExp,      gam61
    Siblings -> EducExp,          gam62
    FatherEd -> EducExp,          gam63
    FatherOcc -> EducExp,         gam64
    Grades -> EducExp,            beta65
    Intelligence -> OccupAsp,     gam71
    Siblings -> OccupAsp,         gam72
    FatherEd -> OccupAsp,         gam73
    FatherOcc -> OccupAsp,        gam74
    Grades -> OccupAsp,           beta75
    EducExp -> OccupAsp,          beta76
                       
sem.kerch <- sem(model.kerch, R.kerch, 737, fixed.x=c('Intelligence','Siblings',
    'FatherEd','FatherOcc'))
summary(sem.kerch)

# The model in equation format:[方程格式中的模型:]

model.kerch <- specifyEquations()
Grades = gam51*Intelligence + gam52*Siblings + gam53*FatherEd + gam54*FatherOcc
EducExp = gam61*Intelligence + gam62*Siblings + gam63*FatherEd + gam64*FatherOcc + beta65*Grades
OccupAsp = gam71*Intelligence + gam72*Siblings + gam73*FatherEd + gam74*FatherOcc + beta75*Grades + beta76*EducExp


#------------------- McArdle/Epstein latent-growth-curve model -----------------[-------------------,麦卡德尔/爱泼斯坦潜在增长曲线模型-----------------]
# This model, from McArdle and Epstein (1987, p.118), illustrates the use of a [麦卡德尔和Epstein(1987年,第118页),说明了这种模式,使用]
# raw moment matrix to fit a model with an intercept. (The example was suggested[原矩矩阵拟合模型与拦截。 (例如有人建议]
# by Mike Stoolmiller.)[的麦克Stoolmiller。)]

M.McArdle <- readMoments(names=c('WISC1', 'WISC2', 'WISC3', 'WISC4', 'UNIT'))
    365.661                                      
    503.175     719.905                           
    675.656     958.479    1303.392               
    890.680    1265.846    1712.475    2278.257     
     18.034      25.819      35.255      46.593     1.000

mod.McArdle <- specifyModel()
    C -> WISC1, NA, 6.07
    C -> WISC2, B2, NA
    C -> WISC3, B3, NA
    C -> WISC4, B4, NA
    UNIT -> C, Mc, NA
    C <-> C, Vc, NA,
    WISC1 <-> WISC1, Vd, NA
    WISC2 <-> WISC2, Vd, NA
    WISC3 <-> WISC3, Vd, NA
    WISC4 <-> WISC4, Vd, NA

sem.McArdle <- sem(mod.McArdle, M.McArdle, 204, fixed.x="UNIT", raw=TRUE)
summary(sem.McArdle)

# The model in equation format:[方程格式中的模型:]

mod.McArdle <- specifyEquations()
WISC1 = 6.07*C
WISC2 = B2*C
WISC3 = B3*C
WISC4 = b4*C
C = Mc*UNIT
v(C) = Vc
v(WISC1) = Vd
v(WISC2) = Vd
v(WISC3) = Vd
v(WISC4) = Vd

   
#------------ Bollen industrialization and democracy example -----------------[------------的博伦产业和民主例如-----------------]
# This model, from Bollen (1989, Ch. 8), illustrates the use in sem() of a[从博伦(1989年,8章),此模型中,示出了使用扫描电镜()的一个]
# case-by-variable data (see ?Bollen) set rather than a covariance or moment matrix[的情况下,变量的数据(见博伦),而不是设置的协方差矩矩阵]

model.bollen <- specifyModel()
        Demo60 -> y1, NA, 1
        Demo60 -> y2, lam2,
        Demo60 -> y3, lam3,
        Demo60 -> y4, lam4,
        Demo65 -> y5, NA, 1
        Demo65 -> y6, lam2,
        Demo65 -> y7, lam3,
        Demo65 -> y8, lam4,
        Indust -> x1, NA, 1
        Indust -> x2, lam6,
        Indust -> x3, lam7,
        y1 <-> y5, theta15
        y2 <-> y4, theta24
        y2 <-> y6, theta26
        y3 <-> y7, theta37
        y4 <-> y8, theta48
        y6 <-> y8, theta68
        Indust -> Demo60, gamma11,
        Indust -> Demo65, gamma21,
        Demo60 -> Demo65, beta21,
        Indust <-> Indust, phi
       
sem.bollen <- sem(model.bollen, data=Bollen)
summary(sem.bollen)
summary(sem.bollen, robust=TRUE) # robust SEs and tests[强大的社会企业和测试]
summary(sem.bollen, analytic.se=FALSE) # uses numeric rather than analytic Hessian[使用数字而不是分析黑森州]

sem.bollen.gls &lt;- sem(model.bollen, data=Bollen, objective=objectiveGLS) # GLS rather than ML estimator[的GLS,而不是ML估计量]
summary(sem.bollen.gls)

# The model in equation format:[方程格式中的模型:]

model.bollen <- specifyEquations()
y1 = 1*Demo60
y2 = lam2*Demo60
y3 = lam3*Demo60
y4 = lam4*Demo60
y5 = 1*Demo65
y6 = lam2*Demo65
y7 = lam3*Demo65
y8 = lam4*Demo65
x1 = 1*Indust
x2 = lam6*Indust
x3 = lam7*Indust
c(y1, y5) = theta15
c(y2, y4) = theta24
c(y2, y6) = theta26
c(y3, y7) = theta37
c(y4, y8) = theta48
c(y6, y8) = theta68
Demo60 = gamma11*Indust
Demo65 = gamma21*Indust + beta21*Demo60
v(Indust) = phi


# -------------- A simple CFA model for the Thurstone mental tests data --------------[--------------一个简单的CFA模型瑟斯顿心理测试数据--------------]

R.thur <- readMoments(diag=FALSE, names=c('Sentences','Vocabulary',
                                          'Sent.Completion','First.Letters','4.Letter.Words','Suffixes',
                                          'Letter.Series','Pedigrees', 'Letter.Group'))
.828                                             
.776   .779                                       
.439   .493    .46                                 
.432   .464    .425   .674                           
.447   .489    .443   .59    .541                    
.447   .432    .401   .381    .402   .288              
.541   .537    .534   .35    .367   .32   .555        
.38   .358    .359   .424    .446   .325   .598   .452

        #  (1) in CFA format:[(1)在CFA格式:]

mod.cfa.thur.c <- cfa()
FA: Sentences, Vocabulary, Sent.Completion
FB: First.Letters, 4.Letter.Words, Suffixes
FC: Letter.Series, Pedigrees, Letter.Group

cfa.thur.c <- sem(mod.cfa.thur.c, R.thur, 213)
summary(cfa.thur.c)

        #  (2) in equation format:[(2)在方程格式:]

mod.cfa.thur.e <- specifyEquations(covs="F1, F2, F3")
Sentences = lam11*F1
Vocabulary = lam21*F1
Sent.Completion = lam31*F1
First.Letters = lam42*F2
4.Letter.Words = lam52*F2
Suffixes = lam62*F2
Letter.Series = lam73*F3
Pedigrees = lam83*F3
Letter.Group = lam93*F3
V(F1) = 1
V(F2) = 1
V(F3) = 1

cfa.thur.e <- sem(mod.cfa.thur.e, R.thur, 213)
summary(cfa.thur.e)

        #  (3) in path format:[(3)在路径格式:]

mod.cfa.thur.p <- specifyModel(covs="F1, F2, F3")
F1 -> Sentences,                      lam11
F1 -> Vocabulary,                     lam21
F1 -> Sent.Completion,                lam31
F2 -> First.Letters,                  lam41
F2 -> 4.Letter.Words,                 lam52
F2 -> Suffixes,                       lam62
F3 -> Letter.Series,                  lam73
F3 -> Pedigrees,                      lam83
F3 -> Letter.Group,                   lam93
F1 <-> F1,                            NA,     1
F2 <-> F2,                            NA,     1
F3 <-> F3,                            NA,     1

cfa.thur.p <- sem(mod.cfa.thur.p, R.thur, 213)
summary(cfa.thur.p)


# -------  a multigroup CFA model fit to the Holzinger-Swineford mental-tests data  ---------[-------多种群CFA模型拟合的Holzinger Swineford心理测试数据---------]

library(MBESS) # for data[的数据]
data(HS.data)

mod.hs <- cfa()
spatial: visual, cubes, paper, flags
verbal: general, paragrap, sentence, wordc, wordm
memory: wordr, numberr, figurer, object, numberf, figurew
math: deduct, numeric, problemr, series, arithmet

mod.mg <- multigroupModel(mod.hs, groups=c("Female", "Male"))

sem.mg <- sem(mod.mg, data=HS.data, group="Gender",
              formula = ~ visual + cubes + paper + flags +
              general + paragrap + sentence + wordc + wordm +
              wordr + numberr + figurer + object + numberf + figurew +
              deduct + numeric + problemr + series + arithmet
              )
summary(sem.mg)

        # with cross-group equality constraints:[跨组等式约束:]
       
mod.mg.eq <- multigroupModel(mod.hs, groups=c("Female", "Male"), allEqual=TRUE)

sem.mg.eq <- sem(mod.mg.eq, data=HS.data, group="Gender",
              formula = ~ visual + cubes + paper + flags +
                general + paragrap + sentence + wordc + wordm +
                wordr + numberr + figurer + object + numberf + figurew +
                deduct + numeric + problemr + series + arithmet
              )
summary(sem.mg.eq)

anova(sem.mg, sem.mg.eq) # test equality constraints[测试等式约束]
       
## End(Not run)[#(不执行)]

## ===============================================================================[#================================================= ==============================]
       
# The following examples use file input and may be executed via example():[下面的例子使用文件输入,并通过实例()可以执行:]

etc &lt;- file.path(.path.package(package="sem")[1], "etc") # path to data and model files[数据和模型文件的路径]

# ------------- Duncan, Haller and Portes peer-influences model ----------------------[-------------邓肯,Haller和波特斯同侪的影响模型----------------------]
# A nonrecursive SEM with unobserved endogenous variables and fixed exogenous variables[未观测到的内生变量和外生变量固定的非递归SEM]

(R.DHP <- readMoments(file=file.path(etc, "R-DHP.txt"),
                                diag=FALSE, names=c("ROccAsp", "REdAsp", "FOccAsp",
                "FEdAsp", "RParAsp", "RIQ", "RSES", "FSES", "FIQ", "FParAsp")))
(model.dhp <- specifyModel(file=file.path(etc, "model-DHP.txt")))
sem.dhp.1 <- sem(model.dhp, R.DHP, 329,
    fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
summary(sem.dhp.1)


# -------------------- Wheaton et al. alienation data ----------------------[-------------------- Wheaton等人。异化的数据----------------------]

(S.wh <- readMoments(file=file.path(etc, "S-Wheaton.txt"),
                                        names=c('Anomia67','Powerless67','Anomia71',
                            'Powerless71','Education','SEI')))

# This is the model in the SAS manual for PROC CALIS: A Recursive SEM with[这是该型号的SAS PROC CALIS手册:一个递归SEM]
# latent endogenous and exogenous variables.[潜在的内生和外生变量。]
# Curiously, both factor loadings for two of the latent variables are fixed.[奇怪的是,两个潜变量的两个因素负荷量是固定的。]

(model.wh.1 <- specifyModel(file=file.path(etc, "model-Wheaton-1.txt")))                    
sem.wh.1 <- sem(model.wh.1, S.wh, 932)
summary(sem.wh.1)

# The same model, but treating one loading for each latent variable as free[同样的模式,但将每个潜变量作为一个装载]
# (and equal to each other).[(及彼此相等)。]

(model.wh.2 <- specifyModel(file=file.path(etc, "model-Wheaton-2.txt")))
sem.wh.2 <- sem(model.wh.2, S.wh, 932)
summary(sem.wh.2)

# Compare the two models by a likelihood-ratio test:[比较两个模型的似然比检验:]

anova(sem.wh.1, sem.wh.2)


# ----------------------- Thurstone data ---------------------------------------[-----------------------瑟斯顿数据------------------------- --------------]

#  Second-order confirmatory factor analysis, from the SAS manual for PROC CALIS[二阶验证性因素分析,从SAS PROC CALIS手册]

(R.thur <- readMoments(file=file.path(etc, "R-Thurstone.txt"),
                diag=FALSE, names=c('Sentences','Vocabulary',
        'Sent.Completion','First.Letters','4.Letter.Words','Suffixes',
        'Letter.Series','Pedigrees', 'Letter.Group')))
(model.thur <- specifyModel(file=file.path(etc, "model-Thurstone.txt")))
sem.thur <- sem(model.thur, R.thur, 213)
summary(sem.thur)


#------------------------- Kerchoff/Kenney path analysis ---------------------[,------------------------- Kerchoff /肯尼路径分析-------------------- - ]

# An observed-variable recursive SEM from the LISREL manual[一个可观察的变量递归扫描电镜从LISREL手册]

(R.kerch <- readMoments(file=file.path(etc, "R-Kerchoff.txt"),
                                           diag=FALSE, names=c('Intelligence','Siblings',
                        'FatherEd','FatherOcc','Grades','EducExp','OccupAsp')))
(model.kerch <- specifyModel(file=file.path(etc, "model-Kerchoff.txt")))
sem.kerch <- sem(model.kerch, R.kerch, 737, fixed.x=c('Intelligence','Siblings',
    'FatherEd','FatherOcc'))
summary(sem.kerch)


#------------------- McArdle/Epstein latent-growth-curve model -----------------[-------------------,麦卡德尔/爱泼斯坦潜在增长曲线模型-----------------]

# This model, from McArdle and Epstein (1987, p.118), illustrates the use of a [麦卡德尔和Epstein(1987年,第118页),说明了这种模式,使用]
# raw moment matrix to fit a model with an intercept. (The example was suggested[原矩矩阵拟合模型与拦截。 (例如有人建议]
# by Mike Stoolmiller.)[的麦克Stoolmiller。)]

(M.McArdle <- readMoments(file=file.path(etc, "M-McArdle.txt"),
                                                 names=c('WISC1', 'WISC2', 'WISC3', 'WISC4', 'UNIT')))
(mod.McArdle <- specifyModel(file=file.path(etc, "model-McArdle.txt")))
sem.McArdle <- sem(mod.McArdle, M.McArdle, 204, fixed.x="UNIT", raw=TRUE)
summary(sem.McArdle)


#------------ Bollen industrialization and democracy example -----------------[------------的博伦产业和民主例如-----------------]

# This model, from Bollen (1989, Ch. 8), illustrates the use in sem() of a[从博伦(1989年,8章),此模型中,示出了使用扫描电镜()的一个]
# case-by-variable data set (see ?Bollen) rather than a covariance or moment matrix[逐变量的数据集(看到了吗?博伦),而不是协方差或者矩矩阵]

(model.bollen <- specifyModel(file=file.path(etc, "model-Bollen.txt")))
sem.bollen <- sem(model.bollen, data=Bollen)
summary(sem.bollen)
summary(sem.bollen, robust=TRUE) # robust SEs and tests[强大的社会企业和测试]
summary(sem.bollen, analytic.se=FALSE) # uses numeric rather than analytic Hessian[使用数字而不是分析黑森州]

sem.bollen.gls &lt;- sem(model.bollen, data=Bollen, objective=objectiveGLS) # GLS rather than ML estimator[的GLS,而不是ML估计量]
summary(sem.bollen.gls)

#------------ Holzinger and Swineford muiltigroup CFA example ----------------[------------ Holzinger Swineford muiltigroup终审法院的例子----------------]

if (require(MBESS)){ # for data[的数据]
        data(HS.data)
       
        mod.hs <- cfa(file=file.path(etc, "model-HS.txt"))
       
        mod.mg <- multigroupModel(mod.hs, groups=c("Female", "Male"))
       
        sem.mg <- sem(mod.mg, data=HS.data, group="Gender",
                      formula = ~ visual + cubes + paper + flags +
                      general + paragrap + sentence + wordc + wordm +
                      wordr + numberr + figurer + object + numberf + figurew +
                      deduct + numeric + problemr + series + arithmet
                      )
        summary(sem.mg)
       
                # with cross-group equality constraints:[跨组等式约束:]
               
        mod.mg.eq <- multigroupModel(mod.hs, groups=c("Female", "Male"), allEqual=TRUE)
       
        sem.mg.eq <- sem(mod.mg.eq, data=HS.data, group="Gender",
                      formula = ~ visual + cubes + paper + flags +
                        general + paragrap + sentence + wordc + wordm +
                        wordr + numberr + figurer + object + numberf + figurew +
                        deduct + numeric + problemr + series + arithmet
                      )
        summary(sem.mg.eq)
       
        anova(sem.mg, sem.mg.eq) # test equality constraints[测试等式约束]
        }

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-5-19 04:37 , Processed in 0.047490 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表