estabrook intro to mplus

81
Mplus Basics Latent Variable Non-SEM Monte Carlo Mplus Tutorial for New and Advanced Users AS F! Ryne Estabrook Department of Psychology University of Virginia Design and Data Analysis February 19, 2009 Estabrook University of Virginia Mplus

Upload: clinpsy

Post on 28-Nov-2014

330 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mplus Tutorial for New and Advanced UsersAS F!

Ryne Estabrook

Department of PsychologyUniversity of Virginia

Design and Data AnalysisFebruary 19, 2009

Estabrook University of Virginia

Mplus

Page 2: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

MplusYou misspelled “Mx"

I Why should we talk about Mplus?I If you’re not familiar, it’s a very flexible program for structural

models and a variety of other GLM techniques.I If you are familiar, it has a lot of capabilities that many

people aren’t familiar with.I If you’re a developer for an alternative program, then

understanding popular SEM programming can help shapenew techniques and show what people use and expect.

I No one should use only one program. They all havestrengths and weaknesses, and knowing a few can help youas a user choose the correct one for the problem at hand.

I Today’s talk:I Should be flexible, so we can skip around or not finish

certain sections.I Includes lots of code, so you can take it and use it as a

primer if you like.

Estabrook University of Virginia

Mplus

Page 3: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

MplusTopic of the Day

I Mplus is a program for structural equation modelingutilizing code-based path-centric specification.

I It consists of a base package and “add-ons" for mixtureand multilevel modeling.

I It uses a Windows GUI and a DOS backend running either32 or 64 bit processing.

I 64-bit Mplus is not subject to the Windows memory limit, sothere’s no restriction on model size.

I It can also be called from DOS, and run with batch files.I It takes input files with the extension .inp and returns .out

files, although additional output options are available.I You can get more information, the manual and the

message boards at www.statmodel.com.

Estabrook University of Virginia

Mplus

Page 4: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

MplusPros

I The path-centric specification is relatively intuitive andeasy to teach.

I Being code based, extensions to larger models are easierto build than graphical path-centric specification (Ctrl+C).

I It has some decidedly non-traditional features, andappears committed to constant development.

I User support is good (Bengt & Linda Muthén personallyrespond to most, if not all, message board threads).

Estabrook University of Virginia

Mplus

Page 5: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

MplusCons

I Cost.I Matrix specification not supported (to my knowledge).I Black box.I Code can get unwieldy at times.I No data management beyond Monte Carlo capabilities.I Does rely on defaults.I This is why you learn multiple programs.

Estabrook University of Virginia

Mplus

Page 6: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Basics of MplusI Mplus commands are written in scripts with sections

known as commands.I These commands include:

I TITLE:I DATA:I VARIABLE:I ANALYSIS:I MODEL:I OUTPUT:

I Other commands that we’ll discuss, time permitting:I DEFINE:I SAVEDATA:I PLOT:I MONTECARLO:

I The comment character is !, which I’ll try to use extensively.

Estabrook University of Virginia

Mplus

Page 7: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The TITLE: Command

I This makes titles.

TITLE: This is the title of my project;

I Mplus has in the past (and may currently) impose a widthlimit of 80 characters on input files.

Estabrook University of Virginia

Mplus

Page 8: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The DATA: Command

DATA: FILE=mydata.dat;TYPE=INDIVIDUAL; !DEFAULT!TYPE=COVARIANCE;

I The general usage of Mplus uses tab or space delimitedindividual data, with a 500 variable limit.

I It can also accept covariance or correlation matrices, fixedformat data, monte carlo and imputation components, aswell as multiple data set specification.

I Data should be in the same folder as the input file.

Estabrook University of Virginia

Mplus

Page 9: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The VARIABLE: Command

VARIABLE:NAMES = ID x1-x3 y1-y3 z1-z3;USEVARIABLES = x1-x3 y1-y3;

I The required statements are NAMES, though USEVAR mayas well be.

I Variables specified in the USEVAR statement are thosespecifically used in the covariance calculation, so ID &related variables aren’t included.

I Every column in the data must be named.I The equal sign and ARE can be used interchangeably, but

the equal sign can’t be confused for a variable name.I Other statements include:

I CATEGORICAL, NOMINAL & CENSOREDI MISSING, which specifies missing data symbolsI IDVARIABLE, GROUPING, CLUSTER, etc.I And many more analysis-specific statements.

Estabrook University of Virginia

Mplus

Page 10: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The VARIABLE: CommandA Note About the Dash

VARIABLE:NAMES = ID x1-x3 y1-y3 z1-z3;USEVARIABLES = x1-x3 y1-y3;

I The code above uses dashes to gloss over repetition.I x1-x3 refers to x1, x2 and x3.I No leading zeros.

