statnet / ergm

Fit, Simulate and Diagnose Exponential-Family Models for Networks
Other
94 stars 36 forks source link

model collapse while using "statnet" to fit "ergm" model #519

Closed cbccbcc closed 1 year ago

cbccbcc commented 1 year ago

I was using statnet in R to fit ergm model, specifically the dependent model and when I coded like: gw1_sup <- ergm(supnet ~ edges + nodefactor("edu") + nodefactor("income") + nodefactor("work") + nodefactor("religious") + nodefactor("gender") + nodecov("age") + edgecov(kin_sup,"kinweight") + gwidegree(.1, T) + gwesp(.1, T) + gwdsp(.1, T), control = control.ergm(MCMC.samplesize = 1e+5, MCMC.burnin = 1e+6, MCMC.interval = 1000, seed = 567), eval.loglik = T, verbose = T) everything is okay.

But when I turned the "edu" and "income" to continuous variables and code like: gw1_sup <- ergm(supnet ~ edges + nodefactor("work") + nodefactor("religious") + nodefactor("gender") + +nodecov("edu") + nodecov("income") + nodecov("age") + edgecov(kin_sup,"kinweight") + gwidegree(.1, T) + gwesp(.1, T) + gwdsp(.1, T), control = control.ergm(MCMC.samplesize = 1e+5, MCMC.burnin = 1e+6, MCMC.interval = 1000, seed = 567), eval.loglik = T, verbose = T) ) At first, it went okay but at around 8/9 iteration the ergm collapsed and report the error: "Error in T2nullity && verbose : invalid 'x' type in 'x && y'", I don't know why but I cannot delete the variables since they are important, right now my only solution is to go back to the old way of treating them as categorical variables.

mbojan commented 1 year ago

Thanks @cbccbcc. It may be data-related. Have you checked (joint) distribution of edu and income? We can have a look, but you'd need to share the supnet data so that we can run the code ourselves.

cbccbcc commented 1 year ago

Thanks @cbccbcc. It may be data-related. Have you checked (joint) distribution of edu and income? We can have a look, but you'd need to share the supnet data so that we can run the code ourselves.↳

Thanks! I'm not quite clear on what you mean by (joint distribution). Does it mean that I need to add the interact variables?

mbojan commented 1 year ago

No, I meant checking if they are perhaps strongly correlated.

krivit commented 1 year ago

It does look like it might be a bug, since even if it errs, it should produce a more informative error message than that. Can you please provide a reproducible example?

cbccbcc commented 1 year ago

It does look like it might be a bug, since even if it errs, it should produce a more informative error message than that. Can you please provide a reproducible example?↳ 截屏2023-03-08 10 04 29

I screenshot my console of the error iteration here, and I can confirm that everytime it went wrong at the ninth iteration

cbccbcc commented 1 year ago

No, I meant checking if they are perhaps strongly correlated.↳

I have run Pearson's Correlation test and the outcome seemed to be not strongly correlated. 截屏2023-03-08 10 09 03

mbojan commented 1 year ago

I have run Pearson's Correlation test and the outcome seemed to be not strongly correlated

Thanks @cbccbcc . Indeed. I guess the problem lies elsewhere. As @krivit wrote, we'd need a reprex to debug this efficiently further.

cbccbcc commented 1 year ago

I have run Pearson's Correlation test and the outcome seemed to be not strongly correlated

Thanks @cbccbcc . Indeed. I guess the problem lies elsewhere. As @krivit wrote, we'd need a reprex to debug this efficiently further.

Thanks! I have already sent my data to Professor Krivitsky by email since the data is under protection, I don't know if it's necessary to send you my data too. If so, could you please give me our email? Thanks a lot:)