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

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

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

                                        Specify a Structural Equation Model
                                         指定一个结构方程模型

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

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

Create the RAM specification of a structural equation model.
创建RAM规格的结构方程模型。


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


specifyModel(file="", exog.variances=FALSE, endog.variances=TRUE, covs,
        suffix="", quiet=FALSE)

specifyEquations(file="", ...)

cfa(file="", covs=paste(factors, collapse=","), reference.indicators=FALSE,
     raw=FALSE, ...)

multigroupModel(..., groups=names(models), allEqual=FALSE)

classifyVariables(model)

removeRedundantPaths(model, warn=TRUE)
## S3 method for class 'semmod'
combineModels(..., warn=TRUE)
## S3 method for class 'semmod'
update(object, file = "", ...)
## S3 method for class 'semmod'
edit(name, ...)

## S3 method for class 'semmod'
print(x, ...)
## S3 method for class 'semmodList'
print(x, ...)



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

参数:file
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), then the specification is read from the standard input stream, and is terminated by a blank line.
(引用)文件,从中读取的模型规范,包括文件的路径,如果它不是在当前目录中。如果""(默认值),然后该规范从标准输入流中读取,并用一个空行终止。


参数:exog.variances
If TRUE (the default is FALSE), free variance parameters are added for the exogenous variables that lack them.
如果TRUE(默认为FALSE),免费方差参数添加的外生变量,缺乏。


参数:endog.variances
If TRUE (the default), free error-variance parameters are added for the endogenous variables that lack them.
如果TRUE(默认值),误差方差参数中添加的内生变量缺乏。


参数:covs
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 covariances among these factors.
可选:一个字符向量的一个或多个元素,每个元素给一个字符串变量名,以逗号分隔。每一个这样的字符串中的所有变量之间的方差和协方差添加到模型中。对于验证性因素分析模型,通过cfa,covs默认为所有的因素在模型中,从而指定所有这些因素之间的协方差。


参数:suffix
a character string (defaulting to an empty string) to be  appended to each parameter name; this can be convenient for specifying multiple-group models.
字符串(默认为空字符串)将被添加到每个参数的名称,这可以方便的指定多组模型。


参数:reference.indicators
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.
FALSE如果,默认情况下,因素的差异设置为1 cfa如果TRUE,差异的因素是免费的参数估计的数据,并加载,而不是第一个因素为每个因子被设置为1,以识别模型。


参数:raw
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).
如果TRUE(默认为FALSE),路径从(Intercept)每个观测变量添加到模型中,原第二时刻(Intercept)固定1。 sem功能,被称为raw=TRUE,要么提供的数据集(通过data参数)或原始矩矩阵(通过S参数)。


参数:quiet
if FALSE, the default, then the number of input lines is reported.
如果FALSE,默认值,然后输入行数据报道。


参数:x, model, object, name
An object of class semmod or semmodList, as produced by specifyModel or multigroupModel.
类的一个对象semmod或semmodList,所产生的specifyModel或multigroupModel。


参数:warn
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.
对于multigroupModel,一个或多种任选命名的参数每一个都是一个semmod对象产生的,例如,通过specifyModel,specifyEquations,或cfa;如果只这样一个模式,那么它将被用于groups参数定义的所有团体。如果参数具有相同的名称在不同的组,那么他们将受到限制是平等的。对于specifyEquations和cfa,参数(如covsspecifyEquations)的情况下,通过specifyModelcombineModels, sem对象忽略了update和print方法。


参数:groups
a character vector of names for the groups in a multigroup model; taken by default from the names of the ... arguments.
字符向量的多种群模型的组名称;采取默认的...参数的名字。


参数:allEqual
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.
如果FALSE(默认值),然后,如果只有一个模型对象的多种群模型,组中的所有相应的参数是不同的; TRUE如果,所有相应的参数将被限制为等于。


Details

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

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,通过单和双箭头指定一个模型RAM(路径)格式,“specifyEquations,指定一个模型方程的格式,然后将其翻译到RAM格式的功能和cfa,紧凑的规格简单的验证性因素分析模型。

specifyModel:
specifyModel:

Each line of the RAM specification for specifyModel consists of three (unquoted) entries,  separated by commas:
每一行的RAM规范specifyModel由三(非上市)项目,以逗号分隔:




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。值:启动一个自由参数的值或值的一个固定的参数。

Lines may end in a comment following \#.
行最终可能会用\#评论。

specifyEquations:
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
对于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)。

cfa:
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). 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.
对于cfa,每个输入行中包含的变量的名称,以逗号分隔,即相应的因子负荷因素的名称是任选的行开始,后跟一个冒号。如果有必要,变量加载上一个因素可能继续跨两个或多个输入线,在这种情况下,每一个这样的行,但最后必须以逗号结束。变量可以加载在一个以上的因子,只要生成的模型被识别时,当然,但如果变量列表继续到下一行,只有一个输入线(或设置的输入线,可能会出现在每个因子)。如果的说法reference.indicators=FALSE,默认情况下,cfa将解决各因子的方差为1,默认情况下,包括对各因素的协方差(即相关性)。或者,如果reference.indicators=TRUE,则因子方差是免费的参数从数据进行估计,并且所述第一负载每个因子被设置为1,以确定的模型。这两种方法产生的等效模型,适合的数据具有相同的,但可选的参数化。指定的参数covs=NULL暗示的因素交互相关为0。

