design_sampling: Design a sampling regime to perform on a theoretical...

Description Usage Arguments Details Value See Also Examples

View source: R/expDesign_sampling.R

Description

This function returns an expDesign object containing a sampling function to apply to scanList objects (see perform_exp()). It is written as a convenient wrapper for commonly used sampling methods: group-scan sampling and focal-scan sampling.

Usage

1
2
3
4
5
design_sampling(
  method = c("group", "focal"),
  sampling = c("constant", "matrix", "even", "random", "function"),
  all.sampled = TRUE
)

Arguments

method

character scalar, either "group" or "focal"

sampling

depending on chosen method, users should input either:

  • a numeric scalar ("constant"): the constant probability of observing an edge for all edges

  • a numeric matrix ("matrix"): the probabilities of observing an edge for each edges

  • a character scalar: for common sampling regimes:

    • "even": in the case of method = "focal": select focals as evenly as possible, and the extra scans uniformly

    • "random": random edge observation probabilities or uniform probability of choosing a focal at each scan

  • a user-defined function ("function"): a function of the adjacency matrix Adj (can be named anything) that:

    • in the case of method = "group": returns a matrix of the probabilities of observing an edge for each edges

    • in the case of method = "focal": returns a vector of the probabilities of choosing a focal node at each scan

  • WIP: more option to be added, like with the possibility to pass a focalList object directly

all.sampled

logical scalar, should all nodes be sampled at least once? (TO CHECK: does it work with group-scan sampling?)

Details

design_sampling() accepts as sampling parameter:

The empirical sampling works by replacing unobserved edges by NAs in the 3D array, either:

Convenience "building blocks" functions - respectively count_NA() and count_nonNA() - can be used to count masked and sampled edges throughout the whole simulation.

New attributes are added to attrs:

Value

an expDesign object containing a function of a theoretical scan.list simulating the empirical sampling of the network's edges at each scan. To be used as part of an expDesign object (see design_exp())

See Also

simunet(), design_exp(), perform_exp(), group_sample(), determine_obsProb(), focal_sample(), draw_focalList(), mask_non.focals(), count_NA(), count_nonNA().

Examples

 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
set.seed(42)
n <- 5L
samp.effort <- 100L

# Adjacency matrix import
## random directed adjacency matrix
Adj <- sample(1:samp.effort,n * n) |>
  matrix(nrow = 5,dimnames = list(letters[1:n],letters[1:n]))
Adj[lower.tri(Adj,diag = TRUE)] <- 0L
Adj

# Designing sampling regimes:
## setting a constant probability of not observing edges
group.constant <- design_sampling(method = "group",sampling = 0.8)
group.constant

## setting a random probability of not observing edges
group.random <- design_sampling(method = "group",sampling = "random")

## setting probability of not observing edges via user-defined functions
g.fun1 <- function(Adj) Adj     # observation proportional to the network's weights,
                                # will be rescaled as probabilities internally
group.fun1 <- design_sampling(method = "group",sampling = g.fun1)

### user-defined functions can also be passed as anonymous functions
group.fun2 <- design_sampling(method = "group",sampling = function(Adj) Adj^2)

## evenly select focals
focal.even <- design_sampling(method = "focal",sampling = "even")

## randomly select focals
focal.random <- design_sampling(method = "focal",sampling = "random")

## setting probability of selecting focals via user-defined functions
f.fun1 <- function(Adj) 1:nrow(Adj)       # linear increase of probability of being focal,
                                          # akin to a linear trait
focal.fun1 <- design_sampling(method = "focal",sampling = f.fun1)

### user-defined functions can also be passed as anonymous functions
focal.fun2 <- design_sampling(method = "focal",sampling = function(Adj) Adj |>
                                   igraph::graph.adjacency(mode = "upper",weighted = TRUE) |>
                                   igraph::eigen_centrality() |> {function(x) x$vector}()
)                            # probabilities proportional to nodes' eigen-vector centralities

# Design and run experiment based on these sampling regime
## sampling regimes can be included in an `expDesign` object and passed to `simunet()`...
g.const.exp <- design_exp(group.constant)
simunet(Adj = Adj,samp.effort = samp.effort,mode = "upper",n.scans = 120L,g.const.exp)

## ... or passed to `perform_exp()`...
g.rand.periRemoved <- design_exp(remove_mostPeripheral,group.random)

sL <- simunet(Adj = Adj,samp.effort = samp.effort,mode = "upper",n.scans = 120L)
sL |> perform_exp(g.rand.periRemoved)

## ... or used "in situ" in either `simunet()` or `perform_exp()`,
## but need to be passed to `design_exp()`
## (TO DO: recognize sampling regime and manage this automatically)
simunet(Adj = Adj,samp.effort = samp.effort,mode = "upper",n.scans = 120L,design_exp(group.fun2))
sL |> perform_exp(focal.even)
sL |> perform_exp(design_sampling("focal","random"))

R-KenK/SimuNet documentation built on Oct. 22, 2021, 1:27 a.m.