# NOT RUN {
#generating a simple network corresponding to the simple Sum of squares
#structural equivalence with blockmodel:
# null com
# null null
n<-20
net<-matrix(NA,ncol=n,nrow=n)
clu<-rep(1:2,times=c(5,15))
tclu<-table(clu)
net[clu==1,clu==1]<-rnorm(n=tclu[1]*tclu[1],mean=0,sd=1)
net[clu==1,clu==2]<-rnorm(n=tclu[1]*tclu[2],mean=4,sd=1)
net[clu==2,clu==1]<-rnorm(n=tclu[2]*tclu[1],mean=0,sd=1)
net[clu==2,clu==2]<-rnorm(n=tclu[2]*tclu[2],mean=0,sd=1)
#computation of criterion function with the correct partition
res<-crit.fun(M=net,clu=clu,approach="ss",blocks="com")
res$err #the error is relativly small
res$BM #The block means are around 0 or 4
plot(res)
#computation of criterion function with the correct partition and correct pre-specified blockmodel
#prespecified blockmodel used
# null com
# null null
B<-array(NA,dim=c(1,2,2))
B[1,,]<-"null"
B[1,1,2]<-"com"
B[1,,]
res<-crit.fun(M=net,clu=clu,approach="ss",BLOCKS=B)
res$err #the error is relativly small
res$IM
plot(res)
#computation of criterion function with the correct partition and
# pre-specified blockmodel with some alternatives
#prespecified blockmodel used
# null null|com
# null null
B<-array(NA,dim=c(2,2,2))
B[1,,]<-"null"
B[2,1,2]<-"com"
res<-crit.fun(M=net,clu=clu,approach="ss",BLOCKS=B)
res$err #the error is relativly small
res$IM
plot(res)
#computation of criterion function with random partition
clu.rnd<-sample(1:2,size=n,replace=TRUE)
res.rnd<-crit.fun(M=net,clu=clu.rnd,approach="ss",blocks="com")
res.rnd$err #the error is larger
res.rnd$BM #random block means
plot(res.rnd)
#adapt network for Valued blockmodeling with the same model
net[net>4]<-4
net[net<0]<-0
#computation of criterion function with the correct partition
res<-crit.fun(M=net,clu=clu,approach="val",
blocks=c("null","com"),m=4)
res$err #the error is relativly small
res$IM
#The image corresponds to the one used for generation of
#the network
plot(res)
#computation of criterion function with random partition
res.rnd<-crit.fun(M=net,clu=clu.rnd,approach="val",
blocks=c("null","com")
, m=4)
res.rnd$err #the error is larger
res.rnd$IM #all blocks are probably null
plot(res.rnd)
# }
Run the code above in your browser using DataLab