I Outside of (after) the VARIABLE: command, these willrefer to the variable array (list) as defined byUSEVARIABLES

I Referring to x1-y3 would refer to x1, x2, x3, y1, y2, & y3.I Had I listed the variables in the USEVARIABLES statement

as x1 y3 y2 x3 x2 y1, stating x1-x3 would referencex1, y3, y2 and x3.

Estabrook University of Virginia

Mplus

Page 11: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The ANALYSIS: Command

I The ANALYSIS: command is used for specifying specificanalysis types and changing estimation procedures.

I Fun topics include:I The TYPE statement, which specifies analysis types

(BASIC, EFA, MIXTURE, TWOLEVEL)I The ESTIMATOR statement (flavors of ML and least

squares).I The INTEGRATION statement, for affecting integration

techniques for ML (STANDARD, GAUSSHERMITE,MONTECARLO)

Estabrook University of Virginia

Mplus

Page 12: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The OUTPUT: CommandHey, you skipped MODEL:

I The OUTPUT: command is to control what is output.I When it runs, Mplus creates an output file using the

extension .out.I It typically includes:

I Estimation and model summaries.I Covariance coverage.I Model fit statistics.I Parameter estimates and standard errors.

I A number of things can be included or suppressed,spanning statistical and technical output.

Estabrook University of Virginia

Mplus

Page 13: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The MODEL: Command

I This is where Mplus becomes a language.I Models are built in terms of relationships between

variables.I The general structure is as follows:

Variable RELATIONSHIP Variable (label);

I The label is always optional, and is of more use forconstraints than for actual labeling.

Estabrook University of Virginia

Mplus

Page 14: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Variances

I Variances are pretty easy. You just name the variable.

X1

X1;

Estabrook University of Virginia

Mplus

Page 15: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Covariances

I Covariances are specified using WITH, as in “this covarieswith that.”

X1 X2

a c

b

X1 WITH X2;

Estabrook University of Virginia

Mplus

Page 16: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

RegressionI Regressions are specified using ON, as in “this is

regressed on that.”I The first variable is the dependent variable, which is

regressed on the independent variable.

X1 Y1

Y1 ON X1;

Estabrook University of Virginia

Mplus

Page 17: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

MeansI The means of variables are specified by placing that

variable’s name inside square brackets.I Path-tracing rules apply.I Manifest variable means are often estimated by default.

Y11

[Y1];

Estabrook University of Virginia

Mplus

Page 18: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

ExampleI We now have all of the tools we need to estimate the

following model:

X1

Y1

X2

1

β1

β2

σ12

σ21

σ22

σ2e

µ1

µ2

µy

Estabrook University of Virginia

Mplus

Page 19: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Example

I Here’s the MODEL statement for that model:

MODEL:!RegressionsY1 ON X1-X2;!CovariancesX1 WITH X2;!VariancesX1; X2; Y1;!Means;[X1 X2 Y1];

Estabrook University of Virginia

Mplus

Page 20: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Example

I Here’s the full code for that model:

TITLE: DADA’s first model;DATA: file=mydata.txt;VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;

USEVAR= x1 x2 y1;MODEL:!RegressionsY1 ON X1-X2;!CovariancesX1 WITH X2;!VariancesX1; X2; Y1;!Means;[X1 X2 Y1];

OUTPUT: SAMPSTAT STANDARDIZED;

Estabrook University of Virginia

Mplus

Page 21: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Output from the Example, Part ISUMMARY OF ANALYSIS

Number of groups 1Number of observations 100

Number of dependent variables 1Number of independent variables 2Number of continuous latent variables 0

Observed dependent variables

ContinuousY1

Observed independent variablesX1 X2

Estimator MLInformation matrix OBSERVEDMaximum number of iterations 1000Convergence criterion 0.500D-04Maximum number of steepest descent iterations 20

Input data file(s)mydata.txt

Input data format FREE

Estabrook University of Virginia

Mplus

Page 22: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Output from the Example, Part II

SAMPLE STATISTICS

MeansY1 X1 X2________ ________ ________

1 -0.148 0.673 0.638

CovariancesY1 X1 X2________ ________ ________

Y1 0.894X1 0.689 1.672X2 0.748 1.430 2.024

CorrelationsY1 X1 X2________ ________ ________

Y1 1.000X1 0.564 1.000X2 0.556 0.778 1.000

I This is what was requested with the SAMPSTAT statementfrom the OUTPUT command.

Estabrook University of Virginia

Mplus

Page 23: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Output from the Example, Part III

THE MODEL ESTIMATION TERMINATED NORMALLY

TESTS OF MODEL FIT

Chi-Square Test of Model Fit

Value 0.000Degrees of Freedom 0P-Value 0.0000

Chi-Square Test of Model Fit for the Baseline Model

