-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6000_analysis.R
108 lines (83 loc) · 3.17 KB
/
6000_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
rm(list = ls())
#################
# #
# Name #
# #
#################
# 6000 Ergms
# Mark McCann modified to loop over imputations
#############
# Purpose #
#############
# Running ergms across imp samples
##############
# #
# Notes #
# #
##############
#
#########################
# #
# Outstanding actions #
# #
#########################
#########################
# #
# Load packages #
# #
#########################
require(parallel)
library(network)
library(ergm)
library(mice)
#########################
# #
# Load functions #
# #
#########################
run.imputed.ergms <- function(dataset = NULL, savename = NULL, num_iters = NA) {
#If num_iters is specified, use that number of iterations.
# Otherwise, use the whole length of the file
leng <- ifelse(is.na(num_iters) , length(dataset), num_iters )
for (j in 1:leng) {
df1 <- dataset[[j]]
for (i in 1:6) {
df <- df1[[i]]
school.result.list[[i]] <- ergm(df ~ edges
+ mutual
+ gwesp(0.25, fixed = T)
+ nodematch("gender")
+ nodefactor("gender")
+ nodematch("sex.var", diff = T)
+ nodefactor("sex.var")
+ absdiff("know.var")
+ absdiff("att.var")
+ absdiff("conf.var")
,
directed=T,
constraints=~bd(maxout=6),
control=control.ergm(main.method=c("MCMLE"),MCMC.samplesize=2000,MCMC.interval=1024,
MCMLE.termination = "Hummel",MCMLE.last.boost = 4,
force.main=F , seed = 274,
parallel=11, parallel.type="PSOCK")
# eval.loglik = F ###This cuts computation time but doesnt update screen
)
}
imputation.list[[j]] <- school.result.list
print(j)
write.table(1, file = paste0("completed iteration",j,"so far.txt"))
save(imputation.list, file = paste0("//192.168.0.17/stash_sna/Data/AnonymisedData/working data/ergm_imp",j,"_",savename,".rdata"))
}
return(imputation.list)
}
#########################
# #
# Main body of script #
# #
#########################
#####Run these before calling the run.imputed.ergms function
imputation.list <- list()
school.result.list <- list()
baseline.imp.results <- run.imputed.ergms(dataset = ergm.data.baseline.imputed,
savename = "baseline",
num_iters = NA)