JointAI v1.0.2
Monthly downloads
Joint Analysis and Imputation of Incomplete Data
Joint analysis and imputation of incomplete data in the Bayesian
framework, using (generalized) linear (mixed) models and extensions there of,
survival models, or joint models for longitudinal and survival data.
Incomplete covariates, if present, are automatically imputed.
The package performs some preprocessing of the data and creates a 'JAGS'
model, which will then automatically be passed to 'JAGS'
<http://mcmc-jags.sourceforge.net/> with the help of
the package 'rjags'.
Readme
JointAI: Joint Analysis and Imputation of Incomplete Data 
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 model, which will then automatically be passed to JAGS with the help of the R 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:
install.packages('JointAI')
Alternatively, you can install JointAI from GitHub:
# install.packages("remotes")
remotes::install_github("NErler/JointAI")
Main functions
JointAI provides the following main functions:
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) ,
lme4::lmer()
or lme4::glmer()
(from the package
lme4) and
survival::survreg()
and survival::coxph()
(from the 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
library(JointAI)
plot_all(NHANES[c(1, 5:6, 8:12)], fill = '#D10E3B', border = '#460E1B', ncol = 4, breaks = 30)
md_pattern(NHANES, color = c('#460E1B', '#D10E3B'))
Fit a linear regression model with incomplete covariates
lm1 <- lm_imp(SBP ~ gender + age + WC + alc + educ + bili,
data = NHANES, n.iter = 500, progress.bar = 'none', seed = 2020)
Visualize the MCMC sample
traceplot(lm1, col = c('#d4af37', '#460E1B', '#D10E3B'), ncol = 4)
densplot(lm1, col = c('#d4af37', '#460E1B', '#D10E3B'), ncol = 4, lwd = 2)
Summarize the Result
summary(lm1)
#>
#> Bayesian linear model fitted with JointAI
#>
#> Call:
#> lm_imp(formula = SBP ~ gender + age + WC + alc + educ + bili,
#> data = NHANES, n.iter = 500, seed = 2020, progress.bar = "none")
#>
#>
#> Posterior summary:
#> Mean SD 2.5% 97.5% tail-prob. GR-crit MCE/SD
#> (Intercept) 87.984 9.0412 70.110 107.092 0.00000 1.00 0.0258
#> genderfemale -3.501 2.2488 -8.039 1.059 0.10400 1.00 0.0258
#> age 0.333 0.0713 0.199 0.471 0.00000 1.01 0.0275
#> WC 0.226 0.0757 0.072 0.373 0.00267 1.00 0.0258
#> alc>=1 6.509 2.3290 1.899 10.859 0.01067 1.00 0.0270
#> educhigh -2.780 2.1237 -6.886 1.248 0.19733 1.00 0.0258
#> bili -5.173 4.8315 -14.599 4.109 0.28800 1.01 0.0303
#>
#> Posterior summary of residual std. deviation:
#> Mean SD 2.5% 97.5% GR-crit MCE/SD
#> sigma_SBP 13.6 0.739 12.3 15.1 1.01 0.0289
#>
#>
#> MCMC settings:
#> Iterations = 101:600
#> Sample size per chain = 500
#> Thinning interval = 1
#> Number of chains = 3
#>
#> Number of observations: 186
coef(lm1)
#> $SBP
#> (Intercept) genderfemale age WC alc>=1 educhigh
#> 87.9839157 -3.5010429 0.3329532 0.2262894 6.5093606 -2.7800225
#> bili sigma_SBP
#> -5.1730414 13.5670206
confint(lm1)
#> $SBP
#> 2.5% 97.5%
#> (Intercept) 70.11037933 107.0920122
#> genderfemale -8.03905105 1.0594821
#> age 0.19919441 0.4705334
#> WC 0.07201019 0.3734877
#> alc>=1 1.89897665 10.8594963
#> educhigh -6.88561508 1.2481772
#> bili -14.59898407 4.1089909
#> sigma_SBP 12.25273343 15.1162472
Functions in JointAI
Name | Description | |
densplot | Plot the posterior density from object of class JointAI | |
list_models | List model details | |
MC_error | Calculate and plot the Monte Carlo error | |
model_imp | Joint Analysis and Imputation of incomplete data | |
ns | Generate a Basis Matrix for Natural Cubic Splines | |
JointAIObject | Fitted object of class 'JointAI' | |
get_MIdat | Extract multiple imputed datasets from an object of class JointAI | |
get_modeltype | Identify the general model type from the covariate model type | |
get_Mlist | Re-create the full Mlist from a "JointAI" object | |
extract_state | Return the current state of a 'JointAI' model | |
longDF | Longitudinal example dataset | |
residuals.JointAI | Extract residuals from an object of class JointAI | |
get_missinfo | Obtain a summary of the missing values involved in an object of class JointAI | |
set_refcat | Specify reference categories for all categorical covariates in the model | |
parameters | Parameter names of an JointAI object | |
JointAI | JointAI: Joint Analysis and Imputation of Incomplete Data | |
plot.JointAI | Plot an object object inheriting from class 'JointAI' | |
clean_survname | Convert a survival outcome to a model name | |
PBC | PBC data | |
predDF | Create a new data frame for prediction | |
default_hyperpars | Get the default values for hyper-parameters | |
md_pattern | Missing data pattern | |
wideDF | Cross-sectional example dataset | |
plot_all | Visualize the distribution of all variables in the dataset | |
traceplot | Create traceplots for a MCMC sample | |
summary.JointAI | Summarize the results from an object of class JointAI | |
plot_imp_distr | Plot the distribution of observed and imputed values | |
sharedParams | Parameters used by several functions in JointAI | |
rd_vcov | Extract the random effects variance covariance matrix Returns the posterior mean of the variance-covariance matrix/matrices of the random effects in a fitted JointAI object. | |
predict.JointAI | Predict values from an object of class JointAI | |
remove_lhs | Remove the left hand side of a (list of) formula(s) | |
simLong | Simulated Longitudinal Data in Long and Wide Format | |
NHANES | National Health and Nutrition Examination Survey (NHANES) Data | |
GR_crit | Gelman-Rubin criterion for convergence | |
add_samples | Continue sampling from an object of class JointAI | |
all_vars | Version of all.vars() that can handle lists of formulas | |
bs | Generate a Basis Matrix for Natural Cubic Splines | |
Surv | Create a Survival Object | |
get_family | Identify the family from the covariate model type | |
No Results! |
Vignettes of JointAI
Last month downloads
Details
URL | https://nerler.github.io/JointAI/ |
License | GPL (>= 2) |
BugReports | https://github.com/nerler/JointAI/issues/ |
LazyData | TRUE |
RoxygenNote | 7.1.1 |
SystemRequirements | JAGS (http://mcmc-jags.sourceforge.net/) |
VignetteBuilder | knitr |
Encoding | UTF-8 |
RdMacros | mathjaxr |
Config/testthat/edition | 3 |
Language | en-GB |
NeedsCompilation | no |
Packaged | 2021-01-13 20:04:37 UTC; erler |
Repository | CRAN |
Date/Publication | 2021-01-13 21:00:02 UTC |
Include our badge in your README
[](http://www.rdocumentation.org/packages/JointAI)