Test imaginary census motifs against a null model
Source:R/test_imaginary_census.R
test_imaginary_census.RdGenerates a null distribution of imaginary-census motif counts by
repeatedly sampling CSS networks with sample_css_network() and compares
the observed counts to this null distribution. Returns an S3 object of
class "imaginarycss_test" with print, summary, and plot methods.
Arguments
- graph
A
barry_graphobject.- n_sim
Integer. Number of null-model simulations (default
100).- alpha
Numeric. Significance level for the two-sided test (default
0.05).- counter_type
Integer passed to
count_imaginary_census()(default0L).- x
An object of class
"imaginarycss_test".- ...
Currently ignored.
- object
An object of class
"imaginarycss_test".- main
Character. Plot title.
Value
An object of class "imaginarycss_test", which is a list
containing:
- results
A data frame with columns
motif,observed,null_mean,null_sd,z_score,p_value, andsignificant.- observed
Named numeric vector of observed motif totals.
- null_matrix
Matrix of null motif totals (motifs x simulations).
- n_sim
Number of simulations used.
- alpha
Significance level used.
print.imaginarycss_test() returns the input object invisibly.
Called for its side effect of printing a summary of significant motifs.
summary.imaginarycss_test() returns the input object invisibly.
Called for its side effect of printing the full results table.
plot.imaginarycss_test() returns the input object invisibly.
Called for its side effect of drawing a horizontal barplot of z-scores.
Examples
data(krackhardt_advice)
data(krackhardt_advice_perceptions)
n_people <- 21
advice_matrix <- matrix(0L, nrow = n_people, ncol = n_people)
advice_matrix[cbind(krackhardt_advice$from, krackhardt_advice$to)] <-
krackhardt_advice$value
krack_graph <- new_barry_graph(
c(list(advice_matrix), krackhardt_advice_perceptions)
)
res <- test_imaginary_census(krack_graph, n_sim = 50)
res
#> Imaginary-census significance test
#> Simulations: 50 | Alpha: 0.05
#>
#> Significant motifs:
#> motif observed z_score p_value
#> Accurate null 992 7.05 0.00
#> Partial false positive (assym) 412 6.08 0.00
#> Partial false positive (null) 343 -5.44 0.00
#> Accurate assym 1052 -4.82 0.00
#> Complete false positive (null) 30 -4.38 0.00
#> Mixed assym 173 4.23 0.00
#> Partial false negative (assym) 463 -2.37 0.04
summary(res)
#> Imaginary-census significance test
#> Simulations: 50 | Alpha: 0.05
#> Motifs tested: 10 | Significant: 7
#>
#> motif observed null_mean null_sd z_score p_value
#> Accurate null 992 865.2 17.98 7.05 0.00
#> Partial false positive (assym) 412 300.1 18.41 6.08 0.00
#> Partial false positive (null) 343 439.4 17.71 -5.44 0.00
#> Accurate assym 1052 1167.1 23.90 -4.82 0.00
#> Complete false positive (null) 30 60.4 6.94 -4.38 0.00
#> Mixed assym 173 126.7 10.96 4.23 0.00
#> Partial false negative (assym) 463 506.1 18.24 -2.37 0.04
#> Complete false negative (full) 81 84.9 9.24 -0.42 0.76
#> Partial false negative (full) 395 392.5 12.74 0.19 0.80
#> Accurate full 469 467.5 15.34 0.10 0.96
#> significant
#> TRUE
#> TRUE
#> TRUE
#> TRUE
#> TRUE
#> TRUE
#> TRUE
#> FALSE
#> FALSE
#> FALSE
plot(res)