?write.csv
write.csv(res_complete, "res_complete.csv")
repnum=100
sim<-c(1:4)
rep<-c(1:repnum)
ssize<-c(50, 100)
cond <-list(
ssize=ssize, sim=sim, rep=rep
)
allcond <- expand.grid(cond)
sum(res_complete$sim==allcond$sim)
sum(res_complete$ssize==allcond$ssize)
sum(res_complete$rep==allcond$rep)
res<-read.csv("res_complete.csv")
library(dplyr)
res %>%  group_by(sim, ssize) %>% summarize(edges=mean(c_edges), gwesp=mean(c_gwesp),"mutual"=mean(c_mutual), "nodematchB"=mean(c_nodematchB), "nodematchC"=mean(c_nodematchC), "nodecovA"=mean(c_nodecovA), "nodefactorB"=mean(c_noefactorB2), "nodecovC"=mean(c_nodecovC)) %>% View()
res %>%  group_by(sim, ssize) %>% summarize(density=mean(density), triangle=mean(triangle), gwesp=mean(gwesp),"reciprocity"=mean(reciprocity), "homophilyA"=mean(homophilyA), "homophilyB"=mean(homophilyB), "homophilyC"=mean(homophilyC))
library(dplur)
library(dplyr)
library(dplyr)
res_complete %>%  group_by(sim, ssize) %>% summarize(edges=mean(c_edges), gwesp=mean(c_gwesp),"mutual"=mean(c_mutual), "nodematchB"=mean(c_nodematchB), "nodematchC"=mean(c_nodematchC), "nodecovA"=mean(c_nodecovA), "nodefactorB"=mean(c_nodefactorB2), "nodecovC"=mean(c_nodecovC)) %>% View()
library(dplyr)
load("/Volumes/GoogleDrive/My Drive/isure project/code1/data/res_complete.RData")
load("/Volumes/GoogleDrive/My Drive/isure project/code1/data/res_complete.RData")
library(dplyr)
res_complete %>%  group_by(sim, ssize) %>% summarize(density=mean(density), triangle=mean(triangle), gwesp=mean(gwesp),"reciprocity"=mean(reciprocity), homophilyA=mean(homophilyA), "homophilyB"=mean(homophilyB), "homophilyC"=mean(homophilyC), "triangles"=mean(triangle), "transitivity"=mean(transitivity))
head(res_complete)
load("data/imputed_bergm1.RData")
repnum=100
sim<-c(1:4)
rep<-c(1:repnum)
mech<-c("mcar", "mar", "mnar1", "mnar2")
prop<-c(0.1, 0.2, 0.3)
tp<-c("actor","cell","mix")
ssize<-c(50, 100)
imp_method<-c("bergm1")
imp_num<-c("avg")
cond <-list(
ssize=ssize, sim=sim, rep=rep, mech=mech, prop=prop, tp=tp, imp_method=imp_method, imp_num=imp_num
)
allcond <- expand.grid(cond)
load("/Volumes/GoogleDrive/My Drive/isure project/code1/data/imputed_bergm1.RData")
load("/Volumes/GoogleDrive/My Drive/isure project/code1/data/nlist.RData")
samen<-0
for (i in 1:nrow(allcond)){
tmp<-allcond[i,]
sim<-tmp$sim
mech<-tmp$mech
prop<-as.numeric(tmp$prop)
tp<-tmp$tp
ssize<-as.numeric(tmp$ssize)
rep<-tmp$rep
imp_method<-tmp$imp_method
imp_num<-tmp$imp_num
propname<-ifelse(prop==0.1, "l", ifelse(prop==0.2, "m", "h"))
mname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp)
impname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp, "_method_", imp_method, "_num_", imp_num)
nname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize)
nnet<-nlist[[nname]]
mnet<-mlist[[mname]]
imputed<-imputed_bergm1[[impname]]
if (sum(imputed==mnet$adj_matrix)==nrow(imputed)^2){
samen=samen+1
}
}
load("data/mlist.RData")
load("/Volumes/GoogleDrive/My Drive/isure project/code1/data/mlist.RData")
for (i in 1:nrow(allcond)){
tmp<-allcond[i,]
sim<-tmp$sim
mech<-tmp$mech
prop<-as.numeric(tmp$prop)
tp<-tmp$tp
ssize<-as.numeric(tmp$ssize)
rep<-tmp$rep
imp_method<-tmp$imp_method
imp_num<-tmp$imp_num
propname<-ifelse(prop==0.1, "l", ifelse(prop==0.2, "m", "h"))
mname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp)
impname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp, "_method_", imp_method, "_num_", imp_num)
nname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize)
nnet<-nlist[[nname]]
mnet<-mlist[[mname]]
imputed<-imputed_bergm1[[impname]]
if (sum(imputed==mnet$adj_matrix)==nrow(imputed)^2){
samen=samen+1
}
}
mnet
sum(imputed==mnet$adj_matrix)
mnet$adj_matrix
imputed
mnet$adj_matrix)
mnet$adj_matrix
for (i in 1:nrow(allcond)){
tmp<-allcond[i,]
sim<-tmp$sim
mech<-tmp$mech
prop<-as.numeric(tmp$prop)
tp<-tmp$tp
ssize<-as.numeric(tmp$ssize)
rep<-tmp$rep
imp_method<-tmp$imp_method
imp_num<-tmp$imp_num
propname<-ifelse(prop==0.1, "l", ifelse(prop==0.2, "m", "h"))
mname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp)
impname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp, "_method_", imp_method, "_num_", imp_num)
nname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize)
nnet<-nlist[[nname]]
mnet<-mlist[[mname]]
imputed<-imputed_bergm1[[impname]]
if (sum(imputed==mnet$adj_matrix, na.rm=T)==nrow(imputed)^2){
samen=samen+1
}
}
samen
imputed_bergm1
imputed_bergm1[[1]]
for (i in 1:nrow(allcond)){
tmp<-allcond[i,]
sim<-tmp$sim
mech<-tmp$mech
prop<-as.numeric(tmp$prop)
tp<-tmp$tp
ssize<-as.numeric(tmp$ssize)
rep<-tmp$rep
imp_method<-tmp$imp_method
imp_num<-tmp$imp_num
propname<-ifelse(prop==0.1, "l", ifelse(prop==0.2, "m", "h"))
mname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp)
impname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize, "_mech_", mech, "_prop_", propname, "_tp_", tp, "_method_", imp_method, "_num_", imp_num)
nname<-paste0("sim_", sim, "_rep_", rep, "_size_", ssize)
nnet<-nlist[[nname]]
mnet<-mlist[[mname]]
imputed<-imputed_bergm1[[impname]]
if (sum(imputed==mnet$adj_matrix, na.rm=T)!=nrow(imputed)^2){
samen=samen+1
}
}
samen
na_count <-lapply(imputed_bergm1, function(y) sum(length(which(is.na(y)))))
na_count
na_count[[na_count>0]]
na_count[na_count>0]
sum(na_count>0)
netdata=mlist[[1]]$adj_matrix
va=mlist[[1]]$va
vb=mlist[[1]]$vb
vc=mlist[[1]]$vc
net <- as.network(netdata)
set.vertex.attribute(net, "va", va)
set.vertex.attribute(net, "vb", vb)
set.vertex.attribute(net, "vc", vc)
imp<-NULL
impnets<-list()
if (length(imp$impNets)<n){
for (x in 1:n){
impnets[[x]]<-netdata
}
}else{
impnets <- lapply(imp$impNets, as.matrix)
}
library(R.utils)
library(reshape2)
library(mice)
library(igraph)
library(class)
library(randomForest)
library(statnet)
library(Bergm)
net <- as.network(netdata)
set.vertex.attribute(net, "va", va)
set.vertex.attribute(net, "vb", vb)
set.vertex.attribute(net, "vc", vc)
imp<-NULL
impnets<-list()
n=5
if (length(imp$impNets)<n){
for (x in 1:n){
impnets[[x]]<-netdata
}
}else{
impnets <- lapply(imp$impNets, as.matrix)
}
impnets
withTimeout(
{tryCatch({
imp <- bergmM(net ~ edges + mutual+ nodecov("va") + nodematch("vb"),
burn.in = 1000,
aux.iters = 2000,
main.iters = 3000,
gamma = 0.5,
prior.sigmas = diag(4, 4),
nImp = n)
},error = function(e){NULL})},
timeout = 3600,
onTimeout = "silent")
imp
impnets<-list()
if (length(imp$impNets)<n){
for (x in 1:n){
impnets[[x]]<-netdata
}
}else{
impnets <- lapply(imp$impNets, as.matrix)
}
length(imo$impnets)
length(imp$impnets)
length(imp$impNets)
sum(is.na(imputed_bergm1[[1]]))
a<-rep(NA, 28800)
for (i in 1:length(imputed_bergm1)){
a[i]=sum(is.na(imputed_bergm1[[i]]))
}
a[a>0]
a
View(imputed_bergm[[300]])
View(imputed_bergm1[[300]])
names(imputed_bergm1)[28800]
