var_to_logvar {mHMMbayes}R Documentation

Transform the between-subject variance in the positive scale to the logvariance in the logarithmic scale

Description

var_to_logvar returns the desired between-subject logvariance in the logarithmic scale corresponding to the between-subject variance in the (real) positive scale specified as input. The logvariance is used as the dispersion parameter in the lognormal distribution adopted as prior for the subject-specific Poisson means in the implementation of mHMM and sim_mHMM of mHMMbayes for count distributed data. It takes as inputs the group-level Poisson means emiss_mu and the desired between-subject variance var_emiss, both in the (real) positive scale.

Usage

var_to_logvar(gen, emiss_mu, var_emiss, byrow = TRUE)

Arguments

gen

List containing the following elements denoting the general model properties:

  • m: numeric vector with length 1 denoting the number of hidden states

  • n_dep: numeric vector with length 1 denoting the number of dependent variables

emiss_mu

A list containing n_dep matrices, i.e., one list for each dependent variable k. Each matrix contains the group-level means of the lognormal emission distributions in each of the states in the natural (positive real numbers) scale. Hence, each matrix consists of either 1 row (when not including covariates in the model) and m columns (see emiss_mu0 in prior_emiss_count), or m rows and 1 column (when not including covariates in the model; see emiss_distr in sim_mHMM), denoting the mean of state i (column or row i) of the lognormal distribution used as prior for the Poisson emissions. By default it is assumed that the matrices contain 1 row and m columns, as specified for emiss_mu0 in prior_emiss_count (see argument byrow). If emiss_mu were to be specified using m rows and 1 column as for emiss_distr in sim_mHMM, then set the argument byrow = FALSE.

Note: in every case the means should be specified in the natural (real positive) scale.

var_emiss

A list containing n_dep elements corresponding to each of the dependent variables k, where each element k is a vector with length m denoting the amount of variance between the subject (emission distribution) means in the natural (positive real numbers) scale. It follows a similar specification as emiss_V in prior_emiss_count.

byrow

A logical scalar indicating whether the emission means are specified in the first row (byrow = TRUE) or the first column (byrow = FALSE) of the n_dep matrices listed in emiss_mu. Use byrow = TRUE if emiss_mu is entered as emiss_mu0 in prior_emiss_count, and byrow = FALSE if emiss_mu is entered as emiss_distr in sim_mHMM. By default, byrow = TRUE.

Value

var_to_logvar Returns a list of n_dep numeric vectors of m elements denoting the state i-specific logvariance (between-subject variance in the logarithmic scale) for the k-dependent variable used as dispersion parameter in the lognormal prior for the Poisson emission distribution.

See Also

mHMM for fitting the multilevel hidden Markov model, and sim_mHMM for simulating data from a multilevel hidden Markov model.

Examples

###### Example on package data


## Example: specifying count priors manually using both positive and log scale:

# Define general parameters:
m       <- 3        # Number of hidden states
n_dep   <- 2        # Number of dependent variables

# Specify priors manually on the positive scale for emuss_mu0 and emiss_V:
manual_prior_emiss_1 <- prior_emiss_count(
  gen = list(m = m, n_dep = n_dep),
  emiss_mu0 = list(matrix(c(30, 70, 170), nrow = 1),
                   matrix(c(7, 8, 18), nrow = 1)),
  emiss_K0 = list(1, 1),
  emiss_V =  list(c(16,25,32),
                  rep(4, m)),
  emiss_nu = list(0.1, 0.1),
  log_scale = FALSE)

# Define logmu and logvar:
logmu <-  list(matrix(log(c(30, 70, 170)), nrow = 1),
               matrix(log(c(7, 8, 18)), nrow = 1))

logvar <- var_to_logvar(gen = list(m = m, n_dep = n_dep),
                        emiss_mu = list(matrix(c(30, 70, 170), nrow = 1),
                                        matrix(c(7, 8, 18), nrow = 1)),
                        var_emiss = list(c(16,25,32),
                                         rep(4, m)),
                        byrow = TRUE)

# Specify priors manually on the log scale for emiss_mu0 and emiss_V:
manual_prior_emiss_2 <- prior_emiss_count(
  gen = list(m = m, n_dep = n_dep),
  emiss_mu0 = logmu,
  emiss_K0 = list(1, 1),
  emiss_V =  logvar,
  emiss_nu = list(0.1, 0.1),
  log_scale = TRUE)

# Check whether they are identical:
identical(manual_prior_emiss_1, manual_prior_emiss_2)




[Package mHMMbayes version 1.1.0 Index]