Value 43.529Degrees of Freedom 2P-Value 0.0000

CFI/TLI

CFI 1.000TLI 1.000

Loglikelihood

H0 Value -412.847H1 Value -412.847

Estabrook University of Virginia

Mplus

Page 24: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Output from the Example, Part IV

Information Criteria

Number of Free Parameters 9Akaike (AIC) 843.695Bayesian (BIC) 867.141Sample-Size Adjusted BIC 838.717(n* = (n + 2) / 24)

RMSEA (Root Mean Square Error Of Approximation)

Estimate 0.00090 Percent C.I. 0.000 0.000Probability RMSEA <= .05 0.000

SRMR (Standardized Root Mean Square Residual)

Value 0.000

I That’s the standard set of model fit statistics for Mplus.

Estabrook University of Virginia

Mplus

Page 25: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Output from the Example, Part VMODEL RESULTS

Two-TailedEstimate S.E. Est./S.E. P-Value

Y1 ONX1 0.242 0.094 2.588 0.010X2 0.199 0.085 2.336 0.019

X1 WITHX2 1.430 0.233 6.139 0.000

MeansX1 0.673 0.129 5.204 0.000X2 0.638 0.142 4.488 0.000

InterceptsY1 -0.438 0.086 -5.097 0.000

VariancesX1 1.672 0.236 7.071 0.000X2 2.023 0.286 7.071 0.000

Residual VariancesY1 0.578 0.082 7.071 0.000

I The STANDARDIZE statement from the OUTPUT commandrequested a standardized version of this.

Estabrook University of Virginia

Mplus

Page 26: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Output from the Example, Part VI

R-SQUARE

Observed Two-TailedVariable Estimate S.E. Est./S.E. P-Value

Y1 0.353 0.077 4.590 0.000

QUALITY OF NUMERICAL RESULTS

Condition Number for the Information Matrix 0.813E-02(ratio of smallest to largest eigenvalue)

Beginning Time: 15:59:25Ending Time: 15:59:25

Elapsed Time: 00:00:00

I And that’s (finally) the end of the code.

Estabrook University of Virginia

Mplus

Page 27: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mplus Output for Basic Modeling

I Mplus spits out a lot of output.I All of this output is essentially in a text file.

I These sections will always occur in the same order, sothese text files can be stripped for their parameters.

I However, warnings and other runoff can change linenumbers, so codes to read .out files should probably bedone on a case-by-case basis.

I Any questions about manifest variable models?

Estabrook University of Virginia

Mplus

Page 28: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Incorporating Latent VariablesI Incorporating latent variables is easy; just refer to them.I The language for defining latent variables is BY, as in “F1

defined by x1-x3."I This links latent variables to their manifest (or latent)

definition variables by way of regressions.

X1 X2 X3 X4 X5

a1 a2 a3 a4 a5

e1 e2 e3 e4 e5

σ21 σ2

2 σ23 σ2

4 σ25

F

σ2F

f1 BY x1-x3;

Estabrook University of Virginia

Mplus

Page 29: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Scaling Latent Variables

I Latent variables require a scale.I Mplus default will constrain the first regression implied by aBY statement at 1, and allow the factor variance and allother regressions will be freely estimated.

I This is the specification of the factor model on which thedefault is based:

f1 BY x1-x3; !Regressions that define factorf1; !Factor Variance

I Standardized factor loadings can be found by including theSTANDARDIZE statement in the OUTPUT command.

Estabrook University of Virginia

Mplus

Page 30: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Making simple constraintsI You may wish to define latent variables differently or

otherwise make simple constraints.I We can constrain a particular relationship to be constant.

I Most commonly, these constants are zero (covariances &regressions) or unity (variances).

I They’ll also play a role in growth modeling and dynamicalsystems.

I We can force parameters to be freely estimated.I Useful when overriding a default.I This is how Mplus handles starting value specification.

I We can constrain some number of free parameters(relationships) to be equal.

I Remember, equality constraints differ in meaning acrossparameterizations.

Estabrook University of Virginia

Mplus

Page 31: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Making simple constraints

I Constraints to a constant are made with an @:

f1@1; !Factor Variance Constrained to 1x1 WITH x2@0; !Covariance Constrained to 0

I Free estimation & starting values use a *:[f1*]; !Factor Mean Freely Estimatedf1 BY x1*1; !Regression Freely Estimated,Starting Value=1

I Equality constraints use labels in parentheses:x1 (e); x2 (e); !Variances of x1 and x2 Equalx1 WITH y1 (cov);x2 WITH y2 (cov); !Covariances Equal

Estabrook University of Virginia

Mplus

Page 32: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Latent and Constraint Example

I We can go through a few model statements for examplesinvolving latent variables & constraints.

I First, a common factor model, using defaults:I Factor defined by constraining first referenced regression

