stocnet / rsiena

An R package for Simulation Investigation for Empirical Network Analysis
http://www.stats.ox.ac.uk/~snijders/siena/
GNU General Public License v3.0
101 stars 25 forks source link

sienaDependent() from sparse matrices not accepted as valid object without covariate in sienaDataCreate() #86

Closed Kaladani closed 9 months ago

Kaladani commented 9 months ago

Describe the bug An object created by sienaDependent from a list of sparse matrices is not accepted as a valid object in sienaDataCreate

To Reproduce Sébastien described how to reproduce the error on groups.io in https://groups.io/g/RSiena/message/945

I tried running the lines proposed as example in the doc (https://search.r-project.org/CRAN/refmans/RSiena/html/sienaDependent.html): sp501 <- as(Matrix(s501), "TsparseMatrix") sp502 <- as(Matrix(s502), "TsparseMatrix") sp503 <- as(Matrix(s503), "TsparseMatrix") mymatlist <- list(sp501, sp502, sp503) mynet.sp <- sienaDependent(mymatlist) and then creating a sienaData object: data.sp <- sienaDataCreate(mynet.sp) but it gives me the same error as I had with my own data: Error : invalid object in sienaDataCreate: argument number 1 is of class dgTMatrix , which is not a valid ... argument. However, when I integrate some coCovar object in the sienaDataCreate function, it runs without problem: smoke <- s50s smoke1 <- coCovar(smoke[ , 1 ]) data.spbis <- sienaDataCreate(mynet.sp, smoke1) returns no error.

I could solve Sébastien's issue temporarily by supplying sienaDependent via list(): data.sp <- sienaDataCreate(list(mynet.sp))

Using this circumvents the error, which might happen due to some interaction of sparse matrices with the substitution for an object with one argument in sienaDataCreate():

dots <- as.list(substitute(list(...)))[-1]
if (length(dots) == 1) {
        ldots <- list(...)
        dotsIsList <- (is.list(ldots[[1]]))
        if (dotsIsList) {
            dots <- as.list(substitute(...))[-1]
            narg <- length(ldots)
        } 

Expected behavior sienaDependent() and sienaDataCreate() should work with a list of sparse matrices without a covariate.

Desktop (please complete the following information):

Kaladani commented 9 months ago

There's another issue with sparse matrices with just one tie in the first observed network described on groups.io Sébastien encountered and is due to some edge case behavior for sparse matrices with just one tie: https://groups.io/g/RSiena/message/946

Should I create a seperate issue for that or include it in this bug report?

Best Regards,

Daniel

TomSnijders commented 9 months ago

I have been working on both problems and hope to have corrected them in the next version. No need to open a new issue.