[Rsiena-help] problem loading data matrices with RSiena

Ruth M. Ripley ruth at stats.ox.ac.uk
Mon Jun 13 20:40:24 CEST 2011


Dear Sebastian,

Glad you got things to work.

I don't think these messages are important, and I thought they always 
appeared, unrelated to covariates. You are not using sparse matrices to 
improve performance at this stage: you only read in your data once and 
will spend much more time fitting models. It is more a matter of 
convenience.

Regards,

Ruth


On Mon, 13 Jun 2011, Sebastián Daza wrote:

> Thank you very much, Ruth. It works great!
>
> However, when I include a covariate (e.g. sex) I get these messages:
>
> <sparse>[ <logic> ] : .M.sub.i.logical() maybe inefficient
> <sparse>[ <logic> ] : .M.sub.i.logical() maybe inefficient
>
> Sebastian
>
> On 6/11/2011 5:41 PM, Ruth M. Ripley wrote:
>> Dear Sebastian,
>> 
>> After looking at your data, I thought I would reply to the list as
>> others may want to know the outcome:
>> 
>> I discovered there is a single 2 in the second matrix. I am not quite
>> sure of your data format but I think you have a duplicate in row 188 of
>> friend2 which results in 2 links from 1706 to 1704.
>> 
>> For the benefit of others, your data is, I think, a row for each actor
>> with 3 nominations, NA if less than three, in an SPSS file. The actor
>> numbers are not sequential.
>> 
>> I have not tried reading the files in SPSS, but if all you want in your
>> data is an integer 4 column matrix, I would think it easier to export
>> from SPSS as a text file, if that is possible.
>> 
>> I advise reading SPSS files using read.spss directly: I am not sure you
>> gain anything by using Hmisc's wrapper version, but it seemed to work OK
>> here. read.spss is in library(foreign).
>> 
>> But once you have read the files in to create two data frames friend1
>> and friend2, you could use siena edgelist format via sparse matrices or
>> create normal matrices via the sparse ones, using the following code:
>> 
>> mymat1 <- matrix(0, nrow=3*nrow(friend1), ncol=3)
>> mymat1[, 1] <- rep(1:nrow(friend1), each=3)
>> mymat1[, 2] <- match(t(as.matrix(friend1[, -1])), friend1[, 1])
>> mymat1[, 3] <- rep(1, nrow(mymat1))
>> mymat1 <- na.omit(mymat1)
>> mymat1 <- unique(mymat1)
>> 
>> mymat2 <- matrix(0, nrow=3*nrow(friend2), ncol=3)
>> mymat2[, 1] <- rep(1:nrow(friend2), each=3)
>> mymat2[, 2] <- match(t(as.matrix(friend2[, -1])), friend2[, 1])
>> mymat2[, 3] <- rep(1, nrow(mymat2))
>> mymat2 <- na.omit(mymat2)
>> mymat2 <- unique(mymat2)
>> 
>> #To get RSiena networks using sparse matrices:
>> 
>> library(Matrix)
>> mymat1s <- spMatrix(nrow(friend1), nrow(friend1),
>> mymat1[, 1], mymat1[, 2], mymat1[, 3])
>> 
>> mymat2s <- spMatrix(nrow(friend2), nrow(friend2),
>> mymat2[, 1], mymat2[, 2], mymat2[, 3])
>> 
>> mynet <- sienaNet(list(mymat1s, mymat2s))
>> 
>> # to get real matrices
>> 
>> mymat1d <- as.matrix(mymat1s)
>> mymat2d <- as.matrix(mymat
>> 
>> ## if you wish add IDs as row numbers to the matrices
>> 
>> rownames(mymat1d) <- friend1[, 1]
>> rownames(mymat2d) <- friend2[, 1]
>> rownames(mymat1s) <- friend1[, 1]
>> rownames(mymat2s) <- friend2[, 1]
>> 
>> ## and add IDs as column numbers
>> colnames(mymat1d) <- friend1[, 1]
>> colnames(mymat2d) <- friend2[, 1]
>> colnames(mymat1s) <- friend1[, 1]
>> colnames(mymat2s) <- friend2[, 1]
>> 
>> Please let me know if you do not understand the code or cannot get it to
>> work. I think it is simpler than your method, and should give the same
>> result apart from the duplicates.
>> 
>> Regards,
>> 
>> Ruth
>> --
>> On Sat, 11 Jun 2011, Ruth M. Ripley wrote:
>> 
>>> Dear Sebastian,
>>> 
>>> If you would like to email me the data in some format (either save the
>>> workspace and send that, or send me the data files and the commands
>>> you used to make the matrices) I will have a look for you.
>>> 
>>> Regards,
>>> 
>>> Ruth
>>> 
>>> 
>>> On Sat, 11 Jun 2011, Sebastián Daza wrote:
>>> 
>>>> Hello,
>>>> I am trying to load two 276x276 matrices using sienaNet, but I got
>>>> this error. Both files are matrices (matrix class), and they have
>>>> only 0s and 1s.
>>>> 
>>>>> friendship <- sienaNet( array( c( mnet1, mnet2),
>>>> + dim = c( 276, 276, 2 ) ) )
>>>> Error in sienaNet(array(c(mnet1, mnet2), dim = c(276, 276, 2))) :
>>>> entries in networks must be 0, 1, 10 or 11
>>>> 
>>>> Does anyone know what could be the problem?
>>>> Thank you in advance.
>>>> Sebastian.
>>>> 
>>>> --
>>>> Sebastián Daza
>>>> sebastian.daza at gmail.com
>>>> _______________________________________________
>>>> Rsiena-help mailing list
>>>> Rsiena-help at lists.r-forge.r-project.org
>>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rsiena-help
>>>> 
>>> 
>
> -- 
> Sebastián Daza
> sebastian.daza at gmail.com
>
>


More information about the Rsiena-help mailing list