(x1 in BY statement) to 1.I Manifest variables have means, latent variable doesn’t.

MODEL:!Regressionsf1 BY x1-x3;!Manifest Variancesx1-x3;!Latent Variancesf1;

Estabrook University of Virginia

Mplus

Page 33: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Restating That Example

I Let’s refit that same model, blowing off the defaults anddefining the factor as having unit variance:

MODEL:!Regressionsf1 BY x1-x3*; !The * is applied to all threeloadings!Manifest Variancesx1-x3;!Latent Variance Constrained to 1f1@1;!Means[x1 x2 x3]; [f1@0];

Estabrook University of Virginia

Mplus

Page 34: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Latent Growth CurvesI Let’s fit a linear growth curve model, considering x1-x3 as

three timepoints:

MODEL:!Regressionslevel BY x1-x3@1; !The @1 is distributiveslope BY x1@0; !Slope loading at time 1slope BY [email protected]; !Slope loading at time 2slope BY x3@1; !Slope loading at time 3!Manifest VariancesX1-X3 (e);!Latent Variances & Covarianceslevel; slope;level WITH slope;!Means[x1-x3@0]; [level* slope*];

Estabrook University of Virginia

Mplus

Page 35: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Latent Basis Growth CurvesI Let’s fit a latent basis growth curve model. Find the

difference:

MODEL:!Regressionslevel BY x1-x3@1; !The @1 is distributiveslope BY x1@0; !Slope loading at time 1slope BY x2*0.5; !Slope loading at time 2slope BY x3@1; !Slope loading at time 3!Manifest VariancesX1-X3 (e);!Latent Variances & Covarianceslevel; slope;level WITH slope;!Means[x1-x3@0]; [level* slope*];

Estabrook University of Virginia

Mplus

Page 36: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Different Model Constraints

I More complex model constraints can also be done inMplus.

I The MODEL CONSTRAINT statement goes at the end ofthe MODEL command, and specifies relationships betweenthe labeled paths in the model.

I A large number of functions are available, which we’llreview when we get to transformations later.

MODEL:!Regressionsf2 ON f1 (reg);!Manifest Variancesf1@1; f2 (var2);MODEL CONSTRAINT:var2=1-reg**2;!Variance of Factor 2=1

Estabrook University of Virginia

Mplus

Page 37: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Different Model ConstraintsI Variables from the dataset that aren’t in the model may be

used in constraints if identified by CONSTRAINTS in theVARIABLE command.

I New variables can also be created for the purposes ofmodel constraints.

MODEL CONSTRAINT:NEW (k*1)var2=var1**k;var3=var2**k

I Model constraints can be tested using the Wald test withthe MODEL TEST statement.

x1-x3 (varx); y1-y3 (vary);MODEL TEST:varx=vary;

Estabrook University of Virginia

Mplus

Page 38: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Advanced Language UsageLatent Variable Specification

I There are some things that I need to address regardinguse of the language for larger models.

I Some are necessary, dealing with defaults and programspecifics that can crash the program.

I Some are just nice to know, saving you keystrokes andkeeping models intuitive and manageable.

I Latent Variables must be defined before they are used incovariances, as predictors or in definitions of other latentvariables.

I As they’re not defined in the USEVAR statement, you haveto be a little careful.

I If you run a second-order factor analysis, you must codethe first level first.

Estabrook University of Virginia

Mplus

Page 39: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Advanced Language UsageEfficient Coding

I You can put series of variables on both sides of an option,and all possible permutations are employed. For instance:

x1-x2 WITH y1-y3;

I is the same as this mess:x1 WITH y1; x2 WITH y1;x1 WITH y2; x2 WITH y2;x1 WITH y3; x2 WITH y3;

I Variables can appear on both sides of a WITH statementwith no effect but a meaningless warning.

Estabrook University of Virginia

Mplus

Page 40: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Advanced Language UsagePairwise Statements

I You can employ pairwise use of the ON and WITH optionsby prefixing them with the letter “P."

I These options must be balanced.I For example:

x1-x3 PWITH y1-y3;

I is the same as the following:x1 WITH y1;x2 WITH y2;x3 WITH y3;

I This is particularly useful for equality constraints throughlabeling.

Estabrook University of Virginia

Mplus

Page 41: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Review and Questions

I With this small set of commands, you could fit a largemajority of the SEM models in use in psychology.

I You can leave the TITLE and OUTPUT lines out in manycases, leaving the DATA, VARIABLE & MODEL commands.

I You could do everything but your model specification inthree lines of code.

I See the manual (available for free) for more informationand a host of examples.

Estabrook University of Virginia

Mplus

Page 42: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Variable-Related Modeling Issues

I Missing Data.I Data transformation and definitions.I Categorical Data.I Multiple Groups.

