rWeightSBM: Sample random weights on edges of a binary Stochastic Block...

Description Usage Arguments Value Examples

View source: R/sampling_sbm.R

Description

This function draws weights according to a user-defined distribution for the edges of an existing binary SBM.

Usage

1
rWeightSBM(anSBM, family = c("gaussian", "poisson", "laplace"), theta)

Arguments

anSBM

SBM sampled from the rSBM function with nbBlock

family

character describing the distribution used for the weigths

theta

list embedding parameters required for the distribution of the weights. Either "gaussian", "poisson" or "laplace". See details.

Elements in the theta should be named as follows, depending on the argument family, with dimension matching the number of blocks in the original SBM:

  • Gaussiantheta$mu, a (nbBlock x nbBlock) matrix of means; theta$sigma, a (nbBlock x nbBlock) matrix of standard deviations

  • Laplacetheta$m, a (nbBlock x nbBlock) matrix of location parameters; theta$s, a (nbBlock x nbBlock) matrix of scale parameters

  • Poissontheta$lambda, a (nbBlock x nbBlock) matrix of means.

  • Otherssoon available.

Value

an SBM weight weigthed edges

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
## graph parameters
nbNodes  <- 90
blockProp <- c(.5, .25, .25)   # group proportions
nbBlock   <- length(blockProp) # number of blocks
connectParam <- diag(.4, nbBlock) + 0.05 # connectivity matrix: affiliation network

## Graph Sampling
mySBM <- rSBM(nbNodes, connectParam, blockProp)

## Sampling Gaussian weights
mu_within   <- 4 ; sigma_within  <- .5
mu_between  <- 2 ; sigma_between <- .5
theta <- list()
theta$mu    <- matrix(mu_between   , nbBlock, nbBlock); diag(theta$mu)    <- mu_within    # means
theta$sigma <- matrix(sigma_between, nbBlock, nbBlock); diag(theta$sigma) <- sigma_within # sd

mySBM_Gaussian <- rWeightSBM(mySBM, "gaussian", theta)
hist(igraph::E(mySBM_Gaussian)$weight,  breaks = sqrt(igraph::gsize(mySBM_Gaussian)))

## Sampling Laplace weights
m_within   <- 4 ; s_within  <- .5
m_between  <- 2 ; s_between <- .5
theta <- list()
theta$m <- matrix(m_between, nbBlock, nbBlock); diag(theta$m) <- m_within # location parameter
theta$s <- matrix(s_between, nbBlock, nbBlock); diag(theta$s) <- s_within # scale parameters

mySBM_Laplace <- rWeightSBM(mySBM, "laplace", theta)
hist(igraph::E(mySBM_Laplace)$weight,  breaks = sqrt(igraph::gsize(mySBM_Laplace)))

## Sampling Poisson weights
lambda_within   <- 4
lambda_between  <- 4
theta <- list()
# mean/variance parameter
theta$lambda <- matrix(lambda_between, nbBlock, nbBlock)
diag(theta$lambda) <- lambda_within

mySBM_Poisson <- rWeightSBM(mySBM, "poisson", theta)
hist(igraph::E(mySBM_Poisson)$weight,  breaks = sqrt(igraph::gsize(mySBM_Poisson)))

jchiquet/rggm documentation built on April 5, 2020, 1:53 a.m.