R/edgeProb.R
draw_edgeProb.Rd
Edge presence probabilities are drawn from a posterior Beta distribution
\(Beta(\alpha,\beta)\), in which parameters \(\alpha\) and \(\beta\) correspond to total
(pseudo-)counts of the times when an edge was 1 and 0, respectively. By default, an uninformative
prior (Jeffrey's prior, i.e. \(\alpha_{prior} = \beta_{prior} = 1 / 2\)) is used, and is added to the observed edge weights in Adj
, so that:
$$\alpha = Adj + \alpha_{prior}, \beta = N_{samp.effort} - Adj + \beta_{prior}$$ where \(N_{samp.effort} -
Adj\) is a positive or null integer.
draw_edgeProb( Adj, samp.effort, Adj.subfun = NULL, alpha.prior = 0.5, beta.prior = 0.5 )
Adj | integer matrix, the adjacency matrix (see |
---|---|
samp.effort | integer scalar, the sampling effort (see |
Adj.subfun | function, the matrix subsetting function relevant for the adjacency matrix
|
alpha.prior | positive numeric scalar, the parameter alpha (added to shape1 in |
beta.prior | positive numeric scalar, the parameter beta (added to shape2 in |
numeric matrix of edge presence probabilities
For Bayesian inference and conjugation, a prior beta distribution \(Beta(\alpha_{prior},\beta_{prior})\) is used, with default $$\alpha_{prior} = \beta_{prior} = 1 / 2$$ which corresponds to Jeffrey's prior. Alternative parametrization can rely on $$\alpha_{prior} = \beta_{prior} = 1$$ for a prior beta distribution equivalent to a uniform distribution over \([0,1]\).
In simunet()
, a new edgeProb
is drawn before simulating binary scans. Two
scanList
s outputted from an identical Adj
matrix and samp.effort
will result in different
edgeProb
s, but these edgeProb
s are drawn from the same posterior Beta distribution
\(Beta(\alpha,\beta)\).
The edgeProb
used is stored in the scanList
outputted by simunet()
as an attribute in the
attributes list attrs
, and can be retrieved via attrs(scan.list,"edgeProb")
).
This procedure is equivalent to drawing a scanList
from a Beta-Binomial distribution
\(BetaBinom(n_{scans},\alpha,\beta)\), but allows
"decomposing" the simulated edge weights into a list of binary scans instead of outputting only a
new weighted adjacency matrix.
# Internally used in `generate_edgeProb()`, itself used in `simunet()` set.seed(42) n <- 5L samp.effort <- 241L # Adjacency matrix import ## random directed adjacency matrix Adj <- matrix(sample(1:samp.effort,n * n), nrow = 5,dimnames = list(letters[1:n],letters[1:n])) diag(Adj) <- 0L Adj#> a b c d e #> a 0 228 47 165 111 #> b 229 0 24 110 131 #> c 65 122 0 20 41 #> d 153 241 100 0 227 #> e 74 128 89 114 0sL <- simunet(Adj = Adj,samp.effort = samp.effort,mode = "directed",n.scans = 20L) attrs(sL,"edge.Prob")#> #> Edge presence probability matrix #> a . 0.935 0.207 0.660 0.428 #> b 0.948 . 0.108 0.421 0.508 #> c 0.319 0.470 . 0.085 0.153 #> d 0.598 0.999 0.401 . 0.957 #> e 0.339 0.537 0.399 0.479 . #> #> alpha.prior = 0.5 - beta.prior = 0.5