-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.Rmd
148 lines (108 loc) · 5.03 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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 <img src="man/figures/logo.png" align="right" alt="" width="160" />
<!-- badges: start -->
[![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)
<!-- badges: end -->
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)
```