Showing posts with label Mplus. Show all posts
Showing posts with label Mplus. Show all posts

Thursday, August 6, 2015

Creating nice SEM diagrams in Powerpoint - the easy way

With five powerpoint shapes, you can create almost any SEM diagram, or at least the diagram below. Just follow the step-by-step guides below, or use this powerpoint template, in which I've included all shapes described below (it's only one slide, see picture). Or, use one of the alternatives at the bottom of the post.



Single headed straight arrow
1) click 'Insert' - 'Shapes'
2) select 'Arrow' under 'Lines'
3) draw
4) right-click on the arrow
5) select 'Format shape'
6) select 'Line style'
7) under 'Arrow settings', select the type and size you would like for the begin and end arrows
8) click 'Close'
9) very good, Daniel-san!

Double headed straight arrow
1) click 'Insert' - 'Shapes',
2) select 'Double headed arrow' under 'Lines',
3) draw
4) right-click on the arrow
5) select 'Format shape'
6) select 'Line style'
7) under 'Arrow settings', select the type and size you would like for the arrow
8) click 'Close'
9) very good, Daniel-san!

Manifest variable
1) click 'Insert' - 'Shapes'
2) select 'Rectangle' under 'Rectangles'
3) draw
4) select the square and just start typing to name the variable 
5) very good, Daniel-san!

Latent variable
1) click 'Insert' - 'Shapes'
2) select 'Oval' under 'Basic Shapes'
3) draw
4) select the circle and just start typing to name the variable
5) very good, Daniel-san!

Double headed curved arrows
Ah, the tricky one! Never use the default 'Curved arrow', it will never look right. Instead:
1) click 'Ínsert' - 'Shapes'
2) select 'Arc' under 'Basic shapes'
3) draw an arc
4) select the rightmost yellow diamond of the arc and drag it to the bottom white square (this should give you the right curve already)
5) right click on the arc
6) select 'Format shape'
7) select 'Line style'
7) under 'Arrow settings', select the type and size you would like for the begin and end arrows
8) click 'Close'
9) very good, Daniel-san!

Alternatives
- Use LaTeX with tikz
- Watch this short video tutorial on creating double head curved arrows in powerpoint: https://www.youtube.com/watch?v=8dAmJxBSLy4

Sunday, February 5, 2012

Getting the largest class last in an Mplus LCA

When performing an LCA, and using likelihood ratio tests for the current, k model, versus the k-1 model (TECH11 and TECH14), according to the MPlus 5 manual, one should make the largest class be last. This has to be done manually (this will be done automatic in a later version of Mplus, I hope!).

For example, p. 659 of the Mplus manual states: "The model with one less class is obtained by deleting the first class in the estimated model. Because of this, it is recommended that model identifying restrictions not be included in the first class. In addition, it is recommended when using starting values that they be chosen so that the last class is the largest class."

Sometimes this takes quite a bit of trial and error, but below is the strategy I have always found to work. It comes down to providing starting values for every class, based on stable estimates obtained in an earlier run.

1) Obtain a stable estimate (i.e. no warnings about best log likelihoods not being replicated) without TECH11 TECH14. Use a large number of random starts, whenever possible, for example by typing STARTS = 200 10 in the ANALYSIS command.

2) Copy and paste the parameter estimates for the tresholds to a text editor (e.g., Tinn-R)

3) Transform these estimates to starting value commands.
a) Remove the last three columns of the estimates for the tresholds (leaving only the first two columns)
b) Every row now consists of something of the form " U11$1 0.531". Make this something of the form "[U11$1 * 0.531]" in every row.
c) Delete the words "Latent Class x" and "Tresholds"
d) Put the number of the last class in front of the parameter estimates of the largest class with the %c#x% statement. The numbers assigned to all the other classes can be anything, as long a they're not the last class or earlier assigned class numbers.
e) End every block of starting value statements with a ";"

4) Paste the starting values to the Mplus syntax you used earlier, and precede it by "MODEL:"

5) Add TECH11 and/or TECH14 to the "OUTPUT" command. Add "LRTSTARTS = 200 10 200 10" to the ANALYSIS command. This will result in 200 random starting value sets in the initial stage, and 10 of those will be used in the final stage optimization. This may be a little overdone, but you'll get stable estimates, and it will reduce the chances of getting the statement: "the best loglikelihood was not replicated in x out of 5 bootstrap draws" in the output. The default is o o 20 5, so if 200 10 200 10 is too computationally demanding, lower these values.

6) Run the syntax, et voilà: works like a charm! (At least, it always does for me...)


Example

The following results were obtained in an LCA, performed on 6 dichotomous items, and 4 classes we're requested. The overall class probabilities were .42, .26, .32. So, to obtain a likelihood ratio test of 3 vs 2 classes, the first class should be last in the analysis. This were the estimates for the tresholds:

Latent Class 1

Thresholds
U11$1 0.531 0.271 1.959 0.050
U13$1 -3.380 0.586 -5.769 0.000
U14$1 -15.000 0.000 999.000 999.000
U15$1 -0.682 0.199 -3.435 0.001
U16$1 -2.101 0.324 -6.486 0.000
U17$1 -3.995 1.318 -3.031 0.002


Latent Class 2

