From 142e70f68ea7bb08473306ad8b7fe67bd2bd448a Mon Sep 17 00:00:00 2001 From: mhunter Date: Fri, 11 Apr 2014 06:09:41 +0000 Subject: [PATCH] Expectation-Fit revision to multigroup User's Guide pages. git-svn-id: http://openmx.psyc.virginia.edu/svn/trunk@3314 df83fd30-4cca-4c36-ab9d-e8b5583ccbd1 --- docs/source/MultipleGroups_Matrix.rst | 25 +++++++++++-------------- docs/source/MultipleGroups_Path.rst | 35 +++++++++++++++-------------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/docs/source/MultipleGroups_Matrix.rst b/docs/source/MultipleGroups_Matrix.rst index eff98c3..e15814e 100644 --- a/docs/source/MultipleGroups_Matrix.rst +++ b/docs/source/MultipleGroups_Matrix.rst @@ -72,8 +72,7 @@ We first fit a heterogeneity model, allowing differences in both the mean and co bivHetModel <- mxModel("bivHet", mxModel("group1"), mxModel("group2"), - mxAlgebra(group1.objective + group2.objective, name="minus2loglikelihood"), - mxAlgebraObjective("minus2loglikelihood") + mxFitFunctionMultigroup(c("group1.fitfunction", "group2.fitfunction")) ) For each of the groups, we fit a saturated model, using a Cholesky decomposition to generate the expected covariance matrix and a row vector for the expected means. Note that we have specified different labels for all the free elements, in the two ``mxModel`` statements. For more details, see example 1. @@ -109,11 +108,12 @@ For each of the groups, we fit a saturated model, using a Cholesky decomposition xy1, type="raw" ), - mxFIMLObjective( + mxExpectationNormal( covariance="EC1", means="EM1", dimnames=selVars - ) + ), + mxFitFunctionML() ), mxModel("group2", mxMatrix( @@ -142,11 +142,12 @@ For each of the groups, we fit a saturated model, using a Cholesky decomposition xy2, type="raw" ), - mxFIMLObjective( + mxExpectationNormal( covariance="EC2", means="EM2", dimnames=selVars - ) + ), + mxFitFunctionML() ), @@ -172,15 +173,11 @@ We estimate five parameters (two means, two variances, one covariance) per group X Y [1,] "mX2" "mY2" -To evaluate both models together, we use an ``mxAlgebra`` command that adds up the values of the objective functions of the two groups. The objective function to be used here is the ``mxAlgebraObjective`` which uses as its argument the sum of the function values of the two groups, referred to by the name of the previously defined ``mxAlgebra`` object ``h12``. +To evaluate both models together, we use an ``mxFitFunctionMultigroup`` command that adds up the values of the fit functions of the two groups. .. code-block:: r - mxAlgebra( - group1.objective + group2.objective, - name="minus2loglikelihood" - ), - mxAlgebraObjective("minus2loglikelihood") + mxFitFunctionMultigroup(c("group1.fitfunction", "group2.fitfunction")) ) Model Fitting @@ -200,7 +197,7 @@ A variety of output can be printed. We chose here to print the expected means a EM2Het <- mxEval(group2.EM2, bivHetFit) EC1Het <- mxEval(group1.EC1, bivHetFit) EC2Het <- mxEval(group2.EC2, bivHetFit) - LLHet <- mxEval(objective, bivHetFit) + LLHet <- summary(bivHetFit)\$Minus2LogLikelihood Homogeneity Model: a Submodel @@ -251,7 +248,7 @@ We can produce similar output for the submodel, i.e. expected means and covarian EM2Hom <- mxEval(group2.EM2, bivHomFit) EC1Hom <- mxEval(group1.EC1, bivHomFit) EC2Hom <- mxEval(group2.EC2, bivHomFit) - LLHom <- mxEval(objective, bivHomFit) + LLHom <- summary(bivHomFit)\$Minus2LogLikelihood Finally, to evaluate which model fits the data best, we generate a likelihood ratio test as the difference between -2 times the log-likelihood of the homogeneity model and -2 times the log-likelihood of the heterogeneity model. This statistic is asymptotically distributed as a Chi-square, which can be interpreted with the difference in degrees of freedom of the two models. diff --git a/docs/source/MultipleGroups_Path.rst b/docs/source/MultipleGroups_Path.rst index 0d244e6..e4e1327 100644 --- a/docs/source/MultipleGroups_Path.rst +++ b/docs/source/MultipleGroups_Path.rst @@ -71,8 +71,7 @@ We first fit a heterogeneity model, allowing differences in both the mean and co bivHetModel <- mxModel("bivHet", mxModel("group1"), mxModel("group2"), - mxAlgebra(group1.objective + group2.objective, name="h12"), - mxAlgebraObjective("h12") + mxFitFunctionMultigroup(c("group1.fitfunction", "group2.fitfunction")) ) For each of the groups, we fit a saturated model, by specifying paths with free parameters for the variances and the covariance using two-headed arrows to generate the expected covariance matrix. Single-headed arrows from the constant ``one`` to the manifest variables contain the free parameters for the expected means. Note that we have specified different labels for all the free elements, in the two ``mxModel`` statements. The type is RAM by default. @@ -176,15 +175,11 @@ We estimate five parameters (two means, two variances, one covariance) per group X Y [1,] "mX2" "mY2" -To evaluate both models together, we use an ``mxAlgebra`` command that adds up the values of the objective functions of the two groups, and assigns a ``name``. The objective function to be used here is the ``mxAlgebraObjective`` which uses as its argument the sum of the function values of the two groups, referred to by the name of the previously defined ``mxAlgebra`` object ``h12``. +To evaluate both models together, we use an ``mxFitFunctionMultigroup`` command that adds up the values of the fit functions of the two groups. .. code-block:: r - mxAlgebra( - group1.objective + group2.objective, - name="h12" - ), - mxAlgebraObjective("h12") + mxFitFunctionMultigroup(c("group1.fitfunction", "group2.fitfunction")) ) Model Fitting @@ -200,11 +195,11 @@ A variety of output can be printed. We chose here to print the expected means a .. code-block:: r - EM1Het <- bivHetFit\$group1.objective@info\$expMean - EM2Het <- bivHetFit\$group2.objective@info\$expMean - EC1Het <- bivHetFit\$group1.objective@info\$expCov - EC2Het <- bivHetFit\$group2.objective@info\$expCov - LLHet <- mxEval(objective, bivHetFit) + EM1Het <- bivHetFit\$group1.fitfunction\$info\$expMean + EM2Het <- bivHetFit\$group2.fitfunction\$info\$expMean + EC1Het <- bivHetFit\$group1.fitfunction\$info\$expCov + EC2Het <- bivHetFit\$group2.fitfunction\$info\$expCov + LLHet <- summary(bivHetFit)\$Minus2LogLikelihood Homogeneity Model: a Submodel @@ -226,8 +221,8 @@ As the free parameters of the paths are translated into RAM matrices, and matrix .. code-block:: r - bivHomModel\$group2.S@labels <- bivHomModel\$group1.S@labels - bivHomModel\$group2.M@labels <- bivHomModel\$group1.M@labels + bivHomModel\$group2.S\$labels <- bivHomModel\$group1.S\$labels + bivHomModel\$group2.M\$labels <- bivHomModel\$group1.M\$labels The specification for the submodel is reflected in the names of the labels which are now equal for the corresponding elements of the mean and covariance matrices, as below:: @@ -259,11 +254,11 @@ We can produce similar output for the submodel, i.e. expected means and covarian .. code-block:: r bivHomFit <- mxRun(bivHomModel) - EM1Hom <- bivHomFit\$group1.objective@info\$expMean - EM2Hom <- bivHomFit\$group2.objective@info\$expMean - EC1Hom <- bivHomFit\$group1.objective@info\$expCov - EC2Hom <- bivHomFit\$group2.objective@info\$expCov - LLHom <- mxEval(objective, bivHomFit) + EM1Hom <- bivHomFit\$group1.fitfunction\$info\$expMean + EM2Hom <- bivHomFit\$group2.fitfunction\$info\$expMean + EC1Hom <- bivHomFit\$group1.fitfunction\$info\$expCov + EC2Hom <- bivHomFit\$group2.fitfunction\$info\$expCov + LLHom <- summary(bivHomFit)\$Minus2LogLikelihood Finally, to evaluate which model fits the data best, we generate a likelihood ratio test from the difference between -2 times the log-likelihood of the homogeneity model and -2 times the log-likelihood of the heterogeneity model. This statistic is asymptotically distributed as a Chi-square, which can be interpreted with the difference in degrees of freedom of the two models, in this case 5 df. -- 2.1.4