1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
!------------------------------------------------------+
! Latent class analysis via Mx |
! marginal ml again |
! data from http://www.people.vcu.edu/~nhenry/LSA50.htm|
! see |
! Latent Class Probs Item 1 Item 2 Item 3 Item 4 |
! .4243 .9240 .6276 .5704 .5125 |
! .5757 .4324 .1871 .1008 .0635 |
! Mx recovers: |
! .4440 0.90736 0.61444 0.55828 0.50176 |
! .5560 0.42838 0.18218 .09394 .05627 |
!------------------------------------------------------+
#ngroups 2 ! number of groups in run
#define $nvar 5 ! Number of variables altogether, before selection
#define nclass 2
#define $nclass 2
#define nv 4 ! number of variables in model
#define ncov 0 ! number of covariates
#define nclassncov 0 ! nclass * ncov
#define ncnv 8 ! number of variables * number of classes
#define $allvar1 Armyrun Favatt squaredeal welfare freq
#define $covariates FHTTLPR1 FHTTLPR2
#define $variables Armyrun Favatt squaredeal welfare freq
#define $frequencies TRUE
#define $freqlabel freq
#define maxcat 1 ! Maximum score of any item
#define maxcatnc 2 ! Must be maxcat times nclass
!-------------------------------------------------------------------
Group 1: Fit the model
Data Ninput=$nvar Nmodel=$nclass
ORdinal File=lazarsfeld.ord
LAbels
$allvar1
!Select if sex = 0
SElect
#if ncov > 0
$variables
$covariates ;
Definition $covariates ;
#else
$variables ;
#endif
#if $frequencies = TRUE
Definition $freqlabel ;
#end if
Begin matrices;
A full nclass 1
#if ncov > 0
P unit nv ncov
K Full nv nclassncov ! regressions of response probabilities on covariates
S full ncov 1 ! vector of observed covariates
X full nclass ncov ! For regression of class membership probs on covariates
#else
P unit nv 1
K Full nv nclass ! Not required except to make algebra work with no covariates
D full 1 1 ! Not required except to make algebra work
S full 1 1 ! Not required except to make algebra work
X full nclass 1 ! For regression of class membership probs on covariates
#endif
E full 1 nv
F unit maxcat 1
G lower maxcat maxcat
T full maxcatnc nv Free ! thresholds, z-score metric for class probabilities
! note that columns are thresholds within variables
I iden nclass nclass
Q full 1 1 ! for frequency if used
R iden nv nv
U unit 1 1
V unit nv 1
W full nclass 1 free ! class membership probabilities
End Matrices;
!
! Be kind to Mx, fix thresholds that are not going anywhere
!
Value 1 G 1 1 - G maxcat maxcat
#if ncov > 0
Specify S $covariates
#endif
#if $frequencies = TRUE
Specify Q $freqlabel
#end if
Matrix W .2 .8
Begin Algebra;
End Algebra;
Thresholds (I@G)*T+(K*(I@S))' ;
Covariance R;
#if $frequencies = TRUE
Frequency Q;
#end if
#if ncov > 0
Specify S $covariates
#endif
#if $frequencies = TRUE
Specify Q $freqlabel
#end if
Matrix W .2 .8
Begin Algebra;
End Algebra;
Thresholds (I@G)*T+(K*(I@S))' ;
Covariance R;
#if $frequencies = TRUE
Frequency Q;
#end if
#if ncov > 0
Weight (W+X*S)@(\sum(W+X*S)~); ! adjusted for covariates
#else
Weight W ;
#endif
Option onecov
Option func=1.e-9
End Group;
Constrain Un-regressed Weights to sum to 1
Constraint
Begin Matrices;
W full nclass 1 = W1
I unit 1 1
End Matrices;
Constraint I = \sum(W);
End
|