exact_loglik {ergmito}R Documentation

Vectorized calculation of ERGM exact log-likelihood

Description

This function can be compared to ergm::ergm.exact with the statistics not centered at x, the vector of observed statistics.

Usage

exact_loglik(x, params, ..., as_prob = FALSE)

## Default S3 method:
exact_loglik(
  x,
  params,
  stats_weights,
  stats_statmat,
  target_offset = double(nrow(x)),
  stats_offset = lapply(stats_weights, function(i) double(length(i))),
  ...,
  as_prob = FALSE
)

exact_gradient(x, params, ...)

## Default S3 method:
exact_gradient(
  x,
  params,
  stats_weights,
  stats_statmat,
  target_offset = double(nrow(x)),
  stats_offset = lapply(stats_weights, function(i) double(length(i))),
  ...
)

exact_hessian(
  params,
  stats_weights,
  stats_statmat,
  stats_offset = lapply(stats_weights, function(i) double(length(i)))
)

Arguments

x

Matrix. Observed statistics

params

Numeric vector. Parameter values of the model.

...

Arguments passed to the default methods.

as_prob

Logical scalar. When TRUE, the function returns probabilities instead of log-likelihoods.

stats_weights

Either an integer vector or a list of integer vectors (see exact_loglik).

stats_statmat

Either a matrix or a list of matrices (see exact_loglik).

target_offset

Numeric vector of length nrow(target_stats).

stats_offset

List of numeric vectors, each of length equal to the lengths of vectors in stats_weights (see details).

Sufficient statistics

One of the most important components of ergmito is calculating the full support of the model's sufficient statistics. Right now, the package uses the function ergm::ergm.allstats which returns a list of two objects:

Since ergmito can vectorize operations, in order to specify weights and statistics matrices for each network in the model, the user needs to pass two lists stats_weights and stats_statmat. While both lists have to have the same length (since its elements are matched), this needs not to be the case with the networks, as the user can specify a single set of weights and statistics that will be recycled (smartly).

In the case of offset terms, these can be passed directly via target_offset and stats_offset. The first is a numeric vector of length equal to the number of networks in the model. The later is a list of vectors that is matched against stats_weights, so each of it's elements must be a numeric vector of the same length that in the list of weights. By default the offset terms are set to equal zero.

Examples

data(fivenets)
ans <- ergmito(fivenets ~ edges + nodematch("female"))

# This computes the likelihood for all the networks independently
with(ans$formulae, {
  exact_loglik(
    x      = target_stats,
    params = coef(ans),
    stats_weights = stats_weights,
    stats_statmat = stats_statmat
  )
})

# This should be close to zero
with(ans$formulae, {
  exact_gradient(
    x      = target_stats,
    params = coef(ans),
    stats_weights = stats_weights,
    stats_statmat = stats_statmat
  )
})

# Finally, the hessian
with(ans$formulae, {
  exact_hessian(
    params = coef(ans),
    stats_weights = stats_weights,
    stats_statmat = stats_statmat
  )
})


[Package ergmito version 0.3-1 Index]