ndtv icon indicating copy to clipboard operation
ndtv copied to clipboard

test ndtv with output from RSiena

Open skyebend opened this issue 8 years ago • 1 comments

(migrated from statnet trac ticket #679) would be really cool to be able to have this working with another package

2 years ago

Corresponded with Christian about this, code below seems to work, hopefully he can recommend another model to visualize.

# example testing creating a movie using RSiena
library(RSiena)
library(ndtv)

# using example from siena07 man page
# need to set Maximum Likelihood to get chain estimation
myalgorithm <- sienaAlgorithmCreate(nsub=2, n3=10,maxlike=TRUE)
# nsub=2 and n3=100 is used here for having a brief computation, not for practice.
mynet1 <- sienaDependent(array(c(tmp3, tmp4), dim=c(32, 32, 2)))
mydata <- sienaDataCreate(mynet1)
myeff <- getEffects(mydata)
# set to return simulation chains as dataframe
sim_ans <- siena07( myalgorithm, data = mydata, 
                    effects = myeff,  
                    returnChains=TRUE,
                    returnDataFrame=TRUE,
                    batch=TRUE )

# convert it to a list of network objects
netList<-lapply(sim_ans$chain,function(sim){
   edgelist<-cbind(sim[[1]][[1]]$Ego,sim[[1]][[1]]$Alter)+1
   as.network.matrix(edgelist,matrix.type='edgelist',loops=TRUE)
  })
# convert the list of network objects to a networkDynamic object
myDynamicNet<-networkDynamic(network.list=netList)
render.animation(myDynamicNet)

skyebend avatar Apr 21 '16 21:04 skyebend

I also wrote some draft code for converting RSiena network objects to network dynamic and back, need to follow up on that...

skyebend avatar Apr 21 '16 21:04 skyebend