Learn R Programming

netdiffuseR (version 1.16.7)

struct_test: Structure dependence test

Description

Test whether or not a network estimates can be considered structurally dependent, i.e. a function of the network structure. By rewiring the graph and calculating a particular statistic $t$, the test compares the observed mean of $t$ against the empirical distribution of it obtained from rewiring the network.

Usage

n_rewires(graph, p = c(100L, rep(0.1, nslices(graph) - 1)))
struct_test(graph, statistic, R, rewire.args = list(p = n_rewires(graph), undirected = getOption("diffnet.undirected", FALSE), copy.first = TRUE, algorithm = "swap"), ...)
"c"(..., recursive = FALSE)
"print"(x, ...)
"hist"(x, main = "Empirical Distribution of Statistic", xlab = expression(Values ~ of ~ t), breaks = 20, annotated = TRUE, b0 = expression(atop(plain("") %up% plain("")), t[0]), b = expression(atop(plain("") %up% plain("")), t[]), ...)

Arguments

graph
A diffnet graph.
p
Either a Numeric scalar or vector of length nslices(graph)-1 with the number of rewires per links.
statistic
A function that returns either a scalar or a vector.
R
Integer scalar. Number of repetitions.
rewire.args
List. Arguments to be passed to rewire_graph
...
Further arguments passed to the method (see details).
recursive
Ignored
x
A diffnet_boot class object.
main
Character scalar. Title of the histogram.
xlab
Character scalar. x-axis label.
breaks
Passed to hist.
annotated
Logical scalar. When TRUE marks the observed data average and the simulated data average.
b0
Character scalar. When annotated=TRUE, label for the value of b0.
b
Character scalar. When annotated=TRUE, label for the value of b.

Value

A list of class diffnet_bot containing the following:
graph
The graph passed to struct_test.
p.value
The resulting p-value of the test (see details).
t0
The observed value of the statistic.
mean_t
The average value of the statistic applied to the simulated networks.
R
Number of simulations.
statistic
The function statistic passed to struct_test.
boot
A boot class object as return from the call to boot.
rewire.args
The list rewire.args passed to struct_test.
The output from the hist method is the same as hist.default.

Details

struct_test is a wrapper for the function boot from the boot package. Instead of resampling data--vertices or edges--in each iteration the function rewires the original graph using rewire_graph and applies the function defined by the user in statistic. In particular, the "swap" algorithm is used in order to preserve the degree sequence of the graph, in other words, each rewired version of the original graph has the same degree sequence.

In struct_test ... are passed to boot, otherwise are passed to the corresponding method (hist for instance).

From the print method, p-value for the null of the statistic been equal between graph and its rewired versions is computed as follows

$$% p(\tau)=2\times\min\left(\mbox{Pr}(t\leq\tau), \mbox{Pr}(t\geq\tau)\right) % $$

Where $Pr(.)$ is approximated using the Empirical Distribution Function retrieved from the simulations.

The test is actually on development by Vega Yon and Valente. A copy of the working paper can be distributed upon request to g.vegayon@gmail.com.

The function n_rewires proposes a vector of number of rewirings that are performed in each iteration.

References

Vega Yon, George G. and Valente, Thomas W. (On development).

Davidson, R., & MacKinnon, J. G. (2004). Econometric Theory and Methods. New York: Oxford University Press.

Examples

Run this code
# Creating a random graph
set.seed(881)
diffnet <- rdiffnet(100, 5, seed.graph="small-world")

# Testing structure-dependency of threshold
res <- struct_test(diffnet, function(g) mean(threshold(g), na.rm=TRUE), R=100)
res
hist(res)

# Adding a legend
legend("topright", bty="n",
 legend=c(
   expression(t[0]:~Baseline),
   expression(t:~Rewired~average)
 )
 )

# Concatenating results
c(res, res)

# Running in parallel fashion
## Not run: 
# res <- struct_test(diffnet, function(g) mean(threshold(g), na.rm=TRUE), R=100,
# ncpus=4, parallel="multicore")
# res
# hist(res)
# ## End(Not run)

Run the code above in your browser using DataLab