# NOT RUN {
myalgorithm <- sienaAlgorithmCreate(nsub=2, n3=100, seed=1293, projname=NULL)
# 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)
ans <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE)
# or for non-conditional estimation --------------------------------------------
# }
# NOT RUN {
model <- sienaAlgorithmCreate(nsub=2, n3=100, cond=FALSE, seed=1283)
ans <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE)
# }
# NOT RUN {
# or if a previous "on track" result ans was obtained --------------------------
# }
# NOT RUN {
ans1 <- siena07(myalgorithm, data=mydata, effects=myeff, prevAns=ans)
# }
# NOT RUN {
# Running in multiple processors -----------------------------------------------
# }
# NOT RUN {
# Not tested because dependent on presence of processors
# Find out how many processors there are
library(parallel)
(n.clus <- detectCores() - 1)
# number of cores; 1 is subtracted to keep time for other processes
ans2 <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE,
useCluster=TRUE, nbrNodes=n.clus, initC=TRUE)
# Suppose 8 processors are going to be used.
# Loading the parallel package and creating a cluster
# with 8 processors (this should be equivalent)
library(parallel)
cl <- makeCluster(n.clus)
ans3 <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE, cl = cl)
# Notice that now -siena07- perhaps won't stop the cluster for you.
# stopCluster(cl)
# You can create even more complex clusters using several computers. In this
# example we are creating a cluster with 3*8 = 24 processors on three
# different machines.
cl <- makePSOCKcluster(
rep(c('localhost', 'machine2.website.com' , 'machine3.website.com'), 8),
user='myusername', rshcmd='ssh -p PORTNUMBER')
ans4 <- siena07(myalgorithm, data=mydata, effects=myeff, batch=TRUE, cl = cl)
stopCluster(cl)
# }
# NOT RUN {
# Accessing simulated networks for ML ------------------------------------------
# The following is an example for accessing the simulated networks for ML,
# which makes sense only if there are some missing tie variables;
# observed tie variables are identically simulated
# at the moment of observation,
# missing tie variable are imputed in a model-based way.
mat1 <- matrix(c(0,0,1,1,
1,0,0,0,
0,0,0,1,
0,1,0,0),4,4, byrow=TRUE)
mat2 <- matrix(c(0,1,1,1,
1,0,0,0,
0,0,0,1,
0,0,1,0),4,4, byrow=TRUE)
mat3 <- matrix(c(0,1,0,1,
1,0,0,0,
0,0,0,0,
NA,1,1,0),4,4, byrow=TRUE)
mats <- array(c(mat1,mat2,mat3), dim=c(4,4,3))
net <- sienaDependent(mats, allowOnly=FALSE)
sdat <- sienaDataCreate(net)
alg <- sienaAlgorithmCreate(maxlike=TRUE, nsub=3, n3=100, seed=12534, projname=NULL)
effs <- getEffects(sdat)
(ans <- siena07(alg, data=sdat, effects=effs, returnDeps=TRUE, batch=TRUE))
# See manual Section 9.1 for information about the following functions
edges.to.adj <- function(x,n){
# create empty adjacency matrix
adj <- matrix(0, n, n)
# put edge values in desired places
adj[x[, 1:2]] <- x[, 3]
adj
}
the.edge <- function(x,n,h,k){
edges.to.adj(x,n)[h,k]
}
# Now show the results
n <- 4
ego <- rep.int(1:n,n)
alter <- rep(1:n, each=n)
ones <- sapply(1:n^2, function(i)
{mean(sapply(ans$sims,
function(x){the.edge(x[[1]][[2]][[1]],n,ego[i],alter[i])}))})
cbind(ego,alter,ones)
matrix(ones,n,n)
# }
Run the code above in your browser using DataLab