ud_fit_advanced: Low-Level Interface for Fitting Ultimate Deconvolution Models

compute_posterior_probsR Documentation

Low-Level Interface for Fitting Ultimate Deconvolution Models

Description

These functions allow for more fine-grained fitting of Ultimate Deconvolution models. Only minimal argument checking is performed and this interface should only be used by experienced users.

Usage

compute_posterior_probs(fit, version = c("Rcpp", "R"))

update_mixture_weights(fit, update = c("em", "none"), zero.threshold = 1e-15)

assign_prior_covariance_updates(fit, control = list())

update_prior_covariances(
  fit,
  covupdates = assign_prior_covariance_updates(fit)$covupdates,
  control = assign_prior_covariance_updates(fit)$control
)

update_resid_covariance(
  fit,
  update = c("em", "none"),
  version = c("Rcpp", "R")
)

Arguments

fit

An Ultimate Deconvolution model fit. Typically, this will be an output of ud_init or ud_fit.

version

When version = "R", the R-only implementation is used; when version = "Rcpp", the more efficient C++ implementation is used.

update

The method to use for updating the prior mixture weights or the residual covariance matrix; see ud_fit for details.

control

A list of parameters controlling the behaviour of the model fitting and initialization. See ud_fit for details.

covupdates

Functions or character strings naming the functions to be called for updating the prior covariance matrices.

minval

Minimum eigenvalue allowed in the prior covariance matrices. Should be a small, positive number.

Details

compute_posterior_probs returns the matrix of posterior mixture assignment probabilities ("responsibilities") given current estimates of the model parameters. This implements the E step in the EM algorithm.

update_mixture_weights performs an M-step update for the mixture weights in the mixture prior (or no update if update = "none").

update_resid_covariance performs an M-step update for the residual covariance matrix, V (or no update if update = "none").

assign_prior_covariance_updates determine the functions for updating the prior covariance matrices based on the the covariance matrix types and the control settings. The "covupdates" return value is a character vector with one entry for each prior covariance matrix.

update_prior_covariances performs an M-step update for all the prior covariance matrices, U.

Value

All functions except assign_prior_covariance_updates return an Ultimate Deconvolution model fit; see ud_fit for details.

See Also

ud_init, ud_fit

Examples

# Simulate data from a UD model.
set.seed(1)
n <- 4000
V <- rbind(c(0.8,0.2),
           c(0.2,1.5))
U <- list(none   = rbind(c(0,0),
                         c(0,0)),
          shared = rbind(c(1.0,0.9),
                         c(0.9,1.0)),
          only1  = rbind(c(1,0),
                         c(0,0)),
          only2  = rbind(c(0,0),
                         c(0,1)))
w <- c(0.8,0.1,0.075,0.025)
rownames(V) <- c("d1","d2")
colnames(V) <- c("d1","d2")
X <- simulate_ud_data(n,w,U,V)

# Perform 4 EM updates.
fit1 <- ud_init(X)
fit1 <- ud_fit(fit1,control = list(maxiter = 4))

# Update the responsibilities matrix.
fit2 <- compute_posterior_probs(fit1)

# Update the mixture weights.
fit2 <- update_mixture_weights(fit2)

# Update the residual covariance, V.
fit2 <- update_resid_covariance(fit2)

# Update the prior covariance matrices, U, using the defaults.
fit2 <- update_prior_covariances(fit2)

# Update only the unconstrained prior covariance matrices using the
# truncated eigenvalue decomposition ("ted") algorithm.
control <- list(scaled.update = "none",rank1.update = "none",
                unconstrained.update = "ted")
updates <- assign_prior_covariance_updates(fit2,control)$covupdates
fit2 <- update_prior_covariances(fit2,updates)

# Compute the new log-likelihood and compare the old one.
print(logLik(fit1),digits = 8)
print(logLik(fit2),digits = 8)


stephenslab/mvebnm documentation built on June 4, 2024, 6:37 a.m.