specify_initial_values {JANE}R Documentation

Specify starting values for EM algorithm

Description

A function that allows the user to specify starting values for the EM algorithm in a structure accepted by JANE.

Usage

specify_initial_values(
  A,
  D,
  K,
  model,
  n_interior_knots = NULL,
  U,
  omegas,
  mus,
  p,
  Z,
  beta
)

Arguments

A

A square matrix or sparse matrix of class 'dgCMatrix' representing the adjacency matrix of the unweighted network of interest.

D

An integer specifying the dimension of the latent positions.

K

An integer specifying the total number of clusters.

model

A character string specifying the model:

  • 'NDH': undirected network with no degree heterogeneity

  • 'RS': undirected network with degree heterogeneity

  • 'RSR': directed network with degree heterogeneity

n_interior_knots

An integer specifying the number of interior knots used in fitting a natural cubic spline for degree heterogeneity models (i.e., 'RS' and 'RSR' only; default is NULL).

U

A numeric N \times D matrix with rows specifying an actor's position in a D-dimensional social space.

omegas

A numeric D \times D \times K array specifying the precision matrices of the multivariate normal distribution for the latent positions of the K clusters.

mus

A numeric K \times D matrix specifying the mean vectors of the multivariate normal distribution for the latent positions of the K clusters.

p

A numeric vector of length K specifying the mixture weights of the finite multivariate normal mixture distribution for the latent positions.

Z

A numeric N \times K matrix with rows representing the conditional probability that an actor belongs to the cluster K = k for k = 1,\ldots,K.

beta

A numeric vector specifying the regression coefficients for the logistic regression model. Specifically, a vector of length 1 + (model =="RS")*(n_interior_knots + 1) + (model =="RSR")*2*(n_interior_knots + 1).

Details

To match JANE, this function will remove isolates from the adjacency matrix A and determine the total number of actors after excluding isolates. If this is not done, errors with respect to incorrect dimensions in the starting values will be generated when executing JANE.

Similarly to match JANE, if an unsymmetric adjacency matrix A is supplied for model %in% c('NDH', 'RS') the user will be asked if they would like to proceed with converting A to a symmetric matrix (i.e., A <- 1.0 * ( (A + t(A)) > 0.0 )).

Value

A list of starting values for the EM algorithm generated from the input values in a structure accepted by JANE.

Examples


# Simulate network
mus <- matrix(c(-1,-1,1,-1,1,1), 
              nrow = 3,
              ncol = 2, 
              byrow = TRUE)
omegas <- array(c(diag(rep(7,2)),
                  diag(rep(7,2)), 
                  diag(rep(7,2))), 
                dim = c(2,2,3))
p <- rep(1/3, 3)
beta0 <- -1
sim_data <- JANE::sim_A(N = 100L, 
                        model = "RSR",
                        mus = mus, 
                        omegas = omegas, 
                        p = p, 
                        beta0 = beta0, 
                        remove_isolates = TRUE)

# Specify starting values
D <- 3L
K <- 5L
N <- nrow(sim_data$A)
n_interior_knots <- 5L

U <- matrix(stats::rnorm(N*D), nrow = N, ncol = D)
omegas <- stats::rWishart(n = K, df = D+1, Sigma = diag(D))
mus <- matrix(stats::rnorm(K*D), nrow = K, ncol = D)
p <- extraDistr::rdirichlet(n = 1, rep(3,K))[1,]
Z <-  extraDistr::rdirichlet(n = N, alpha = rep(1, K))
beta <- stats::rnorm(n = 1 + 2*(1 + n_interior_knots))

my_starting_values <- JANE::specify_initial_values(A = sim_data$A,
                                                   D = D,
                                                   K = K,
                                                   model = "RSR",
                                                   n_interior_knots = n_interior_knots,
                                                   U = U,
                                                   omegas = omegas, 
                                                   mus = mus, 
                                                   p = p, 
                                                   Z = Z,
                                                   beta = beta)         

# Run JANE using my_starting_values (no need to specify D and K as function will 
# determine those values from my_starting_values)
res <- JANE::JANE(A = sim_data$A,
                  initialization = my_starting_values,
                  model = "RSR")


[Package JANE version 0.2.1 Index]