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:
|
emiss_mu |
A list containing Note: in every case the means should be specified in the natural (real positive) scale. |
var_emiss |
A list containing |
byrow |
A logical scalar indicating whether the emission means are
specified in the first row ( |
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)