Estabrook University of Virginia

Mplus

Page 43: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Missing Data

I Mplus has a few different ways of dealing with missingdata, but the most common involves MCAR & MARassumptions and FIML.

I The EM algorithm is used here, but some documentationrefers to a multiple group approach as well.

I The general way of invoking these assumptions is tospecify a character for missing data in the VARIABLEcommand with the MISSING statement.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;MISSING = .;!MISSING IS .; !Works just as well

Estabrook University of Virginia

Mplus

Page 44: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Missing DataNotes

I By default, Mplus throws warnings when covariancecoverage is below 10%

I You may specify multiple missingness codes, or differentcodes for different variables.

MISSING = ALL(-999);!All -999s are missingMISSING = x1-y3(1 -999) z1-z3(.);!1s and -999smissing for x1-y3; dots missing z1-z3

I Missingness status can be calculated as a binary variableusing DATA MISSING:

DATA: FILE=mydata.txtDATA MISSING: NAMES = x1;

BINARY = u1;

Estabrook University of Virginia

Mplus

Page 45: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

TransformationsThe DEFINE command

I One can create new variables with the DEFINE command.I New variables can be functions of any variable or set of

variables in the dataset.I To use them in analysis, new variables must be listed in theUSEVAR list after all preexisting variables.

I These variables function just like any other manifestvariable.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-x3 new;

DEFINE: new=log(z1)*y2;

Estabrook University of Virginia

Mplus

Page 46: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

The DEFINE commandSupported Functions

I A large number of functions can be used:I Arithmetic: +, -, *, /, **, % (remainder).I LOG, LOG10, EXP, SQRT, ABS, SIN, COS, TAN,ASIN, ACOS, ATAN

I CUT can be used to chop a continuous variable into anumber of categories:

CUT z3 (-1 0 1); !Yields 4 categories for z3

I You can also define new variables conditionally:I AND, OR, NOT, EQ(==), NE(/=), GE(>=),LE(<=), GT(>), LT(<)

I IF, THEN

IF (x1 GE 0 AND sex NE 1) THEN test=14;

Estabrook University of Virginia

Mplus

Page 47: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Categorical DataI A lot of the original work to come through Mplus has

involved its categorical data handling.I Four statements in the VARIABLE command deal with this:

I CATEGORICAL (binary and ordinal variables),I NOMINAL,I CENSORED, andI COUNT

I In general, Mplus deals with categorical data parametersusing # to designate special properties like thresholds,categories and inflation.

I Categorical data is automatically recoded in ascendingintegers, starting with zero.

u1#1 !Threshold between categories 0 and 1

Estabrook University of Virginia

Mplus

Page 48: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

CATEGORICAL DataI The most common category for categorical data isCATEGORICAL.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;CATEGORICAL = z1-z3;

I This specifies some variables (z1-z3) as ordinal (binary ifonly two categories are found).

I These variables can be referred to like any other.I They can’t have more than 10 unique categories.I Invoking this statement will likely change your estimator.

I You have some control over parameterization, particularlyfor binary items.

I In the DELTA parameterization, scale factors (loadings) areparameters, residual variances are not (default).

I The THETA parameterization is the opposite.

Estabrook University of Virginia

Mplus

Page 49: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

NOMINAL Data

I NOMINAL data functions very similarly to CATEGORICALdata.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;NOMINAL = z1-z3;

I You can refer to all but the last (reference) category.I These seem to be more commonly used for path models as

opposed to more advanced and latent variable models.I I don’t know of a way to define the reference group.

Estabrook University of Virginia

Mplus

Page 50: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

CENSORED Data

I CENSORED data requires an additional argument,specifying the direction of censoring and whether inflatedmodels will be used.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;CENSORED = z1 (a) z2 (b) z3 (ai);

I Above (a) & below (b) refer to censoring at the top andbottom of the range of data, with the suffix “i" indicatinginflation.

I Inflated variable modeling creates an additional binarylatent variable for analysis, referenced by variable#1.

I Model assumptions for censored data should be known andconsidered in advance.

Estabrook University of Virginia

Mplus

Page 51: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

COUNT Data

I COUNT data is useful for specifying variables for Poissonand zero-inflated Poisson models

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;COUNT = z1 z2 (i) z3;

I Simply listing the variable treats it as a count variable forother analyses.

I The suffix (i) functions similarly to the CENSORED example,creating a binary latent variable that can be referenced andmodeled by variable#1.

Estabrook University of Virginia

Mplus

Page 52: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multiple Group Modeling

I Mplus supports multiple group analysis for virtually all of itsanalysis types.

I Multiple group EFAs aren’t available, but that’s easy enoughto work around.

I Mixture models don’t support multiple groups, but do havea KNOWNCLASS option that functions similarly.

