Description Usage Arguments Details Value Examples
Constructor for a mixedMemModelVI
object which can be used be fit using
variational inference in the mixedMem
package.
1 2 |
Total |
the number of individuals in the sample. |
J |
the number of variables observed on each individual. |
Rj |
a vector of length J specifying the number of repeated measurements for each variable. |
Nijr |
an array with dimension ( |
K |
the number of sub-populations. |
Vj |
a vector of length |
alpha |
a vector of length |
theta |
an array with dimensions ( |
phi |
an array with dimensions ( |
delta |
an array with dimensions ( |
dist |
a vector of length |
obs |
an array with dimensions ( |
The function returns an object of mixedMemModelVI
class. This object
contains dimensions of the model, the observed data, and the model
parameters. Once a mixedMemModelVI
object is created, the specified
model can be fit for the data using the mmVarFit
function. If the
inputs are inconsistent (ie if dimensions do not match,
or if observations and distribution types are not compatible,
mixedMemModelVI
will throw an error.
For additional details on usage, and model assumptions, see the
corresponding vignette "Fitting Mixed Membership Models
Using mixedMem
". Supported data types include Bernoulli, Multinomial,
and Rank (Plackett-Luce). Note that the variational methods of mixeMem
do not support the "Extended GoM" model which can be fit through the provided
MCMC methods.
returns an object of class mixedMemModelVI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | set.seed(123)
Total <- 50 # 50 Individuals
J <- 3 # 3 different variables
# distributions of each variable
dist <- c("multinomial", "bernoulli", "rank")
# 100 repeated measures of the multinomial, 5 repeated measures of the
# Bernoulli, 1 repeated measure of the rank
Rj <- c(100, 5, 1)
K <- 4 # 4 sub-populations
alpha <- rep(.5, K) #hyperparameter for dirichlet distribution
# Number of categories/alternatives for each variable. For the Bernoulli, Vj = 1
Vj <- c(10, 1, 4)
theta <- array(0, dim = c(J, K, max(Vj)))
# Parameters governing multinomial
theta[1,,] <- gtools::rdirichlet(K, rep(.3, Vj[1]))
# parameters governing Bernoulli
theta[2,,] <- cbind(rbeta(K, 1,1), matrix(0, nrow = K, ncol = Vj[1]-1))
theta[3,,] <- cbind(gtools::rdirichlet(K, rep(.3, Vj[3])),
matrix(0, nrow = K, ncol = Vj[1]-Vj[3]))
# Items selected for each observation. For Multinomial and Bernoulli, this is always 1
# For rank data, this will be the number of alternatives ranked
Nijr = array(0, dim = c(Total, J, max(Rj)))
Nijr[,1,c(1:Rj[1])] = 1 # N_ijr is 1 for multinomial variables
Nijr[,2,c(1:Rj[2])] = 1 # N_ijr is 1 for Bernoulli variables
Nijr[,3,c(1:Rj[3])] = sample.int(Vj[3], size = Total, replace = TRUE)
# generate random sample of observations
sampleMixedMem <- rmixedMem(Total, J, Rj, Nijr, K, Vj,
dist, theta, alpha)
## Initialize a mixedMemModel object
test_model <- mixedMemModel(Total = Total, J = J,Rj = Rj,
Nijr= Nijr, K = K, Vj = Vj,dist = dist, obs = sampleMixedMem$obs,
alpha = alpha, theta = theta)
# Look at Summary of the initialized model
summary(test_model)
# Plot the current values for theta
plot(test_model)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.