# Package `glmmAK`

This package implements several generalized linear (mixed) models (GLMM) where for random effects either a conventional normal distribution is assumed or a flexible model based on penalized smoothing is used for the random effect distribution. We call the second class of models as penalized Gaussian mixture (PGM) or shortly G-spline.

Models with random effects are estimated in a Bayesian way using the MCMC. The package implements also some models without random effects and these can be estimated also using maximum-likelihood. Additional information can be found in the references mentioned below and at personal webpage of Arnošt Komárek.
This overview provides a sorted list of the functions of the package and links to few more involved examples.

# 1. Generalized linear models (GLM)

Two functions of the package implements few instances of the GLM and their equivalents can be found also in other (standard) R packages, namely

- cumlogit
  fits
  - a logit model for binomial response (see also glm from package stats);
  - a cumulative logit model for multinomial response under the assumption of the proportional odds (see also polr from package MASS) and also without assuming proportionality of the odds.
- logpoisson
  fits a log-linear model for Poisson response (see also glm from package stats).

# 2. Generalized linear mixed models (GLMM)

The core functions related to the GLMM's with normally distributed random effects and with random effects which distribution is specified in a flexible way using the penalized Gaussian mixture (PGM) or shortly G-spline. Methodology has been described in

- KOMÁREK, A. and LESAFFRE, E. (2008).
  Generalized linear mixed model with a penalized Gaussian mixture as a random-effects distribution.
  Computational Statistics and Data Analysis, 52(7), 3441-3458.

### Main functions from the package related to this methodology

- cumlogitRE
  implements MCMC sampling for the random effects logit model for binary response and the cumulative logit model for multinomial response.
- cumlogitRE.predict
  implements computation of the posterior predictive category probabilities in models fitted using `cumlogitRE`.
- logpoissonRE
  implements MCMC sampling for the random effects log linear model for Poisson response.
- logpoissonRE.predict
  implements computation of the posterior predictive counts in models fitted using `logpoissonRE`.
- summaryGspline1
  provides computation of the pointwise posterior summaries (mean, quantiles) of a univariate penalized Gaussian mixture fitted as a random effect distribution using `cumlogitRE` or `logpoissonRE`. In other words, this function provides an estimate of the random effect distribution in PGM GLMM's with univariate random effects (e.g., models with random intercept).
- summaryGspline2
  provides computation of the pointwise posterior summaries (mean, quantiles) of a bivariate penalized Gaussian mixture fitted as a random effect distribution using `cumlogitRE` or `logpoissonRE`. In other words, this function provides an estimate of the random effect distribution in PGM GLMM's with bivariate random effects (e.g., models with random intercept and slope).

### Secondary functions from the package related to this methodology

- rgspline1, dgspline1
- rgspline2
- glmmAK.files2coda
- maxPosterProb
- momentsGMRF, rGMRF, dGMRF, dGMRF2

### Examples

- `ex-Toenail.pdf` - example 1 using the data set toenail. Among others, it shows in more detail use of functions cumlogitRE, summaryGspline1.
- `ex-Toenail.R` - code for the example 1
- `ex-Epileptic.pdf` - example 2 using the data set epilepticBC Among others, it shows in more detail use of functions logpoissonRE, summaryGspline2.
- `ex-Epileptic.R` - code for the example 2

# 3. Posterior computation

There are few functions in the package for general posterior computation which either supplement the coda package or slightly modify its functions:

- BPvalue
- densplotAK

# 4. Miscellaneous

The package also contains some functions which are either simple utilities or are related to some of my secondary interests and were written mainly for testing purposes.

- scanFH
- QuantileFun
- mfLand, mfPort
- Cgauss, cgauss
- Cclayton, cclayton
- Cplackett, cplackett

# 5. Datasets

Finally, there are some datasets, mostly taken from the literature, available in the package:

- toenail
- epileptic
- epilepticBC