mixedMemModel {mixedMem} | R Documentation |
Constructor for a mixedMemModel
object which can be used for analysis
in the mixedMem
package.
mixedMemModel(Total, J, Rj, Nijr, K, Vj, alpha, theta, phi = NULL, delta = NULL, dist, obs, fixedObs = NULL, P = NULL, beta = NULL)
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 ( |
fixedObs |
an array with dimensions (1, |
P |
scalar between 0 and 1 corresponding to initial value for the proportion of individuals in the fixed group |
beta |
scalar between 0 and 1 corresponding to the initial value of beta, the conditional probability of being in the fixed group for an individual who's observed responses match the fixed group. |
The function returns an object of mixedMemModel
class. This object contains dimensions of the model,
the observed data, and the model parameters. Once a mixedMemModel
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,mixedMemModel
will throw an error. For additional details on usage, and model
assumptions, see the corresponding vignette "Fitting Mixed Membership Models Using mixedMem
".
returns an object of class mixedMemModel
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)