-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
531 lines (531 loc) · 24.1 KB
/
.Rhistory
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
show(GroupAJackknifed)
library(netjack)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
library(netjack)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
Sub1JackknifedGlobEff <- net_stat_apply(Sub1Jackknifed, net.stat.fun = global_efficiency)
show(Sub1JackknifedGlobEff)
GroupAJackknifedGlobEff <- net_stat_apply(GroupAJackknifed, net.stat.fun = global_efficiency)
show(GroupAJackknifedGlobEff)
library(netjack)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
Sub1JackknifedGlobEff <- net_stat_apply(Sub1Jackknifed, net.stat.fun = global_efficiency)
show(Sub1JackknifedGlobEff)
GroupAJackknifedGlobEff <- net_stat_apply(GroupAJackknifed, net.stat.fun = global_efficiency)
show(GroupAJackknifedGlobEff)
Sub1Data = to_data_frame(Sub1JackknifedGlobEff)
head(Sub1Data)
GroupAData = to_data_frame(GroupAJackknifedGlobEff)
head(GroupAData)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20))
GroupAJackknifed = net_apply(GroupASamp, net.function = "node_jackknife")
GroupAJackknifedGlobEff = net_stat_apply(GroupASamp, net.stat.fun = "global_efficiency")
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20))
GroupAJackknifed = net_apply(GroupASamp, net.function = "node_jackknife")
GroupAJackknifedGlobEff = net_stat_apply(GroupAJackknifed, net.stat.fun = "global_efficiency")
diff_test(GroupAJackknifedGlobEff)
net_ggPlot(GroupAJackknifedGlobEff)
as_data_frame(GroupAJackknifedGlobEff)
to_data_frame(GroupAJackknifedGlobEff)
fullGroup = c(GroupA, GroupB)
fullSamp = as_NetSample(fullGroup, sample.variables = list(group = c(rep("GroupA", 20), rep("GroupB", 20))))
fullSamp = as_NetSample(fullGroup,net.names = 1:40, sample.variables = list(group = c(rep("GroupA", 20), rep("GroupB", 20))))
fullSamp = as_NetSample(fullGroup,net.names = as.character(1:40), sample.variables = list(group = c(rep("GroupA", 20), rep("GroupB", 20))))
fullSampJackknifed = net_apply(fullSamp, net.function = "node_jackknife")
fullSampleJackknifedGlobEff = net_stat_apply(fullSampJackknifed, net.stat.fun = "global_efficiency")
group_test(fullSampleJackknifedGlobEff)
group_test(fullSampleJackknifedGlobEff, grouping.variable = "group")
to_data_frame(fullSampleJackknifedGlobEff)
grouping.variable = "group"
form = paste0("nets.stat", "~", grouping.variable)
form
form = stats::as.formula(form)
group_test(fullSampleJackknifedGlobEff, grouping.variable = "group")
group_test(fullSampleJackknifedGlobEff, grouping.variable = "group",non.parametric = F)
library(netjack)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
Sub1JackknifedGlobEff <- net_stat_apply(Sub1Jackknifed, net.stat.fun = global_efficiency)
show(Sub1JackknifedGlobEff)
GroupAJackknifedGlobEff <- net_stat_apply(GroupAJackknifed, net.stat.fun = global_efficiency)
show(GroupAJackknifedGlobEff)
Sub1Data = to_data_frame(Sub1JackknifedGlobEff)
names(Sub1Data)
GroupAData = to_data_frame(GroupAJackknifedGlobEff)
head(GroupAData)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20))
GroupAJackknifed = net_apply(GroupASamp, net.function = "node_jackknife")
GroupAJackknifedGlobEff = net_stat_apply(GroupAJackknifed, net.stat.fun = "global_efficiency")
diff_test(GroupAJackknifedGlobEff)
net_ggPlot(GroupAJackknifedGlobEff)
fullGroup = c(GroupA, GroupB)
fullSamp = as_NetSample(fullGroup,net.names = as.character(1:40), sample.variables = list(group = c(rep("GroupA", 20), rep("GroupB", 20))))
fullSampJackknifed = net_apply(fullSamp, net.function = "node_jackknife")
fullSampleJackknifedGlobEff = net_stat_apply(fullSampJackknifed, net.stat.fun = "global_efficiency")
group_test(fullSampleJackknifedGlobEff, grouping.variable = "group",non.parametric = F)
netGroup_ggPlot(fullSampleJackknifedGlobEff, grouping.variable="group")
library(netjack)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
Sub1JackknifedGlobEff <- net_stat_apply(Sub1Jackknifed, net.stat.fun = global_efficiency)
show(Sub1JackknifedGlobEff)
GroupAJackknifedGlobEff <- net_stat_apply(GroupAJackknifed, net.stat.fun = global_efficiency)
show(GroupAJackknifedGlobEff)
Sub1Data = to_data_frame(Sub1JackknifedGlobEff)
names(Sub1Data)
GroupAData = to_data_frame(GroupAJackknifedGlobEff)
head(GroupAData)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20))
GroupAJackknifed = net_apply(GroupASamp, net.function = "node_jackknife")
GroupAJackknifedGlobEff = net_stat_apply(GroupAJackknifed, net.stat.fun = "global_efficiency")
diff_test(GroupAJackknifedGlobEff)
net_ggPlot(GroupAJackknifedGlobEff)
net_ggPlot(GroupAJackknifedGlobEff)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
Sub1JackknifedGlobEff <- net_stat_apply(Sub1Jackknifed, net.stat.fun = global_efficiency)
show(Sub1JackknifedGlobEff)
GroupAJackknifedGlobEff <- net_stat_apply(GroupAJackknifed, net.stat.fun = global_efficiency)
show(GroupAJackknifedGlobEff)
Sub1Data = to_data_frame(Sub1JackknifedGlobEff)
names(Sub1Data)
GroupAData = to_data_frame(GroupAJackknifedGlobEff)
head(GroupAData)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20))
GroupAJackknifed = net_apply(GroupASamp, net.function = "node_jackknife")
GroupAJackknifedGlobEff = net_stat_apply(GroupAJackknifed, net.stat.fun = "global_efficiency")
diff_test(GroupAJackknifedGlobEff)
net_ggPlot(GroupAJackknifedGlobEff)
library(netjack)
data("GroupA")
Subject1 <- as_Net(GroupA[[i]], "Subject1")
show(Subject1)
Subject2 <- as_Net(GroupA[[2]], "Subject1", node.variables = list(community = c(rep(1,10), rep(2,10))))
show(Subject2)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20) , node.variables = list(community = c(rep(1,10), rep(2,10))), sample.variables = list(group = rep(1, 20)))
show(GroupASamp)
Sub1Jackknifed <- net_apply(network = Subject1, net.function = "node_jackknife")
show(Sub1Jackknifed)
GroupAJackknifed <- net_apply(network = GroupASamp, net.function = "node_jackknife")
show(GroupAJackknifed)
GroupANetJackknifed <- net_apply(GroupASamp, net.function = "network_jackknife", net.function.args = list(network.variable = "community"))
show(GroupANetJackknifed)
Sub1JackknifedGlobEff <- net_stat_apply(Sub1Jackknifed, net.stat.fun = global_efficiency)
show(Sub1JackknifedGlobEff)
GroupAJackknifedGlobEff <- net_stat_apply(GroupAJackknifed, net.stat.fun = global_efficiency)
show(GroupAJackknifedGlobEff)
Sub1Data = to_data_frame(Sub1JackknifedGlobEff)
names(Sub1Data)
GroupAData = to_data_frame(GroupAJackknifedGlobEff)
head(GroupAData)
GroupASamp = as_NetSample(GroupA, net.names = as.character(1:20))
GroupAJackknifed = net_apply(GroupASamp, net.function = "node_jackknife")
GroupAJackknifedGlobEff = net_stat_apply(GroupAJackknifed, net.stat.fun = "global_efficiency")
diff_test(GroupAJackknifedGlobEff)
net_ggPlot(GroupAJackknifedGlobEff)
fullGroup = c(GroupA, GroupB)
fullSamp = as_NetSample(fullGroup,net.names = as.character(1:40), sample.variables = list(group = c(rep("GroupA", 20), rep("GroupB", 20))))
fullSampJackknifed = net_apply(fullSamp, net.function = "node_jackknife")
fullSampleJackknifedGlobEff = net_stat_apply(fullSampJackknifed, net.stat.fun = "global_efficiency")
group_test(fullSampleJackknifedGlobEff, grouping.variable = "group")
netGroup_ggPlot(fullSampleJackknifedGlobEff, grouping.variable="group")
plot(1:10)
plot(10:1)
knitr::kable(head(mtcars, 10))
group_diff_test(fullSampleJackknifedGlobEff, grouping.variable = "group")
netGroupDiff_ggPlot(fullSampleJackknifedGlobEff, grouping.variable="group")
library(netjack)
devtools::build()
devtools::use_vignette("my-vignette")
rmarkdown::html_vignette
library(netjack)
library(netjack)
library(netjack)
nNets = 1:26
combn(nNets, 2)
t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
combn(1:nNets, 2)
nNets = 26
combn(1:nNets, 2)
combn(nNets:1, 2)
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
View(index)
index = rbind(index,cbind(1:nNets, 1:nNets))
26^2
?mapply
setGeneric("pairwise_net_stat_apply", function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE) {
standardGeneric("pairwise_net_stat_apply")
})
#' @describeIn pairwise_net_stat_apply net_stat_apply for NetSample
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "logical", self.comp = "logical"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric, self.comp){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(net.stat.fun = net.stat.fun, net.stat.fun.args = net.stat.fun.args))
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(pairwise.vector)
})
edit_dist <- function(Net1, Net2){
nNodes = dim(Net1@net)[[1]]
editDist = abs(Net1@net - Net2@net)/(((nNodes-1)*nNodes)/2)
return(editDist)
}
library(netjack)
<<<<<<< HEAD
data("GroupA")
testSet = as_NetSample(GroupA, net.names = 1:20)
pairwise_fun_wrapper <- function(index1, index2, nets, net.stat.fun, net.stat.fun.args ){
return(do.call(net.stat.fun, args = c(list(nets[index1], nets[index2]), net.stat.fun.args)))
}
testPair = pairwise_net_stat_apply(testSet, edit_dist)
setGeneric("pairwise_net_stat_apply", function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE) {
standardGeneric("pairwise_net_stat_apply")
})
#' @describeIn pairwise_net_stat_apply net_stat_apply for NetSample
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "logical", self.comp = "logical"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(net.stat.fun = net.stat.fun, net.stat.fun.args = net.stat.fun.args))
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(pairwise.vector)
})
testPair = pairwise_net_stat_apply(testSet, edit_dist)
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "ANY", self.comp = "ANY"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(net.stat.fun = net.stat.fun, net.stat.fun.args = net.stat.fun.args))
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(pairwise.vector)
})
testPair = pairwise_net_stat_apply(testSet, edit_dist)
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "ANY", self.comp = "ANY"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(nets = NetSet@nets, net.stat.fun = net.stat.fun, net.stat.fun.args = net.stat.fun.args))
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(pairwise.vector)
})
testPair = pairwise_net_stat_apply(testSet, edit_dist)
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "ANY", self.comp = "ANY"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(nets = netSet@nets, net.stat.fun = net.stat.fun, net.stat.fun.args = net.stat.fun.args))
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(pairwise.vector)
})
testPair = pairwise_net_stat_apply(testSet, edit_dist)
pairwise_fun_wrapper <- function(index1, index2, nets, net.stat.fun, net.stat.fun.args ){
return(do.call(net.stat.fun, args = c(list(nets[[index1]], nets[[index2]]), net.stat.fun.args)))
}
testPair = pairwise_net_stat_apply(testSet, edit_dist)
edit_dist <- function(Net1, Net2){
nNodes = dim(Net1@net)[[1]]
editDist = mean(abs(Net1@net - Net2@net))/(((nNodes-1)*nNodes)/2)
return(editDist)
}
testPair = pairwise_net_stat_apply(testSet, edit_dist)
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "ANY", self.comp = "ANY"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(nets = netSet@nets, net.stat.fun = net.stat.fun,
net.stat.fun.args = net.stat.fun.args), SIMPLIFY = F)
resMat = matrix(NA, nNets, nNets)
resMat[index] = pairwise.vector
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(resMat)
})
testPair = pairwise_net_stat_apply(testSet, edit_dist)
setMethod("pairwise_net_stat_apply", signature = c(netSet = "NetSample", net.stat.fun = "ANY",
net.stat.fun.args = "ANY", net.stat.name = "ANY",
symmetric = "ANY", self.comp = "ANY"),
function(netSet, net.stat.fun, net.stat.fun.args, net.stat.name, symmetric = TRUE, self.comp = FALSE){
if(missing(net.stat.name)){
net.stat.name = deparse(substitute(net.stat.fun))
}
net.stat.fun = match.fun(net.stat.fun)
if(missing(net.stat.fun.args)){
net.stat.fun.args = list()
}
nNets = length(netSet@nets)
if(symmetric){
index = t(combn(1:nNets, 2))
}else{
index = t(cbind(combn(1:nNets, 2), combn(nNets:1, 2)))
}
if(self.comp){
index = rbind(index,cbind(1:nNets, 1:nNets))
}
pairwise.vector = mapply(FUN = pairwise_fun_wrapper,index1 = index[,1], index2 = index[,2],
MoreArgs = list(nets = netSet@nets, net.stat.fun = net.stat.fun,
net.stat.fun.args = net.stat.fun.args))
resMat = matrix(NA, nNets, nNets)
resMat[index] = pairwise.vector
#
# toReturn = methods::new("NetStatSet",fun = netSet@fun,
# fun.name = netSet@fun.name,
# fun.args = netSet@fun.args,
# stat.fun = net.stat.fun,
# stat.fun.name = net.stat.name,
# stat.fun.args = net.stat.fun.args,
# orig.net.name = netSet@orig.net.name,
# orig.net.stat = orig.stat,
# nets.stat = nets.stat,
# nets.names = netSet@nets.names)
return(resMat)
})
testPair = pairwise_net_stat_apply(testSet, edit_dist)
View(testPair)
=======
data(GroupA)
GroupA_Net = as_NetSample(GroupA, 1:20, node.variables = list(community = c(rep(1, 10), rep(2,10))),
sample.variables = list(group = c(rep(1, 10), rep(2,10))))
Jackknife_GroupA_Net = net_apply(GroupA_Net, node_jackknife)
show(Jackknife_GroupA_Net)
?factor
install.packages("devtools")
install.packages("roxygen2")
install.packages(c("ggplot2", "igraph", "braingraph", "Rdpack"))
install.packages("brainGraph")
install.packages("rmarkdown")
install.packages("pdflatex")
install.packages("pandoc")
devtools::use_build_ignore("README.md")
devtools::use_build_ignore("NEWS.md")
?t.test
>>>>>>> b4fbbd590c54ab7e2c1cf1edd1b8ba5fe43e432f