Parsing a String with DO Statements
This function parses a string and expands this string in case of DO
statements which are shortcuts for writing loops. The statement
DO(n,m,k)
increments an index from n
to m
in steps
of k
. The index in the string model
must be defined
as %
. For a nested loop within a loop,
the DO2
statement can be used using %1
and %2
as indices. See Examples for hints on the specification. The loop in DO2
must not be explicitly crossed, e.g. in applications for specifying
covariances or correlations. The formal syntax for for (ii in 1:(K-1)){ for (jj in (ii+1):K) { ... } }
can be written as DO2(1,K-1,1,%1,K,1
)
. See Example 2.
doparse(model)
model |
A string with |
Parsed string in which DO
statements are expanded.
This function is also used in lavaanify.IRT
and
tamaanify
.
############################################################################# # EXAMPLE 1: doparse example ############################################################################# # define model model <- " # items I1,...,I10 load on G DO(1,10,1) G=~ lamg% * I% DOEND I2 | 0.75*t1 v10 > 0 ; # The first index loops from 1 to 3 and the second index loops from 1 to 2 DO2(1,3,1, 1,2,1) F%2=~ a%2%1 * A%2%1 ; DOEND # Loop from 1 to 9 with steps of 2 DO(1,9,2) HA1=~ I% I% | beta% * t1 DOEND " # process string out <- TAM::doparse(model) cat(out) ## # items I1,...,I10 load on G ## G=~ lamg1 * I1 ## G=~ lamg2 * I2 ## G=~ lamg3 * I3 ## G=~ lamg4 * I4 ## G=~ lamg5 * I5 ## G=~ lamg6 * I6 ## G=~ lamg7 * I7 ## G=~ lamg8 * I8 ## G=~ lamg9 * I9 ## G=~ lamg10 * I10 ## I2 | 0.75*t1 ## v10 > 0 ## F1=~ a11 * A11 ## F2=~ a21 * A21 ## F1=~ a12 * A12 ## F2=~ a22 * A22 ## F1=~ a13 * A13 ## F2=~ a23 * A23 ## HA1=~ I1 ## HA1=~ I3 ## HA1=~ I5 ## HA1=~ I7 ## HA1=~ I9 ## I1 | beta1 * t1 ## I3 | beta3 * t1 ## I5 | beta5 * t1 ## I7 | beta7 * t1 ## I9 | beta9 * t1 ############################################################################# # EXAMPLE 2: doparse with nested loop example ############################################################################# # define model model <- " DO(1,4,1) G=~ lamg% * I% DOEND # specify some correlated residuals DO2(1,3,1,%1,4,1) I%1 ~~ I%2 DOEND " # process string out <- TAM::doparse(model) cat(out) ## G=~ lamg1 * I1 ## G=~ lamg2 * I2 ## G=~ lamg3 * I3 ## G=~ lamg4 * I4 ## # specify some correlated residuals ## I1 ~~ I2 ## I1 ~~ I3 ## I1 ~~ I4 ## I2 ~~ I3 ## I2 ~~ I4 ## I3 ~~ I4
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.