I Grouping is specified with the GROUPING statement in theVARIABLE command.

I This variable is not a part of the USEVAR array.I All levels of the variable must be named for later reference.I Multiple datasets are also supported.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;GROUPING = sex (1=male, 2=female);

Estabrook University of Virginia

Mplus

Page 53: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multiple Group Modeling

I When a multiple group model is requested, all groups arefit with the model specified in the MODEL command.

I One can also specify group specific model commands.I The MODEL command specifies the general model.I Group specific models are specified with MODELgroupname;

MODEL:f1 BY x1-z3;x1-z3; f1;

MODEL male;f1 BY x1-y3;f2 BY z1-z3;x1-z3; f1; f2;

Estabrook University of Virginia

Mplus

Page 54: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multiple Group Modeling DefaultsMplus likes to guess what you mean

I All groups are fit with the same model by default, but not allparameters are held constant across groups.

I These parameters are equal by default across groups:I Factor loadings.I Intercepts & thresholds for factor indicators.I Think (strong) measurement invariance.

I These parameters freely vary by default across groups:I Manifest residual variances.I Latent means, variances and covariances.I Latent means for “first" group is zero; all others free.

I Equalities can still be done using labels.I Free parameters in group-specific model statements

override defaults.

Estabrook University of Virginia

Mplus

Page 55: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multiple Group Modeling DefaultsTwo-Group Example Using Sex

MODEL:f1 BY x1-x3; !Constantf2 BY y1-y3; !Across Groupsf3 BY z1-z3; !By Default[x1-z3@0];

MODEL male;f1 f1 f2 PWITH f2 f3 f3 (1-3);[f1* f2* f3*];f1-f3 (4-6); x1-z3 (11-19);

MODEL female;f1 f1 f2 PWITH f2 f3 f3 (1-3);[f1* f2* f3*];f1-f3 (4-6); x1-z3 (11-19);

I This will test for group differences in factor means.

Estabrook University of Virginia

Mplus

Page 56: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Review and Questions

I Mplus relies on the VARIABLE command to alter the typesof models it can run.

I It handles missing data reasonably well.I You can define new variables without affecting your data.I You can actually handle non-continuous items.I Multiple groups is very easy to do, although constraints can

be a problem.I Using these options will change the models you run.

I Every model has an implied default estimator, though manyother options are available.

I Categorical data tends to employ variants of LS, whichchange model output, statistics and greatly affectcomputation times.

Estabrook University of Virginia

Mplus

Page 57: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Alternative Modeling Topics

I Some models not often thought of from a structuralmodeling framework can be estimated using Mplus.

I These typically specifying a TYPE in the ANALYSIScommand.

I They co-opt the language of the MODEL commandwhenever possible, and have a few extra components.

I Exploratory Factor Analysis (TYPE=EFA).I Multilevel and Mixed Modeling (TYPE=RANDOM).I Mixture Distributions (TYPE=MIXTURE).I Other models.

Estabrook University of Virginia

Mplus

Page 58: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Exploratory Factor AnalysisOkay, this isn’t that advanced.

I Exploratory Factor Analysis is easy in that there is no needfor a MODEL statement.

I It is our first use of the ANALYSIS command.I This analysis consists of an analysis type (EFA), which

requires two arguments, the minimum and maximumnumber of factors to be extracted.

I One can also add options, like ROTATION in this code:

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;

ANALYSIS: TYPE = EFA 1 4;ROTATION = PROMAX;

Estabrook University of Virginia

Mplus

Page 59: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixed and Multilevel ModelingDifferent conceptually, but often equivalent.

I There are a number of ways to deal with mixed andmultilevel models in Mplus.

I If you can specify them using the discrete-time SEMapproach, more power to you.

I Mplus differentiates between growth curves (its primarymixed functionality) and multilevel models (in which itfocuses on two-level models).

I First, we’ll talk about a different way to deal with growthcurves.

I Then we’ll deal with the multilevel capabilities.

Estabrook University of Virginia

Mplus

Page 60: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixed & Growth Curve Models

I Mplus allows for the specification of latent growth curvesand other random effect models using ANALYSIS:TYPE=RANDOM, using a “|" for model specification.

I For those unfamiliar, this is Shift+\, which looks like adashed line, pronounced “pipe."

I The focus is certainly on growth curves, but you can trick ita little bit.

I The general format is:

growth parameters | manifest variables@time information

Estabrook University of Virginia

Mplus

Page 61: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixed & Growth Curve Models

I This is the standard linear growth curve:

i s | x1@0 [email protected] [email protected] [email protected] x5@1;

I TYPE=RANDOM need not be specified, but is implied, bythis.

I When two variables are on the left side of the pipe, a linearmodel is fit.

I The (latent) variables specified on the left side can takeany name you give them; “i" and “s" are common throughthe Mplus manual.

