design_exp: Design experiment to perform on theoretical 'scanList'

Description Usage Arguments Details Value See Also Examples

View source: R/expDesign_tools.R

Description

Generate expDesign objects that mainly consist on a sequence of functions to apply to scanList objects. expDesign object generation relies on purrr's compose() function.

Usage

1
design_exp(..., .dir = c("forward", "backward"))

Arguments

...

functions of scanList objects. Can be a combination of the provided "building blocks" and user-defined function (cf. the example section).

.dir

character scalar, either "forward" (default) or "backward" (see purrr's compose()) to indicate in which order inputted functions should be applied (first function first, or vice versa).

Details

It is best practice to use a combination of:

expDesign objects are used to store sequences of manipulations to apply to a theoretical scanList, in order to obtain a (simulated) empirical scanList. Such manipulations can represent empirical sampling (e.g. group-scan sampling, focal sampling, biased sampling), observation error, node removal, etc.

expDesign objects can be applied to scanList objects via the function perform_exp(), or directly as simunet() exp.design argument for simunet() to automatically generate a theoretical scanList and apply the inputted expDesign to it.

Providing more than one expDesign object to either perform_exp() or simunet() functions (i.e. effectively passing them as their ... argument) will make them output a list of scanList objects - i.e. a sLlist object - which are convenient ways to apply different experimental manipulation sequences to a given theoretical scanList and allow for comparison (e.g. of the impact of sampling regime).

Value

an expDesign objects, a list consisting in the following elements:

See Also

perform_exp(), simunet(), design_sampling().

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
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 the experiments:
## setting a constant probability of not observing edges
group.scan <- design_sampling(method = "group",sampling = 0.8)

## setting a biased focal sampling favoring central individual (node strength)
focal.scan <- design_sampling(
 method = "focal",
 sampling = function(Adj) Adj |>
  igraph::graph.adjacency("upper",weighted = TRUE) |>
  igraph::strength()
)

## Adding more scans, removing the most peripheral individual, before performing an even focal
## sampling
focal.periRemoved <- design_exp(
  function(Adj) add_scans(Adj,42),     # users can use anonymous function to specify arguments
  remove_mostPeripheral,               # ... or pass functions as arguments directly
  design_sampling(method = "focal",sampling = "even")    # design_sampling: special case
                                                            # that returns sampling functions
)

# Apply the experimental design
## on previously obtained theoretical scans
sL <- simunet(Adj = Adj,samp.effort = samp.effort,mode = "upper",n.scans = 120L)

perform_exp(sL,group.scan)
perform_exp(sL,focal.periRemoved) |> sum_scans()

## on newly simulated scanList within the simunet() wrapper
simunet(Adj = Adj,samp.effort = samp.effort,mode = "upper",n.scans = 120L,
        focal.scan
)

## performing a list of experiments
perform_exp(sL,group.scan,focal.scan)
simunet(Adj = Adj,samp.effort = samp.effort,mode = "upper",n.scans = 120L,
        focal.scan,focal.periRemoved
)

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