AnthonyRaborn / ShortForm

Algorithms for creating short forms based on psychometric principles.
10 stars 2 forks source link

Ant keeps running and data analysis doesn't end #17

Open zteuber opened 1 year ago

zteuber commented 1 year ago

Dear Anthony,

I'm running a 3-factor model using the "antcolony.mplus" function. Below is my R script. However, it keeps calculating, and after 2 days, it still hasn't finished (see screenshot). Are there any errors in my R script? I've also attached my data.

Best regards, Ziwen

initial.MplusAutomation.model <- MplusAutomation::mplusObject( TITLE = "PGrit Shortform 3 factors;", MODEL = "PE BY PG_PGPE2 PG_PGPE3 PG_PGPE5 PG_PGPE7; SP BY PG_PGSP2 PG_PGSP4 PG_PGSP5 PG_PGSP6 PG_PGSP7; AG BY PG_PGAG1 PG_PGAG2 PG_PGAG3 PG_PGAG4 PG_PGAG6 PG_PGAG7;", ANALYSIS = "ESTIMATOR = WLSMV;", VARIABLE = "CATEGORICAL = PG_PGPE2 PG_PGPE3 PG_PGPE5 PG_PGPE7 PG_PGSP2 PG_PGSP4 PG_PGSP5 PG_PGSP6 PG_PGSP7 PG_PGAG1 PG_PGAG2 PG_PGAG3 PG_PGAG4
PG_PGAG6 PG_PGAG7;", OUTPUT = "stdyx;", rdata = data)

finally, call the function with some minor changes to the default values.

Pgritshort = antcolony.mplus(ants = 20, evaporation = 0.7,

Screenshot 2023-09-19 at 16 01 15
mplus = initial.MplusAutomation.model,
list.items = list(c("PG_PGPE2","PG_PGPE3","PG_PGPE5","PG_PGPE7"), 
                  c("PG_PGSP2","PG_PGSP4","PG_PGSP5","PG_PGSP6","PG_PGSP7"), 
                  c("PG_PGAG1","PG_PGAG2","PG_PGAG3","PG_PGAG4","PG_PGAG6","PG_PGAG7")), 
full = 15,
i.per.f = c(4,4,4), factors = c('PE','SP','AG'), 
steps = 3, max.run = 50, resultfile = NULL,
summaryfile = 'summary.txt',
min.CFI = 0.95, min.TLI = 0.95, max.RMSEA = 0.08,
feedbackfile = 'iteration.html', Mplus.Automation=TRUE,
dataOut = '3factorModel.dat',
modelOut = '3factorModel.inp')

data.csv

AnthonyRaborn commented 1 year ago

Hello,

Unfortunately, the MPlus portion of the code is quite old and I do not have an installation of MPlus that I can test it with. The only thing I can suggest at the moment is to try the lavaan version of the function and see if you have any difficulties that way.

zteuber commented 1 year ago

Hello,

I tried the lavaan version. Unfortunately, it didn't work. Below you can see my codes and a screenshot of the error.

Best wishes, Ziwen

devtools::install_github('AnthonyRaborn/ShortForm', ref = 'bugfix') remotes::install_github('AnthonyRaborn/ShortForm', ref = 'bugfix')

antModel = 'PE =~ PG_PGPE2 + PG_PGPE3 + PG_PGPE5 + PG_PGPE7 SP =~ PG_PGSP2 + PG_PGSP4 + PG_PGSP5 + PG_PGSP6 + PG_PGSP7 AG =~ PG_PGAG1 + PG_PGAG2 + PG_PGAG3 + PG_PGAG4 + PG_PGAG6 + PG_PGAG7'

list.items <- list(c('PG_PGPE2','PG_PGPE3','PG_PGPE5','PG_PGPE7', 'PG_PGSP2','PG_PGSP4','PG_PGSP5','PG_PGSP6','PG_PGSP7', 'PG_PGAG1','PG_PGAG2','PG_PGAG3','PG_PGAG4','PG_PGAG6','PG_PGAG7'))

Grit = antcolony.lavaan(data = pgrit,ants = 20, evaporation = 0.7, antModel = antModel, list.items = list.items, full = 15, i.per.f = c(4,4,4), factors = c('PE', 'SP', 'AG'), steps = 3, fit.indices = c('cfi','rmsea'), fit.statistics.test = "(cfi > 0.9)&(rmsea < 0.08)", summaryfile = 'summary.txt', feedbackfile ='iteration.html', max.run = 100) Grit[[1]]

Screenshot 2023-09-25 at 09 01 45
AnthonyRaborn commented 1 day ago

Note - I have access to Mplus. {antcolony.mplus} is quite behind the main function {antcolony.lavaan} and will need significant updates. This is on the list for updating before doing other code refactoring, but I don't have a timeline for completion yet for this part.

If this is still an issue one year later, would you try the latest code on the main branch (which will soon be on CRAN as v0.5.6)? I made a few minor improvements and the {antcolony.lavaan} function should work a little nicer now. Note that there are also {summary}, {print}, and {plot} methods for the object produced by {antcolony.lavaan} and you can access the exact final model with something like Grit@best_model, which is the lavaan object of the final model produced by the function.