Estabrook University of Virginia

Mplus

Page 62: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixed & Growth Curve Models

I We can fit quadratic models:

MODEL:i s q | x1@0 [email protected] [email protected] [email protected] x5@1;

I or cubic models:

MODEL:i s q c| x1@0 [email protected] [email protected] [email protected] x5@1;

I The format is the same.I First variable is always intercept.I After that, increasing powers of the time variables.

Estabrook University of Virginia

Mplus

Page 63: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixed & Growth Curve ModelsWhat if time isn’t fixed?

I TYPE=RANDOM models can put a TSCORES option in theVARIABLES command.

I This option specifies variables that contain time informationfor mixed models that shouldn’t be in the covariancecalculation.

I For example:

VARIABLE:TSCORES = t1-t5;MODEL:i s q | x1-x5 AT t1-t5;

I This is a quadratic growth curve model for longitudinal datawith individually varying times of observation.

I You can do more.

Estabrook University of Virginia

Mplus

Page 64: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

TYPE=RANDOM tricks

I As an aside, the pipe in TYPE=RANDOM is used to createnew random effect variables, generally as the product oftwo other variables.

I This creates a random regression effect “rand":

rand | y ON x; !Requires TYPE=TWOLEVEL

I XWITH specifies multiplication, which is very handy forinteractions between latent variables:

int | i XWITH s;X2 | X XWITH X;

Estabrook University of Virginia

Mplus

Page 65: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multilevel Modeling

I Multilevel modeling (or heirarchical linear modeling, orrandom effect modeling, etc) is an important part ofmodern psychological research.

I In Mplus, this requires three components:I The identification of a CLUSTERing variable in theVARIABLE command,

I The specification of TYPE=TWOLEVEL in the ANALYSIScommand, and

I Between and within group models in the MODEL command.I Let’s see how it works!

Estabrook University of Virginia

Mplus

Page 66: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multilevel Modeling

VARIABLE: NAMES = ID x y zWITHIN = x;BETWEEN = z;CLUSTER = ID;

ANALYSIS: TYPE=TWOLEVEL;

MODEL:%WITHIN%y ON x;%BETWEEN%y ON z;!Defaults Shamelessly Employed

Estabrook University of Virginia

Mplus

Page 67: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Multilevel Modeling

MODEL:%WITHIN%y ON x;%BETWEEN%y ON z;

I y is predicted from x, which varies at the individual level,and z, which varies at the cluster or group level.

I There are, of course, much more complex options.I In particular, multilevel mixture models and higher order

clustering.I These topics are officially special topics, and are two in

depth to be dealt with here.

Estabrook University of Virginia

Mplus

Page 68: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Questions on Mixed/Random and Multilevel Models

I Depending on intent and specification, one could usethese two styles of analysis for very similar problems.

I They both have strengths and drawbacks, and expectdifferent data formats.

I Random components expect wide-formatone-entry-per-row data.

I Multilevel is expects the tall-format presentation of clustereddata.

I They’re very useful parts of Mplus.

Estabrook University of Virginia

Mplus

Page 69: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixture ModelingI Mixture modeling is supported under the ANALYSIS

command’s TYPE=MIXTURE option.I Required components:

I A VARIABLE which designates the number and name ofclasses.

I Some differences in the models across classes to make themodel identifiable.

I The overall model is stated with %OVERALL%, with themodels for different classes referenced with%classvariable#class%.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-z3;CLASSES = c (2);

ANALYSIS: TYPE=MIXTURE;

Estabrook University of Virginia

Mplus

Page 70: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixture Modeling

I Here’s a (relatively) simple example.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1 y1;CLASSES = c (2);

ANALYSIS: TYPE=MIXTURE;MODEL:%OVERALL%y1 ON x1;!Regressiony1 ON c;!Classes have different meansc ON x1;!Logistic Regression%c#2%y1 ON x1;!Regression depends on class

Estabrook University of Virginia

Mplus

Page 71: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixture Modeling

I Here’s a growth mixture model, using the parameterizationwe discussed for TYPE=RANDOM.

VARIABLE: NAMES = ID sex x1-x3 y1-y3 z1-z3;USEVAR = x1-x3;CLASSES = c (2);

ANALYSIS: TYPE=MIXTURE;STARTS = 20 2;!20 sets of starting values!2 sets used for final evaluation

MODEL:%OVERALL%i s | x1@0 [email protected] x3@1;!Growth Model!Class Mean Differencesi s ON c;

Estabrook University of Virginia

Mplus

Page 72: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Mixture ModelingGood time for questions

I Mixture output includes:I Likelihood based fit.I Class membership, proportions and entropy.I Parameter estimates regarding binary latent class variable.