See sem and the examples for further details on model specification.
见sem的例子型号规格的进一步详情。

Other Functions:
其他功能:

classifyVariables classifies the variables in a model as endogenous or exogenous.
classifyVariables分类模型中的内源性或外源性的变量。

combineModels and removeRedundantPaths take semmod objects as arguments and do what their names imply.
combineModels和removeRedundantPathssemmod对象作为参数,并做他们的名字所暗示的。

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.
fileupdate semmod对象,默认情况下是从标准输入方法,输入参数是一组更新的指令,每行一个。有五种类型的指令。在每一种情况下,指令的指令名称,由一个或多个以逗号分隔的开始。




1. delete: Remove a path from the model. Example: delete, RSES -> FGenAsp
1。删除:从模型中取出的路径。例如:delete, RSES -> FGenAsp




2. add: Add a path to the model. Example (the NA for the start value is optional): add, RSES -> FGenAsp, gam14,  NA
2。添加:添加路径的模型。示例(NA的初始值是可选的):add, RSES -> FGenAsp, gam14,  NA




3. replace: 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"
3。更换:更换所有发生的第一与第二的变量和模型参数的字符串。这个指令可以使用,例如,要改变一个变量或重命名参数。例如:replace, gam, gamma,替换的字符串"gamma"




4. fix: Fix a parameter that was formerly free. Example: fix, RGenAsp  -> REdAsp, 1
4。修复:修复以前是免费的参数。例如:fix, RGenAsp  -> REdAsp, 1




5. free: Free a parameter that was formerly fixed. Example (the NA for the start value is optional):
5。免费:免费的前身是固定的参数。例(NA开始值是可选的):

The edit method for semmod objects opens the model in the R editor.
edit方法打开semmod对象的模型的R编辑器中。


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

specifyModel, specifyEquations, cfa, removeRedundantPaths, combineModels,  update, and edit return an object of class semmod, suitable as input for sem.
specifyModel,specifyEquations,cfa,removeRedundantPaths,combineModels,update和edit返回一个类的对象<X >,适合的输入semmod。

multigroupModel returns an object of class semmodList, also suitable as input for sem.
multigroupModel返回一个对象类semmodList,也适合作为输入为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.
classifyVariables返回一个列表,有两个特征向量:endogenous,包含模型中的内生变量的名称; exogenous,包含外生变量名。


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


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



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

sem
sem


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



# Note: These examples can't be run via example() because the default file[注意:通过实例,这些例子不能运行(),因为默认的文件]
#  argument of specifyModel() requires that the model specification be entered[的specifyModel()的参数需要输入型号规格]
#  at the command prompt. The examples can be copied and run in the R console,[在命令提示符下。这些例子可以被复制和R控制台中运行,]
#  however.[然而。]

    ## Not run: [#不运行:]
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
   
model.dhp
   
# an equivalent specification, allowing specifyModel() to generate[等效的说明书中,允许specifyModel()来生成]
#  variance parameters for endogenous variables (and suppressing[为内生变量的方差参数(和抑制]
#  the unnecessary trailing 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

model.dhp

# 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

model.dhp

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

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

model.dhp

classifyVariables(model.dhp)

# updating the model to impose equality constraints[更新模式,实行平等的限制]
#  and to rename the latent variables and gamma parameters[并更名潜变量和γ参数]

model.dhp.eq <- update(model.dhp)
delete, RSES -> FGenAsp
delete, FSES -> FGenAsp
delete, FIQ  -> FGenAsp
delete, FParAsp -> FGenAs
delete, RGenAsp  -> FGenAsp
add, RSES     -> FGenAsp, gam14,  NA
add, FSES     -> FGenAsp, gam13,  NA
add, FIQ      -> FGenAsp, gam12,  NA
add, FParAsp  -> FGenAsp, gam26,  NA
add, RGenAsp  -> FGenAsp, beta12, NA
replace, gam, gamma
replace, Gen, General

model.dhp.eq

# A three-factor CFA model for the Thurstone mental-tests data, specified three equivalent ways:[一个三因素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

        #  (1a) in CFA format:[(1A)在终审法院格式:]

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)

        #  (1b) in CFA format, using reference indicators:[(1b)在终审法院格式,使用参考指标:]
       
mod.cfa.thur.r <- cfa(reference.indicators=TRUE)
FA: Sentences, Vocabulary, Sent.Completion
FB: First.Letters, 4.Letter.Words, Suffixes
FC: Letter.Series, Pedigrees, Letter.Group

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

        #  (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[多种群CFA模型拟合Holzinger,Swineford的的,]
#   mental-tests data (from the MBESS package)[心理测试数据(从MBESS包)]

library(MBESS)
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)
   
## End(Not run)[#(不执行)]

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


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

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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