Thresholds
U11$1 -1.374 0.180 -7.649 0.000
U13$1 -15.000 0.000 999.000 999.000
U14$1 -3.841 0.445 -8.630 0.000
U15$1 -1.278 0.108 -11.830 0.000
U16$1 -6.899 5.955 -1.158 0.247
U17$1 -3.790 0.302 -12.553 0.000


Latent Class 3

Thresholds
U11$1 1.313 0.218 6.030 0.000
U13$1 -1.388 0.362 -3.834 0.000
U14$1 -2.332 0.815 -2.860 0.004
U15$1 0.285 0.193 1.473 0.141
U16$1 1.407 0.312 4.507 0.000
U17$1 -2.384 0.538 -4.430 0.000



And this is what it should look like, following the steps under 3) above, when it is pasted into the MODEL command in the Mplus syntax:


%c#3%
[U11$1* 0.531]
[U13$1* -3.380]
[U14$1* -15.000]
[U15$1* -0.682]
[U16$1* -2.101]
[U17$1* -3.995];
%c#1%
[U11$1* -1.374]
[U13$1* -15.000]
[U14$1* -3.841]
[U15$1* -1.278]
[U16$1* -6.899]
[U17$1* -3.790];
%c#2%
[U11$1* 1.313]
[U13$1* -1.388]
[U14$1* -2.332]
[U15$1* 0.285]
[U16$1* 1.407]
[U17$1* -2.384];

Monday, January 30, 2012

Factor mixture analysis in Mplus

I'm using factor mixture analysis (FMA) for the estimation of latent classes (latent categories) and latent traits (latent dimensions) in the same model. I think it's great that this model provides an opportunity for combining factors and classes. Muthen even goes so far as to say that performing a Latent Class Analysis (LCA) or Factor Analysis (FA) is actually performing a restricted Factor Mixture Analysis (FMA), because in these models, the dimensional, or categorical, nature of the latent variables are not taken into account.

I was using the paper "MODELS AND STRATEGIES FOR FMA" on the statmodel website, to see how one would go about fitting such a model. It provides much more practical details about how to do a factor mixture analysis than most of the Muthen papers on FMA, which is great. At the same time, they leave some issues unresolved, and some issues just made me wonder. What follows are the questions / problems I came across, and my opinion on these issues.




Latent (co)variances

While their fmm-2 to fmm-5 models allow for the estimation of factor covariance matrices, only in fmm-3 to fmm-5, covariances between latent traits are modelled. I have been wondering for some time, why only class specific factor variances are modelled in fmm-2, while factor covariances are fixed to zero. The answer is simple and straightforward: by definition, latent classes do not permit covariances between the variables they explain, within classes. Covariances between the latent factors are supposed to be explained by the classes, so no covariations is allowed. However, variation on the latent traits within classes is allowed, by estimating variances for the factors, within class.


Prepare to wait and wait and wait


Estimating (c0)variances for the latent traits requires numerical integration.
This is invoked by adding the line "ALGORITHM = INTEGRATION" in the ANALYSIS command. Be prepared to wait a long time: it may take very long, depending on you sample size, number of observed variables, and number of latent variables. If you want a faster, but less precise solution, add the line "INTEGRATION = STANDARD(7)" (the default is 15). This should speed up things.

Obviously, more factors and more classes take more time. My model, consisting of two factors and 28 binary indicators, running on an HP probook 6550b in Mplus 6, took 24 hours to complete the estimation of a four class model (with the default precision, using 100 random starts and 10 final stage iterations). And then some authors advice to obtain likelihood ratio tests for the k vs. k-1 model comparison. I simply gave up, this would take me a week.


Comparing FMA results to FA or LCA results


I you want to compare the outputs of an exploratory (EFA) or confirmatory factor analysis (consisting of only latent traits, not latent classes) to an FMA model, you may want to obtain values for AIC, BIC and SSABIC to be able to compare an exclusively dimensional model to a factor mixture model. In order to obtain these, use ML estimation (or a robust variation of it: MLM, MLMV or MLR), by typing the line "ESTIMATOR = ML;" in the ANALYSIS command.

How many factors, and how many classes should we fit to the data? The authors don't seem to have an answer, either. In the introduction, they seem to argue that the number of factors and classes of the best fitting models, when only LCA of only FA is applied to the data should be taken as an upper limit for the number of factors and classes in an FMA. Later on however, they note "Because a large number of factors computationally intensive to fit with the already complicated FMM's, the fitting of models stopped with two factors." Yes, and then we didn't even try to obtain the Lo-Mendell-Rubin Likelihood ratio test (TECH 11), or the bootstrapped Likelihood ratio test (TECH 14). I'd suggest you just inspect AIC, BIC and SSABIC values, and especially: check if the model makes sense! A class solution which includes near zero proportions is not a useful solution, so try a solution with less classes.


Different loadings and tresholds (or intercepts) for each class?

Why would one want to estimate different loadings and treshold (or intercepts) in every class? It may result in better model fit, but how are we to interpret the resulting factorial structure? It seems in such a case, we are measuring a different latent variable in every class. Personally, I feel comparing models with non-invariant loadings and tresholds (or intercepts) across classes, turns the factor mixture model into an analysis of measurement invariance across latent classes, which seems to be an altogether different subject.