r - Creating lavaan and mirt models permuations of varying size and length -


hoping can offer guidance here.

i'm creating multivariate simulation using simdesign package, varying number of factors items load on each factor. write command identifies number of factors present in factornumbers , assigns appropriate items them (no cross loading). testing combinations of conditions below , more, , have model command acknowledge iterations of differing models, don't have write multiple model statements.

factornumbers<-c(1,2,3,5) itemsperfactor<-c(5,10,30) 

what lavaan , mirt looking below:

mirtmodel<-mirt.model('                     f1=1-15                     f2=16-30                     mean=f1,f2                     cov=f1*f2')  lavmodel <- ' f1=~ item_1 + item_2 + item_3 + item_4 + item_5 + item_6 + item_7 + item_8 + item_9 + item_10 + item_11 + item_12 + item_13 + item_14 + item_15               f2=~ item_16 + item_17 + item_18 + item_19 + item_20 + item_21 + item_22 + item_23 + item_24 + item_25 + item_26 + item_27 + item_28 + item_29 + item_30' 

the simdesign package offers example, expand on i'm not sure have know-how:

lavmodel<-paste0('f=~ ', paste0(colnames(dat)[1l], ' + '),                paste0(colnames(dat)[-1l], collapse = ' + ')) 

what single mirt , lavaan command finds number of factors specified in factornumbers command , assigns correct items specified in data itemsperfactor.

edit: model identification pick on factor & item structure in use condition , fill in model identification correct information.

for example:

mirtmodel<-mirt.model('                     f1=1-1                     f2=6-10                     f3=11-15                     f4=16-20                     f5=21-25                     mean=f1,f2,f3,f4,f5                     cov=f1*f2*f3*f4*f5') 

or

 mirtmodel<-mirt.model('                     f1=1-30                     f2=31-60                     mean=f1,f2                     cov=f1*f2') 

and corresponding lavaan models.

the essential idea here become efficient @ pasting different strings condition input simdesign required construct suitable output string. generating syntax simulations arguably annoying part of simulations, @ least in r there number of helpful string operations.

here's interpretation of looking for.

design <- expand.grid(factornumbers = c(1,2,3,5),                       itemsperfactor = c(5,10,30))  gen_syntax_mirt <- function(condition){     fn <- with(condition, factornumbers)     ipf <- with(condition, itemsperfactor)     nitems <- fn * ipf     maxloads <- sort(seq(nitems, ipf, length.out = fn))     minloads <- c(1, maxloads[-length(maxloads)] + 1)     fnames <- paste0('f', 1:fn)     df <- cbind(fnames, ' = ', minloads, '-', maxloads)     s1 <- apply(df, 1, paste0, collapse = '')     s2 <- paste0('mean = ', paste0(fnames, collapse = ','))     s3 <- paste0('cov = ', paste0(fnames, collapse = '*'))     ret <- paste0(c(s1, s2, s3), collapse = '\n')     mirt.model(ret) }  gen_syntax_mirt(design[1,]) gen_syntax_mirt(design[10,]) 

the input function single row design input runsimulation(), can see here work fine. similar lavaan's syntax , you'll set.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo