statnet / ergm

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

Some of the goodness of fit plots fail for directed networks. #493

Closed jrisi256 closed 1 year ago

jrisi256 commented 1 year ago

So for undirected graphs, plotting gof works fine. This example is taken directly from the help pages.

data(florentine)
gest <- ergm(flomarriage ~ edges + kstar(2))
gofflo <- gof(gest)
plot(gofflo)

However for directed graphs, not all of the plots get plotted.

data(emon)
gest <- ergm(emon[[1]] ~ edges + ostar(2))
gofemon <- gof(gest)
plot(gofemon)

Specifically the geodesic distances (distance) and shared partner distributions (espartners) do not graph as I get the error: Error in out[, na.omit(i), drop = FALSE] : subscript out of bounds.

From R Session Info:

R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] ergm_4.2.3         network_1.18.0     ina_0.0.12         RColorBrewer_1.1-3

loaded via a namespace (and not attached):
 [1] lpSolveAPI_5.5.2.0-17.8 rstudioapi_0.14         knitr_1.40              magrittr_2.0.3         
 [5] MASS_7.3-53.1           lattice_0.20-41         rlang_1.0.6             fastmap_1.1.0          
 [9] fansi_1.0.3             tools_4.0.0             parallel_4.0.0          grid_4.0.0             
[13] rle_0.9.2               xfun_0.33               utf8_1.2.2              cli_3.4.1              
[17] coda_0.19-4             tibble_3.1.8            lifecycle_1.0.3         Matrix_1.3-2           
[21] purrr_0.3.5             vctrs_0.4.2             trust_0.1-8             robustbase_0.95-0      
[25] memoise_2.0.1           glue_1.6.2              cachem_1.0.6            statnet.common_4.7.0   
[29] DEoptimR_1.0-11         compiler_4.0.0          pillar_1.8.1            renv_0.15.5            
[33] pkgconfig_2.0.3  
mbojan commented 1 year ago

Thank you @jrisi256 . Looks like a bug in CRAN and master versions of the package.

mbojan commented 1 year ago

Interestingly when computed individually distance works while espartners fails (and in both cases model is included even though it should not, but that's something separate):

gof(gest, GOF = ~ espartners - model) |>
  plot()
## Error in out[, na.omit(i), drop = FALSE] : subscript out of bounds

gof(gest, GOF = ~ distance - model) |>
  plot()

@jrisi256 until we fix it you can produce the gofplot for distances as in the above.

mbojan commented 1 year ago

Given

gof(gest, GOF = ~ espartners - model) |>
  plot()
## Error in out[, na.omit(i), drop = FALSE] : subscript out of bounds

It seems that i computed at

https://github.com/statnet/ergm/blob/033dd693abd7c93d38daa938eea369fa645b83bb/R/gof.ergm.R#L502-L512

is too long (here 1:14) for the actual dimension of out being subscripted (here it is 100 x 13). The logic behind computing i is obscure to me. Is this your design @krivit ?

krivit commented 1 year ago

Is this your design @krivit ?

"Design" isn't the right word. gof() used to be a mess with a lot of repetition, which I eventually turned into a mess with less repetition.

krivit commented 1 year ago

This problem turns out to have been affecting not so much directed networks as any networks dense enough to have maximum observed ESP close to the size.

jrisi256 commented 1 year ago

Do you know when this will be pushed to CRAN?

krivit commented 1 year ago

Do you know when this will be pushed to CRAN?

Already has been. It's up to CRAN now.