Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worrisome warnings #93

Open
jpritikin opened this issue Oct 31, 2024 · 4 comments
Open

worrisome warnings #93

jpritikin opened this issue Oct 31, 2024 · 4 comments

Comments

@jpritikin
Copy link

jpritikin commented Oct 31, 2024

lavaan 0.6-19 (cran), blavaan 0.5-6.1311 (via github)

Are these warnings harmless?

Warning messages:
1: lavaan->lavParTable():  
   using a single label per parameter in a multiple group setting implies imposing 
   equality constraints across all the groups; If this is not intended, either remove 
   the label(s), or use a vector of labels (one for each group); See the Multiple 
   groups section in the man page of model.syntax. 
2: In TH[[i]][exidx] <- fit$theta[fit$th.idx] :
  number of items to replace is not a multiple of replacement length
3: lavaan->lav_samplestats_step2():  
   correlation between variables sleep and anxiety is (nearly) 1.0 
4: In TH[[i]][exidx] <- fit$theta[fit$th.idx] :
  number of items to replace is not a multiple of replacement length

Code:

library(rstan)
options(mc.cores = parallel::detectCores()/2)
library(blavaan)

future::plan("multicore")

NoYesLevels <- c('No','Not sure','Yes')
EuphoricLevels <- c('Euphoric', 'Mildly euphoric', 'No change', 'Mild discomfort', 'Severe discomfort')
ImpactLevels <- c('Helped','Slightly helped','No impact','Slightly hindered','Hindered')
AbsItemNames <- c('boredom','frustration','anxiety', 'abort','bodyAcute','bodyAfter','sleep')

ImportStudyItems <- function(df) {
  if (any(is.na(match(AbsItemNames, colnames(df))))) stop("Items are mising")
  
  df[['boredom']] <- ordered(df[['boredom']], levels=NoYesLevels)
  df[['frustration']] <- ordered(df[['frustration']], levels=NoYesLevels)
  df[['anxiety']] <- ordered(df[['anxiety']], levels=NoYesLevels)
  df[['abort']] <- ordered(df[['abort']], levels=NoYesLevels)
  df[['bodyAcute']] <- ordered(df[['bodyAcute']], levels=EuphoricLevels)
  df[['bodyAfter']] <- ordered(df[['bodyAfter']], levels=EuphoricLevels)
  df[['sleep']] <- ordered(df[['sleep']], levels=ImpactLevels)
  df
}

psiData <- ImportStudyItems(read.csv("psi.csv"))
pmData <- ImportStudyItems(read.csv("pm.csv"))
combinedData <- rbind(cbind(psiData, group="psi"),
                      cbind(pmData, group="pm"))
combinedData$group <- factor(combinedData$group, levels=c('psi','pm'))

spec <- '
phenom =~ boredomL*boredom + frustrationL*frustration + anxietyL*anxiety + abortL*abort + bodyAcuteL*bodyAcute + bodyAfterL*bodyAfter + sleepL*sleep

phenom ~ c(0,NA)*1
boredom ~ boredomM*1
frustration ~ frustrationM*1
anxiety ~ anxietyM*1
abort ~ abortM*1
bodyAcute ~ bodyAcuteM*1
bodyAfter ~ bodyAfterM*1
sleep ~ sleepM*1

phenom ~~ 1*phenom
boredom ~~ 1*boredom
frustration ~~ 1*frustration
anxiety ~~ 1*anxiety
abort ~~ 1*abort
bodyAcute ~~ 1*bodyAcute
bodyAfter ~~ 1*bodyAfter
sleep ~~ 1*sleep

boredom | -.431*t1 + .431*t2
frustration | -.431*t1 + .431*t2
anxiety | -.431*t1 + .431*t2
abort | -.431*t1 + .431*t2
bodyAcute | -.842*t1 + -.253*t2 + .253*t3 + .842*t4
bodyAfter | -.842*t1 + -.253*t2 + .253*t3 + .842*t4
sleep | -.842*t1 + -.253*t2 + .253*t3 + .842*t4
'

fit <- blavaan(spec, data=combinedData,
               n.chains = 4,
               ordered = AbsItemNames,
               dp = dpriors(nu="normal(0,1)", alpha="normal(0,1)", lambda="normal(0,1)"),
               group = "group",
               std.lv=TRUE, allow.empty.cell = TRUE, test = "none")
summary(fit)

Data:
pm.csv
psi.csv

@jpritikin jpritikin changed the title number of items to replace is not a multiple of replacement length worrisome warnings Oct 31, 2024
@ecmerkle
Copy link
Owner

ecmerkle commented Nov 7, 2024

I think the first warning is related to lines like this:

boredom ~ boredomM*1

you have two groups, but only one parameter label "boredomM". That implicitly fixes the parameter to be equal across groups. If you didn't want that, you need something like

boredom ~ c("boredom1", "boredom2") * 1

I believe the other warnings are related to lavaan setting up a model with empty cells and etc. I suspect they are harmless but will need to look.

@jpritikin
Copy link
Author

jpritikin commented Nov 7, 2024

you have two groups, but only one parameter label "boredomM". That implicitly fixes the parameter to be equal across groups.

Fixing these parameters equal across groups is desired and intentional. I guess that warning is fine.

@ecmerkle
Copy link
Owner

Sorry for the delay on this. I found that the "number of items to replace is not a multiple of replacement length" warning happens when there is an empty middle category of an ordinal variable surrounded by observed categories (perhaps also with empty categories at a boundary). For example, a 5-category variable with category frequencies of 0, 50, 0, 50, 0. In your data, an example is the "sleep" variable in the pm group.

The fix for the the "number of items to replace is not a multiple of replacement length" warning requires a pull request to lavaan. I just made the change to my fork (ecmerkle/lavaan), and it would be helpful if you could try it out in case there are further issues. (But I understand you may be well beyond this project at this point!)

I continue to think that the warning is harmless. The other warning, about a correlation near 1, comes from lavaan when setting up the model. I think it is related to choice of starting values for maximum likelihood estimation, so it is also harmless.

@jpritikin
Copy link
Author

harmless

Glad to hear it. Thanks for following up.

I understand you may be well beyond this project at this point!

I wish. It's taking forever to collect data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants