项目作者: NErler

项目描述 :
Joint Analysis and Imputation of generalized linear models and linear mixed models with missing values
高级语言: R
项目地址: git://github.com/NErler/JointAI.git
创建时间: 2016-10-28T13:55:32Z
项目社区:https://github.com/NErler/JointAI

开源协议:

下载


" class="reference-link">JointAI: Joint Analysis and Imputation of Incomplete Data

CRAN_Status_Badge

Download
counter
codecov
R build
status

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:

  1. install.packages('JointAI')

Alternatively, you can install JointAI from GitHub:

  1. # install.packages("remotes")
  2. remotes::install_github("NErler/JointAI")

Main functions

JointAI provides the following main functions:

  1. lm_imp() # linear regression
  2. glm_imp() # generalized linear regression
  3. clm_imp() # cumulative logit model
  4. mlogit_imp() # multinomial logit model
  5. lognorm_imp() # log-normal regression
  6. betareg_imp() # beta regression
  7. lme_imp() / lmer_imp() # linear mixed model
  8. glme_imp() / glmer_imp() # generalized linear mixed model
  9. clmm_imp() # cumulative logit mixed model
  10. mlogitmm_imp() # multinomial logit model
  11. lognormmm_imp() # log-normal regression
  12. betamm_imp() # beta regression
  13. survreg_imp() # parametric (Weibull) survival model
  14. coxph_imp() # proportional hazards survival model
  15. 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

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

  1. md_pattern(NHANES, color = c('#460E1B', '#D10E3B'))

Fit a linear regression model with incomplete covariates

  1. lm1 <- lm_imp(SBP ~ gender + age + WC + alc + educ + bili,
  2. data = NHANES, n.iter = 500, progress.bar = 'none', seed = 2020)

Visualize the MCMC sample

  1. traceplot(lm1, col = c('#d4af37', '#460E1B', '#D10E3B'), ncol = 4)

  1. densplot(lm1, col = c('#d4af37', '#460E1B', '#D10E3B'), ncol = 4, lwd = 2)

Summarize the Result

  1. summary(lm1)
  2. #>
  3. #> Bayesian linear model fitted with JointAI
  4. #>
  5. #> Call:
  6. #> lm_imp(formula = SBP ~ gender + age + WC + alc + educ + bili,
  7. #> data = NHANES, n.iter = 500, seed = 2020, progress.bar = "none")
  8. #>
  9. #>
  10. #> Posterior summary:
  11. #> Mean SD 2.5% 97.5% tail-prob. GR-crit MCE/SD
  12. #> (Intercept) 87.662 8.6088 70.3830 104.899 0.00000 1.00 0.0271
  13. #> genderfemale -3.487 2.2407 -7.9563 0.818 0.10533 1.01 0.0258
  14. #> age 0.334 0.0683 0.1986 0.468 0.00000 1.01 0.0258
  15. #> WC 0.230 0.0721 0.0876 0.376 0.00133 1.00 0.0258
  16. #> alc>=1 6.419 2.3862 1.6656 11.112 0.00667 1.03 0.0358
  17. #> educhigh -2.805 2.0681 -6.9371 1.339 0.17067 1.00 0.0258
  18. #> bili -5.277 4.7332 -14.7727 3.596 0.25333 1.01 0.0275
  19. #>
  20. #> Posterior summary of residual std. deviation:
  21. #> Mean SD 2.5% 97.5% GR-crit MCE/SD
  22. #> sigma_SBP 13.5 0.725 12.2 15 1.01 0.0258
  23. #>
  24. #>
  25. #> MCMC settings:
  26. #> Iterations = 101:600
  27. #> Sample size per chain = 500
  28. #> Thinning interval = 1
  29. #> Number of chains = 3
  30. #>
  31. #> Number of observations: 186
  1. coef(lm1)
  2. #> $SBP
  3. #> (Intercept) genderfemale age WC alc>=1 educhigh
  4. #> 87.6622381 -3.4873104 0.3335133 0.2302755 6.4194926 -2.8054874
  5. #> bili sigma_SBP
  6. #> -5.2768560 13.5278177
  7. confint(lm1)
  8. #> $SBP
  9. #> 2.5% 97.5%
  10. #> (Intercept) 70.38301720 104.8986161
  11. #> genderfemale -7.95631510 0.8182921
  12. #> age 0.19857014 0.4678630
  13. #> WC 0.08761699 0.3756334
  14. #> alc>=1 1.66562640 11.1121370
  15. #> educhigh -6.93714769 1.3389344
  16. #> bili -14.77269911 3.5955383
  17. #> sigma_SBP 12.16165429 15.0367180