leifeld / btergm

Temporal Exponential Random Graph Models by Bootstrapped Pseudolikelihood
16 stars 10 forks source link

GOF Several Error Messages #18

Closed Laupheim closed 4 years ago

Laupheim commented 4 years ago

Hello,

I am trying to conduct a Goodness of Fit assessment for my multiple network analysis, but the function does not work properly.

I have tried two different functions, but both of them are not functioning as intended.

g0 <- gof(M0, statistics = c(triad.directed, esp, fastgreedy.modularity,rocpr), nsim = 50)

g0 <- gof(M0)

This is the error message for gof(M0, statistics = c(triad.directed, esp, fastgreedy.modularity,rocpr), nsim = 50)

_Starting GOF assessment on a single computing core....

No 'target' network(s) provided. Using networks on the left-hand side of the model formula as observed networks.

Simulating 50 networks from the following formula: networks[[1]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[1]]))

Simulating 50 networks from the following formula: networks[[2]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[2]]))

2 networks from which simulations are drawn were provided.

Processing statistic: Triad census Skipping statistic for the following reason: Error in 0:(nrow(mat) - 2): Argument der Länge 0 Skipping statistic for the following reason: Error in [.default(el, , 3): falsche Anzahl von Dimensionen Processing statistic: Tie prediction_

And this is the error message for g0 <- gof(M0):

_Starting GOF assessment on a single computing core....

No 'target' network(s) provided. Using networks on the left-hand side of the model formula as observed networks.

Simulating 100 networks from the following formula: networks[[1]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[1]]))

Simulating 100 networks from the following formula: networks[[2]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[2]]))

2 networks from which simulations are drawn were provided.

Skipping statistic for the following reason: Error in 0:(nrow(mat) - 2): Argument der Länge 0 Skipping statistic for the following reason: Error in 0:(nrow(mat) - 2): Argument der Länge 0 Skipping statistic for the following reason: Error in degree(0:(nrow(mat) - 1)): konnte Funktion "degree" nicht finden Skipping statistic for the following reason: Error in idegree(0:(nrow(mat) - 1)): konnte Funktion "idegree" nicht finden Processing statistic: Geodesic distances Processing statistic: Tie prediction Processing statistic: Modularity (walktrap)_

When I try to plot the outcome with summary(g0) and plot(g0) you can see the outcome in the following image. It does not look right at all.

RplotErrorGOF

I do not know what I am doing wrong, but it sure does not look right to me. Moreover, sometimes I get the error message that lme4 is causing a problem and that I should de-install it. But only sometimes when I have not cleared my workspace. The above mentioned error messages are coming regardless if whether or not lme4 is loaded.

I have attached the complete R Code I am using for error replication. I have send the network and attribute data files to you via E-Mail for reasons of confidentiality.

Best regards

R Code.txt

leifeld commented 4 years ago

I have tried to look into this, but the script throws a number of errors. The data do not seem to be complete. The first error I get is this:

Error in setwd("C:/Users/User/Desktop/BA Thesis/Data-Analysis") : cannot change working directory

The second error is this:

Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'C:/Users/User/Desktop/BA Thesis/Data-Analysis/Data Management/FB1_attributes_imputed.csv': No such file or directory

Then a number of additional errors follow.

Can you provide a minimal reproducible example?

Laupheim commented 4 years ago

Hello Professor Leifeld,

thank you for trying to look into my issue. And yes, you are right. I wanted to minimize the sample as much as possible, but only gave the data for 2 out of the 3 teams that I am working with. I beg your pardon for this mistake.

I have attached a new script which I have tested myself several times. It functions as expected until the mentioned problems with the gof function come up.

Be aware that you have to change the names of the directories since the script uses my personal directory path to get the data, which is of course a different path from the one on your PC.

Script MTERGM GOF.txt

PS.: I am using R 4.0.0 in case that it matters.

leifeld commented 4 years ago

In the line g0 <- gof(M0), the following output is produced on my machine:

Starting GOF assessment on a single computing core....

No 'target' network(s) provided. Using networks on the left-hand side of the model formula as observed networks.

Simulating 100 networks from the following formula:
 networks[[1]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[1]])) 

Simulating 100 networks from the following formula:
 networks[[2]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[2]])) 

Simulating 100 networks from the following formula:
 networks[[3]] ~ edges + mutual + twopath + ctriple + nodeocov("Psychological Safety") + nodeicov("Psychological Safety") + nodeocov("Psychological Empowerment") + nodeicov("Psychological Empowerment") + offset(edgecov(offsmat[[3]])) 

3 networks from which simulations are drawn were provided.

Processing statistic: Dyad-wise shared partners
Processing statistic: Edge-wise shared partners
Processing statistic: Degree
Processing statistic: Indegree
Processing statistic: Geodesic distances
Processing statistic: Tie prediction
Processing statistic: Modularity (walktrap)

If I plot it with plot(g0), I get the following diagram, which looks right to me:

plot_zoom

I do get a single warning message in the following line:

g0 <- gof(M0, statistics = c(triad.directed, esp, fastgreedy.modularity,rocpr), nsim = 50)

The warning is:

Processing statistic: Modularity (fast & greedy)
  Skipping statistic for the following reason: Error in `[.default`(el, , 3): incorrect number of dimensions

I will look into this and get back to you. Are there any other concerns I missed?

leifeld commented 4 years ago

OK, I think I have fixed the warning mentioned above in commit d839cbb0d7fadc215000099c3e2a9ee1eb56ae89. Please install the updated version from GitHub as follows and try it out:

library("remotes")
install_github("leifeld/btergm")
Laupheim commented 4 years ago

Dear Prof. Leifeld,

I had several error messages when I tried the code earlier today, but I will try your latest fix out.

Laupheim commented 4 years ago

Ok, so I have installed and loaded your fix. It looks fine now! No error messages anymore.

Thank you so much!

RplotGoFPlot

I just have one question regarding the geodesic distance: Is it normal that it just shows 3 boxplots in comparison to the other functions with several more boxplots? It looks a bit odd.

leifeld commented 4 years ago

Maybe you were previously using the version from CRAN. I may have fixed something since the last CRAN release that may have affected your problem. Anyway, glad it works now!

Regarding geodesic distances: There are more boxplots -- in fact for all values on the x-axis up to and including 18. But shortest paths of more than three occur so infrequently in the simulations that the boxplots for these values are so narrow that they are hidden behind the black curve for the empirical distribution. If you choose not to plot the black curve, they should be visible as very narrow boxplots. Try something like plot(g0, median = FALSE, mean = FALSE).

Laupheim commented 4 years ago

Ah, very well. Thank you again for the explanation!

I wish you a good week!

Best regards