Dyadic Data & SEM - Not Positie Definite / Model Estimation Failed

133 views
Skip to first unread message

john pappas

unread,
Nov 28, 2022, 12:36:34 PM11/28/22
to lavaan
Dear all,

I am working with dyadic data trying to predict how the gender of a buyer and a seller in a negotiation affect willingness to negotiate, by influencing creativity. In my model, I use heterosexual dyads, but it is important to know the gender of the buyer and the seller (that is why I include it as a variable). Please see my data frame below

Untitled.png

I run the following code:


Model1<-

'

#Path a

Creativity_Buyer~ a11*Gender_Buyer

Creativity_Seller~ a21*Gender_Seller

#Path b

Buyer_WtN~ b11*Creativity_Buyer + b12*Creativity_Seller

Seller_WtN~b21*Creativity_Seller + b22*Creativity_Buyer

 '

apim1 <- sem(Model1, data = Trial)

summary(apim1, fit.measures = TRUE)

 

Yet, I receive the following messages.


Warning messages:
1: In lav_samplestats_icov(COV = cov[[g]], ridge = 1e-05, x.idx = x.idx[[g]],  :
  lavaan WARNING: sample covariance matrix is not positive-definite
2: In lavaan::lavaan(model = Model1, data = Trial, model.type = "sem",  :
  lavaan WARNING:
    Model estimation FAILED! Returning starting values.

I check and the issue is with path a and I guess that probably the issue is that the gender is perfectly correlated and negatively. however, it is important in my framework, to know who is the male and the female and cannot skip it.

Do you know whether I can do something to make the covariance matrix positive definite and thus solve the problem.

Thank you in advance :)






Edward Rigdon

unread,
Nov 28, 2022, 12:53:56 PM11/28/22
to lav...@googlegroups.com
Perhaps you could sort you cases as male buyer vs female buyer and use a multi group approach, constraining some parameters to equality but letting others vary across groups. But you will have to infer some parameters estimates as differences across groups, because genders won't be in the model explicitly

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/6a5852d3-b0f1-43d0-a251-9832f6d044c9n%40googlegroups.com.

Joseph Bonito

unread,
Nov 28, 2022, 1:07:34 PM11/28/22
to lav...@googlegroups.com
Probably not with that data format.  Seems this requires a multilevel SEM, with observations nested within dyad in a long-file format—what you have here is the wide file with dyad as the unit of analysis.  See Lederman and Kenny (2017) and work that has followed.  

You’d then use gender as a moderator for your regressions at L1.  L2 would be dyadic variances and covariances, though you can include dyadic-level predictors if desired. lavaan can handle the model pretty easily.  

  


On Nov 28, 2022, at 10:53 AM, Edward Rigdon <edward...@gmail.com> wrote:

Perhaps you could sort you cases as male buyer vs female buyer and use a multi group approach, constraining some parameters to equality but letting others vary across groups. But you will have to infer some parameters estimates as differences across groups, because genders won't be in the model explicitly

On Mon, Nov 28, 2022, 12:36 PM john pappas <pappa...@gmail.com> wrote:
Dear all,

I am working with dyadic data trying to predict how the gender of a buyer and a seller in a negotiation affect willingness to negotiate, by influencing creativity. In my model, I use heterosexual dyads, but it is important to know the gender of the buyer and the seller (that is why I include it as a variable). Please see my data frame below

john pappas

unread,
Nov 29, 2022, 3:24:50 AM11/29/22
to lavaan
I would like to thank you for your suggestions. They were really helpful cause till now I thought that the two approaches (SEM and MLM) can do exactly the same thing. However, it seems that in some cases and depending on your research question, you need one of them.

Thank you so much for your help!

Yannis

Joseph Bonito

unread,
Dec 1, 2022, 12:08:31 PM12/1/22
to lav...@googlegroups.com
You are welcome.  I had some time and wanted to prove a few things to myself.  I used data from Dave Kenny’s website, the analysis of which appears near the end of Kenny et al. (2006).  Code is below.  The MSEM version has some nice advantages but a few drawbacks, too, most notably no obvious way to get residual variances for each partner’s DV.  But the regression estimates and variances are spot on as reported in Kenny et al.

pacman::p_load(tidyverse, lavaan)

#wide file ready for APIM/SEM
mixdata <- haven::read_spss("http://davidakenny.net/kkc/c7/campbell.sav")

names(mixdata)
head(mixdata)

#specify model
apim.sem <- '
mdistr ~ mneuro + fneuro
fdistr ~ fneuro + mneuro

mdistr ~ 1
fdistr ~ 1

mneuro ~~ fneuro
'

apim.sem.out <- sem(apim.sem, data=mixdata)
summary(apim.sem.out)

#convert to long file
mixdata |> 
  pivot_longer(cols = (mdistr:fneuro),
               names_to = c("gender", ".value"),
               names_pattern = "(.)(.*)") |> 
  mutate(sex0 = ifelse(gender=="m", 0, 1),
         male = ifelse(gender=="m", 1, 0),
         female = ifelse(gender=="f", 1, 0)) |>
  group_by(dyad) |> 
  mutate(pneuro = sum(neuro)-neuro) |> #get partner score on same line as actor
  ungroup() |> 
  mutate(act.neuro = sex0*neuro, part.neuro=sex0*pneuro) |> #needed interactions
  rownames_to_column("id") -> mixdata.long


head(mixdata.long)

names(mixdata.long)

apim.msem <- '

level: 1
distr ~ a*neuro + pa*pneuro + g*sex0 + ap*act.neuro + p*part.neuro

#Compute APIM estimates from regression effects
act.act := a + pa*0 + g*0 + ap*0 + p*0 #male actor effect
part.act := a*0 + pa + g*0 + ap*0 + p*0 #female-male partner effect
act.part := a*0 + pa + g*0 + ap*0 + p #male-female partner effect
part.part := a + pa*0 + g*0 + ap + p*0 #female actor effect


level: 2
#residual covariance at the between-dyad level

#intercept
distr ~ 1
'

apim.msem.out <- sem(apim.msem, cluster = "dyad", data=mixdata.long)
summary(apim.msem.out)  


Joe



J Pap

unread,
Mar 11, 2023, 12:12:47 PM3/11/23
to lavaan
Thanks a lot Joe!
Reply all
Reply to author
Forward
0 new messages