EM Algorithm for Mixtures of Regressions with Random Effects
regmixEM.mixed.RdReturns EM algorithm output for mixtures of multiple regressions with random effects and an option to incorporate fixed effects and/or AR(1) errors.
Usage
regmixEM.mixed(y, x, w = NULL, sigma = NULL, arb.sigma = TRUE,
alpha = NULL, lambda = NULL, mu = NULL,
rho = NULL, R = NULL, arb.R = TRUE, k = 2,
ar.1 = FALSE, addintercept.fixed = FALSE,
addintercept.random = TRUE, epsilon = 1e-08,
maxit = 10000, verb = FALSE)Arguments
- y
A list of N response trajectories with (possibly) varying dimensions of length \(n_i\).
- x
A list of N design matrices of dimensions \((n_i)\times p\). Each trajectory in y has its own design matrix.
- w
A list of N known explanatory variables having dimensions \((n_i)\times q\). If
mixed= FALSE, thenwis replaced by a list of N zeros.- sigma
A vector of standard deviations. If NULL, then \(1/s^2\) has random standard exponential entries according to a binning method done on the data.
- arb.sigma
If TRUE, then
sigmais k-dimensional. Else a common standard deviation is assumed.- alpha
A q-vector of unknown regression parameters for the fixed effects. If NULL and
mixed= TRUE, thenalphais random from a normal distribution with mean and variance according to a binning method done on the data. Ifmixed= FALSE, thenalpha= 0.- lambda
Initial value of mixing proportions for the assumed mixture structure on the regression coefficients. Entries should sum to 1. This determines number of components. If NULL, then
lambdais random from uniform Dirichlet and the number of components is determined bymu.- mu
A pxk matrix of the mean for the mixture components of the random regression coefficients. If NULL, then the columns of
muare random from a multivariate normal distribution with mean and variance determined by a binning method done on the data.- rho
An Nxk matrix giving initial values for the correlation term in an AR(1) process. If NULL, then these values are simulated from a uniform distribution on the interval (-1, 1).
- R
A list of N pxp covariance matrices for the mixture components of the random regression coefficients. If NULL, then each matrix is random from a standard Wishart distribution according to a binning method done on the data.
- arb.R
If TRUE, then
Ris a list of N pxp covariance matrices. Else, one common covariance matrix is assumed.- k
Number of components. Ignored unless
lambdais NULL.- ar.1
If TRUE, then an AR(1) process on the error terms is included. The default is FALSE.
- addintercept.fixed
If TRUE, a column of ones is appended to the matrices in w.
- addintercept.random
If TRUE, a column of ones is appended to the matrices in x before p is calculated.
- epsilon
The convergence criterion.
- maxit
The maximum number of iterations.
- verb
If TRUE, then various updates are printed during each iteration of the algorithm.
Value
regmixEM returns a list of class mixEM with items:
- x
The predictor values corresponding to the random effects.
- y
The response values.
- w
The predictor values corresponding to the (optional) fixed effects.
- lambda
The final mixing proportions.
- mu
The final mean vectors.
- R
The final covariance matrices.
- sigma
The final component error standard deviations.
- alpha
The final regression coefficients for the fixed effects.
- rho
The final error correlation values if an AR(1) process is included.
- loglik
The final log-likelihood.
- posterior.z
An Nxk matrix of posterior membership probabilities.
- posterior.beta
A list of N pxk matrices giving the posterior regression coefficient values.
- all.loglik
A vector of each iteration's log-likelihood.
- restarts
The number of times the algorithm restarted due to unacceptable choice of initial values.
- ft
A character vector giving the name of the function.
References
Xu, W. and Hedeker, D. (2001) A Random-Effects Mixture Model for Classifying Treatment Response in Longitudinal Clinical Trials, Journal of Biopharmaceutical Statistics, 11(4), 253–273.
Young, D. S. and Hunter, D. R. (2015) Random Effects Regression Mixtures for Analyzing Infant Habituation, Journal of Applied Statistics, 42(7), 1421–1441.
Examples
## EM output for simulated data from 2-component mixture of random effects.
data(RanEffdata)
set.seed(100)
x <- lapply(1:length(RanEffdata), function(i)
matrix(RanEffdata[[i]][, 2:3], ncol = 2))
x <- x[1:20]
y <- lapply(1:length(RanEffdata), function(i)
matrix(RanEffdata[[i]][, 1], ncol = 1))
y <- y[1:20]
lambda <- c(0.45, 0.55)
mu <- matrix(c(0, 4, 100, 12), 2, 2)
sigma <- 2
R <- list(diag(1, 2), diag(1, 2))
em.out <- regmixEM.mixed(y, x, sigma = sigma, arb.sigma = FALSE,
lambda = lambda, mu = mu, R = R,
addintercept.random = FALSE,
epsilon = 1e-02, verb = TRUE)
#> iteration= 1 diff= Inf log-likelihood -1149.303
#> iteration= 2 diff= 0.9521686 log-likelihood -1148.351
#> iteration= 3 diff= 0.4258641 log-likelihood -1147.925
#> iteration= 4 diff= 0.2389194 log-likelihood -1147.686
#> iteration= 5 diff= 0.153466 log-likelihood -1147.532
#> iteration= 6 diff= 0.1074595 log-likelihood -1147.425
#> iteration= 7 diff= 0.07976373 log-likelihood -1147.345
#> iteration= 8 diff= 0.06171877 log-likelihood -1147.283
#> iteration= 9 diff= 0.04925958 log-likelihood -1147.234
#> iteration= 10 diff= 0.04027054 log-likelihood -1147.194
#> iteration= 11 diff= 0.03355877 log-likelihood -1147.16
#> iteration= 12 diff= 0.0284077 log-likelihood -1147.132
#> iteration= 13 diff= 0.02436437 log-likelihood -1147.108
#> iteration= 14 diff= 0.0211303 log-likelihood -1147.086
#> iteration= 15 diff= 0.01850191 log-likelihood -1147.068
#> iteration= 16 diff= 0.0163362 log-likelihood -1147.052
#> iteration= 17 diff= 0.01453026 log-likelihood -1147.037
#> iteration= 18 diff= 0.0130084 log-likelihood -1147.024
#> iteration= 19 diff= 0.01171389 log-likelihood -1147.012
#> iteration= 20 diff= 0.01060354 log-likelihood -1147.002
#> iteration= 21 diff= 0.009643985 log-likelihood -1146.992
#> number of iterations= 21
em.out[4:10]
#> $lambda
#> [1] 0.45 0.55
#>
#> $mu
#> [,1] [,2]
#> [1,] 0.1199961 99.92340
#> [2,] 3.4174408 11.85396
#>
#> $R
#> $R[[1]]
#> [,1] [,2]
#> [1,] 0.5571739 -1.376503
#> [2,] -1.3765025 4.091600
#>
#> $R[[2]]
#> [,1] [,2]
#> [1,] 0.2887151 0.3805641
#> [2,] 0.3805641 1.0934910
#>
#>
#> $sigma
#> [1] 2.065884
#>
#> $alpha
#> [1] 0
#>
#> $loglik
#> [1] -1146.992
#>
#> $posterior.z
#> comp.1 comp.2
#> [1,] 1 0
#> [2,] 1 0
#> [3,] 0 1
#> [4,] 0 1
#> [5,] 0 1
#> [6,] 1 0
#> [7,] 1 0
#> [8,] 0 1
#> [9,] 1 0
#> [10,] 1 0
#> [11,] 1 0
#> [12,] 0 1
#> [13,] 1 0
#> [14,] 0 1
#> [15,] 0 1
#> [16,] 0 1
#> [17,] 0 1
#> [18,] 1 0
#> [19,] 0 1
#> [20,] 0 1
#>