I Other features of mixture modeling framework:I Multiple sets of classes may be used.I Known classes may be used, either for mixture capabilities

or an alternative approach to multiple group models.I Multilevel mixture modeling & mixture modeling for complex

survey data.

Estabrook University of Virginia

Mplus

Page 73: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Other Models

I Survival Analysis.I Parametric and Cox PH survival models are options.I ANALYSIS: BASEHAZARD=ON or OFF

I Parameterization:I VARIABLE command takes SURVIVAL andTIMECENSORED statements to identify time and censoringvariables.

I The variable referenced by SURVIVAL is used in the model,with the TIMECENSORED associated with in in theappropriate way.

I Questions?

Estabrook University of Virginia

Mplus

Page 74: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Monte Carlo CapabilitiesI Mplus can be used for Monte Carlo studies.

I Of course, you could do this manually, using anotherprogram to generate data and a batch file to call Mplus.

I The real virtue of Mplus in this regard is that it cangenerate data for Monte Carlo work based on yourparameters.

I Scripts for Monte Carlo studies require the followingcommands:

I MONTECARLO, which replaces the DATA and VARIABLEcommands to describe the dimensions of the data, as wellas the simulation parameters.

I MODEL POPULATION, which specifies the underlyingpopulation model which is used to generate the data.

I MODEL MISSING (optional), which specifies a model formissingness.

I MODEL, which specifies the model you’re trying to fit.

Estabrook University of Virginia

Mplus

Page 75: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Monte Carlo CapabilitiesThe MONTECARLO Command

I The following statements fall under the MONTECARLOcommand:

I NAMES, which names the variables;I NOBSERVATIONS, which states the number of observations

per dataset;I NREPS, which gives the number of repetitions for the

simulation;I SEED, which specifies the random seed (optional);I CUTPOINTS, which specifies some variables as binary and

gives a cutpoint for the standard normal distribution used indata generation.

I PATMISS, which gives pattern(s) of missing data. If multiplepatterns are used, they are separated by a | and thePATPROBS statement describes the probabilities of eachpattern.

Estabrook University of Virginia

Mplus

Page 76: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Monte Carlo CapabilitiesThe MONTECARLO Command

MONTECARLO:NAMES = x1-x5 sex;NOBSERVATIONS = 100;NREPS = 500;SEED = 090219;CUTPOINTS = sex (0);PATMISS = x1 (.1) x2 (.05) x3 (.2) x4 (.1) |

x1 (.5) x2 (.5) x3 (.05) x4 (.3);PATPROBS = .9 | .1;

Estabrook University of Virginia

Mplus

Page 77: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Monte Carlo CapabilitiesThe MODEL POPULATION Command

MODEL POPULATION:level BY x1-x5@1;slope BY x1@0;slope BY x2*.25;slope BY x3*.5;slope BY x4*.75;slope BY x5@1;level; slope; level WITH slope*.2;[x1-x5@0; level; slope;]level ON sex*1;slope ON sex*0;

I Why use @ and * interchangeably?

Estabrook University of Virginia

Mplus

Page 78: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Monte Carlo CapabilitiesThe MODEL Command

MODEL:level BY x1-x5@1;slope BY x1@0;slope BY x2*.25;slope BY x3*.5;slope BY x4*.75;slope BY x5@1;level; slope; level WITH slope*.2;[x1-x5@0; level; slope;]level ON sex*1;slope ON sex*0;

I If you’re fitting the same model you’re generating.

Estabrook University of Virginia

Mplus

Page 79: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Monte Carlo CapabilitiesAdvanced Usage

I Mplus’ Monte Carlo Capabilities can be used to generatedata for and fit any of the models we’ve discussed heretoday.

I It also has the following capabilities:I Output generated data for later analysis.I Read previously generated data for a Monte Carlo study.I Output estimates as a data file for later analysis.

I There’s not a lot I can say that the manual doesn’t on thesetopics.

Estabrook University of Virginia

Mplus

Page 80: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Summary

I There are many topics we didn’t cover.I Technical output control, from viewing the (LISREL style)

matrices to modification indices.I Data and statistical output for later analysis.I The PLOT command.I Support for advanced data structures, from long-to-wide

transformations to cohort data.I Bootstrapping.I Categorical Latent Variables and their scale factors.I Indirect effects and their standard errors.I Integration options (INTEGRATION=MONTECARLO is good

to know).I Mplus is a good tool. It’s not a perfect tool. Use it, don’t

use it, and/or write a competing program.

Estabrook University of Virginia

Mplus

Page 81: Estabrook Intro to Mplus

Mplus Basics Latent Variable Non-SEM Monte Carlo

Acknowledgements

I John Nesselroade.I Jack McArdle, Aki Hamagami, Kevin Grimm.I All members of the OpenMx development team.

Estabrook University of Virginia

Mplus