EM Algorithm for Mixtures of Poisson Regressions
poisregmixEM.RdReturns EM algorithm output for mixtures of Poisson regressions with arbitrarily many components.
Usage
poisregmixEM(y, x, lambda = NULL, beta = NULL, k = 2,
addintercept = TRUE, epsilon = 1e-08,
maxit = 10000, verb = FALSE)Arguments
- y
An n-vector of response values.
- x
An nxp matrix of predictors. See
addinterceptbelow.- lambda
Initial value of mixing proportions. Entries should sum to 1. This determines number of components. If NULL, then
lambdais random from uniform Dirichlet and number of components is determined bybeta.- beta
Initial value of
betaparameters. Should be a pxk matrix, where p is the number of columns of x and k is number of components. If NULL, thenbetais generated by binning the data into k bins and usingglmon the values in each of the bins. If bothlambdaandbetaare NULL, then number of components is determined byk.- k
Number of components. Ignored unless
lambdaandbetaare both NULL.- addintercept
If TRUE, a column of ones is appended to the x matrix before the value of 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
poisregmixEM returns a list of class mixEM with items:
- x
The predictor values.
- y
The response values.
- lambda
The final mixing proportions.
- beta
The final Poisson regression coefficients.
- loglik
The final log-likelihood.
- posterior
An nxk matrix of posterior probabilities for observations.
- 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
McLachlan, G. J. and Peel, D. (2000) Finite Mixture Models, John Wiley and Sons, Inc.
Wang, P., Puterman, M. L., Cockburn, I. and Le, N. (1996) Mixed Poisson Regression Models with Covariate Dependent Rates, Biometrics, 52(2), 381–400.
Examples
## EM output for data generated from a 2-component model.
set.seed(100)
beta <- matrix(c(1, .5, .7, -.8), 2, 2)
x <- runif(50, 0, 10)
xbeta <- cbind(1, x)%*%beta
w <- rbinom(50, 1, .5)
y <- w*rpois(50, exp(xbeta[, 1]))+(1-w)*rpois(50, exp(xbeta[, 2]))
out <- poisregmixEM(y, x, verb = TRUE, epsilon = 1e-03)
#> Need new starting values due to underflow...
#> Need new starting values due to underflow...
#> Need new starting values due to underflow...
#> iteration= 1 diff= Inf log-likelihood -355.6115
#> iteration= 2 diff= 234.2121 log-likelihood -121.3994
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted rates numerically 0 occurred
#> iteration= 3 diff= 0.02347817 log-likelihood -121.3759
#> Warning: glm.fit: algorithm did not converge
#> Need new starting values due to singularity...
#> Warning: glm.fit: fitted rates numerically 0 occurred
#> iteration= 1 diff= 156.2348 log-likelihood -117.8764
#> Warning: glm.fit: fitted rates numerically 0 occurred
#> iteration= 2 diff= 0.5641961 log-likelihood -117.3122
#> Warning: glm.fit: fitted rates numerically 0 occurred
#> iteration= 3 diff= 0.006001777 log-likelihood -117.3062
#> Warning: glm.fit: fitted rates numerically 0 occurred
#> iteration= 4 diff= 0.0004355172 log-likelihood -117.3058
#> number of iterations= 4
out
#> $x
#> x
#> [1,] 1 3.0776611
#> [2,] 1 2.5767250
#> [3,] 1 5.5232243
#> [4,] 1 0.5638315
#> [5,] 1 4.6854928
#> [6,] 1 4.8377074
#> [7,] 1 8.1240262
#> [8,] 1 3.7032054
#> [9,] 1 5.4655860
#> [10,] 1 1.7026205
#> [11,] 1 6.2499648
#> [12,] 1 8.8216552
#> [13,] 1 2.8035384
#> [14,] 1 3.9848790
#> [15,] 1 7.6255108
#> [16,] 1 6.6902171
#> [17,] 1 2.0461216
#> [18,] 1 3.5752485
#> [19,] 1 3.5947511
#> [20,] 1 6.9029053
#> [21,] 1 5.3581115
#> [22,] 1 7.1080385
#> [23,] 1 5.3834870
#> [24,] 1 7.4897223
#> [25,] 1 4.2010145
#> [26,] 1 1.7142021
#> [27,] 1 7.7030161
#> [28,] 1 8.8195359
#> [29,] 1 5.4909671
#> [30,] 1 2.7772376
#> [31,] 1 4.8830599
#> [32,] 1 9.2850507
#> [33,] 1 3.4869198
#> [34,] 1 9.5415771
#> [35,] 1 6.9527414
#> [36,] 1 8.8945354
#> [37,] 1 1.8040725
#> [38,] 1 6.2939085
#> [39,] 1 9.8956414
#> [40,] 1 1.3028887
#> [41,] 1 3.3066053
#> [42,] 1 8.6512055
#> [43,] 1 7.7758444
#> [44,] 1 8.2730345
#> [45,] 1 6.0332436
#> [46,] 1 4.9123182
#> [47,] 1 7.8035851
#> [48,] 1 8.8422703
#> [49,] 1 2.0771390
#> [50,] 1 3.0708590
#>
#> $y
#> [1] 0 0 0 2 31 0 0 0 50 1 0 219 9 31 0 0 0 0 0
#> [20] 84 0 0 43 96 22 4 117 238 28 0 0 249 19 317 0 258 6 0
#> [39] 0 6 10 0 0 0 51 0 154 0 0 15
#>
#> $lambda
#> [1] 0.5310379 0.4689621
#>
#> $beta
#> comp.1 comp.2
#> beta.0 8.981084 1.006641
#> beta.1 -5.473055 0.498414
#>
#> $loglik
#> [1] -117.3058
#>
#> $posterior
#> comp.1 comp.2
#> [1,] 9.999973e-01 2.738164e-06
#> [2,] 9.999546e-01 4.539359e-05
#> [3,] 1.000000e+00 0.000000e+00
#> [4,] 3.297823e-158 1.000000e+00
#> [5,] 6.360016e-260 1.000000e+00
#> [6,] 1.000000e+00 5.018208e-14
#> [7,] 1.000000e+00 0.000000e+00
#> [8,] 1.000000e+00 2.640250e-08
#> [9,] 0.000000e+00 1.000000e+00
#> [10,] 9.734848e-01 2.651516e-02
#> [11,] 1.000000e+00 0.000000e+00
#> [12,] 0.000000e+00 1.000000e+00
#> [13,] 2.018289e-30 1.000000e+00
#> [14,] 9.143009e-207 1.000000e+00
#> [15,] 1.000000e+00 0.000000e+00
#> [16,] 1.000000e+00 0.000000e+00
#> [17,] 9.995019e-01 4.980858e-04
#> [18,] 9.999999e-01 7.701756e-08
#> [19,] 9.999999e-01 6.570915e-08
#> [20,] 0.000000e+00 1.000000e+00
#> [21,] 1.000000e+00 0.000000e+00
#> [22,] 1.000000e+00 0.000000e+00
#> [23,] 0.000000e+00 1.000000e+00
#> [24,] 0.000000e+00 1.000000e+00
#> [25,] 7.295103e-156 1.000000e+00
#> [26,] 3.783680e-02 9.621632e-01
#> [27,] 0.000000e+00 1.000000e+00
#> [28,] 0.000000e+00 1.000000e+00
#> [29,] 1.544038e-286 1.000000e+00
#> [30,] 9.999840e-01 1.600539e-05
#> [31,] 1.000000e+00 2.498002e-14
#> [32,] 0.000000e+00 1.000000e+00
#> [33,] 8.326491e-101 1.000000e+00
#> [34,] 0.000000e+00 1.000000e+00
#> [35,] 1.000000e+00 0.000000e+00
#> [36,] 0.000000e+00 1.000000e+00
#> [37,] 2.761451e-05 9.999724e-01
#> [38,] 1.000000e+00 0.000000e+00
#> [39,] 1.000000e+00 0.000000e+00
#> [40,] 5.415414e-01 4.584586e-01
#> [41,] 4.841602e-46 1.000000e+00
#> [42,] 1.000000e+00 0.000000e+00
#> [43,] 1.000000e+00 0.000000e+00
#> [44,] 1.000000e+00 0.000000e+00
#> [45,] 0.000000e+00 1.000000e+00
#> [46,] 1.000000e+00 1.576517e-14
#> [47,] 0.000000e+00 1.000000e+00
#> [48,] 1.000000e+00 0.000000e+00
#> [49,] 9.995647e-01 4.353444e-04
#> [50,] 2.968915e-63 1.000000e+00
#>
#> $all.loglik
#> [1] -274.1112 -117.8764 -117.3122 -117.3062 -117.3058
#>
#> $restarts
#> [1] 4
#>
#> $ft
#> [1] "poisregmixEM"
#>
#> attr(,"class")
#> [1] "mixEM"