An open API service indexing awesome lists of open source software.

https://github.com/nerler/jointai

Joint Analysis and Imputation of generalized linear models and linear mixed models with missing values
https://github.com/nerler/jointai

bayesian generalized-linear-models glm glmm imputation imputations jags joint-analysis linear-mixed-models linear-regression-models mcmc-sample mcmc-sampling missing-data missing-values rstats survival

Last synced: 5 months ago
JSON representation

Joint Analysis and Imputation of generalized linear models and linear mixed models with missing values

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.align = 'center'
)
```

# JointAI: Joint Analysis and Imputation of Incomplete Data

[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version-last-release/JointAI)](https://CRAN.R-project.org/package=JointAI)
[![](https://cranlogs.r-pkg.org/badges/grand-total/JointAI)](https://CRAN.R-project.org/package=JointAI)
[![Download counter](https://cranlogs.r-pkg.org/badges/JointAI)](https://cran.r-project.org/package=JointAI)
[![codecov](https://codecov.io/gh/NErler/JointAI/branch/master/graph/badge.svg)](https://app.codecov.io/gh/NErler/JointAI)
[![R build status](https://github.com/NErler/JointAI/workflows/R-CMD-check/badge.svg)](https://github.com/NErler/JointAI/actions)

The package **JointAI** provides functionality to perform joint analysis and
imputation of a range of model types in the Bayesian framework. Implemented are
(generalized) linear regression models and extensions thereof, models for
(un-/ordered) categorical data, as well as multi-level (mixed) versions of these
model types.

Moreover, survival models and joint models for longitudinal and survival data
are available. It is also possible to fit multiple models of mixed types
simultaneously. Missing values in (if present) will be imputed automatically.

**JointAI** performs some preprocessing of the data and creates a
[JAGS](https://mcmc-jags.sourceforge.io/) model, which will then automatically be
passed to [JAGS](https://mcmc-jags.sourceforge.io/) with the help of the R
package [**rjags**](https://CRAN.R-project.org/package=rjags).

Besides the main modelling functions, **JointAI** also provides a number of
functions to summarize and visualize results and incomplete data.


## Installation

**JointAI** can be installed from [CRAN](https://cran.r-project.org/):
```{r CRAN-instalation, eval = FALSE}
install.packages('JointAI')
```

Alternatively, you can install **JointAI** from GitHub:
```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("NErler/JointAI")
```

## Main functions
**JointAI** provides the following main functions:

``` r
lm_imp() # linear regression
glm_imp() # generalized linear regression
clm_imp() # cumulative logit model
mlogit_imp() # multinomial logit model
lognorm_imp() # log-normal regression
betareg_imp() # beta regression
lme_imp() / lmer_imp() # linear mixed model
glme_imp() / glmer_imp() # generalized linear mixed model
clmm_imp() # cumulative logit mixed model
mlogitmm_imp() # multinomial logit model
lognormmm_imp() # log-normal regression
betamm_imp() # beta regression
survreg_imp() # parametric (Weibull) survival model
coxph_imp() # proportional hazards survival model
JM_imp() # joint model for longitudinal and survival data
```

The functions use specification similar to that of well known standard functions
like `lm()` and `glm()` from base R, `nlme::lme()` (from the package
[**nlme**](https://CRAN.R-project.org/package=nlme)) , `lme4::lmer()` or
`lme4::glmer()` (from the package
[**lme4**](https://CRAN.R-project.org/package=lme4)) and `survival::survreg()`
and `survival::coxph()` (from the package
[**survival**](https://CRAN.R-project.org/package=survival)).

Functions `summary()`, `coef()`, `traceplot()` and `densplot()` provide a
summary of the posterior distribution and its visualization.

`GR_crit()` and `MC_error()` implement the Gelman-Rubin diagnostic for
convergence and the Monte Carlo error of the MCMC sample, respectively.

**JointAI** also provides functions for exploration of the distribution of the
data and missing values, export of imputed values and prediction.

## Minimal Example
### Visualize the observed data and missing data pattern
```{r, echo = FALSE}
par(mar = c(2.5, 3, 2.5, 1), mgp = c(2, 0.8, 0))
```

```{r, fig.width = 8, fig.height = 4, message = FALSE, collapse=TRUE}
library(JointAI)

plot_all(NHANES[c(1, 5:6, 8:12)], fill = '#D10E3B', border = '#460E1B', ncol = 4, breaks = 30)
```

```{r, fig.height = 5}
md_pattern(NHANES, color = c('#460E1B', '#D10E3B'))
```

### Fit a linear regression model with incomplete covariates

```{r fit_lm1, message = F}
lm1 <- lm_imp(SBP ~ gender + age + WC + alc + educ + bili,
data = NHANES, n.iter = 500, progress.bar = 'none', seed = 2020)
```

### Visualize the MCMC sample
```{r fig.width = 8, fig.height = 4, out.width = '100%', dpi = 300}
traceplot(lm1, col = c('#d4af37', '#460E1B', '#D10E3B'), ncol = 4)
```

```{r fig.width = 8, fig.height = 4, out.width = '100%', dpi = 300}
densplot(lm1, col = c('#d4af37', '#460E1B', '#D10E3B'), ncol = 4, lwd = 2)
```

### Summarize the Result
```{r}
summary(lm1)
```

```{r}
coef(lm1)

confint(lm1)
```