Skip to content

Commit

Permalink
Update support_blocks with master
Browse files Browse the repository at this point in the history
Merge branch 'master' into support_blocks

# Conflicts:
#	DESCRIPTION
#	NEWS.md
#	R/ampute.R
#	R/method.R
#	R/mice.R
#	R/mice.impute.rf.R
#	man/ampute.Rd
#	man/mice.Rd
#	man/mice.impute.rf.Rd
#	tests/testthat/test-parlmice.R
  • Loading branch information
stefvanbuuren committed Nov 22, 2024
2 parents 15321b4 + 448e8cf commit deac372
Show file tree
Hide file tree
Showing 170 changed files with 2,826 additions and 2,903 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected].0
uses: JamesIves/[email protected].9
with:
clean: false
branch: gh-pages
Expand Down
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mice
Type: Package
Version: 3.999.1
Version: 3.16.16
Title: Multivariate Imputation by Chained Equations
Date: 2024-04-17
Date: 2024-10-16
Authors@R: c(person("Stef", "van Buuren", role = c("aut","cre"),
email = "[email protected]"),
person("Karin", "Groothuis-Oudshoorn", role = "aut",
Expand Down Expand Up @@ -40,7 +40,9 @@ Authors@R: c(person("Stef", "van Buuren", role = c("aut","cre"),
person("Caspar", "van Lissa", role = "ctb",
email = "[email protected]"),
person("Hanne", "Oberman", role = "ctb",
email = "[email protected]"))
email = "[email protected]"),
person("Stephen", "Wade", role = "ctb",
email = "[email protected]"))
Maintainer: Stef van Buuren <[email protected]>
Depends:
R (>= 2.10.0)
Expand All @@ -67,6 +69,7 @@ Suggests:
furrr,
haven,
knitr,
literanger,
lme4,
MASS,
miceadds,
Expand Down Expand Up @@ -99,6 +102,4 @@ URL: https://github.com/amices/mice,
BugReports: https://github.com/amices/mice/issues
LinkingTo: cpp11, Rcpp
License: GPL (>= 2)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
VignetteBuilder: knitr
RoxygenNote: 7.3.2
24 changes: 24 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@
## -----------------------------------------------------------


# mice 3.16.16

* Prevent `as.mids()` from filling the `imp` object for complete variables

# mice 3.16.15

* Initialize single-variables blocks in `make.method()` in a more efficient way (resolves #672)

# mice 3.16.14

* Fixes a bug during initialization of factor values

# mice 3.16.13

* Adds support for the `literanger` package for `rf` imputation that is about twice as fast as `ranger` (#648). Thanks @stephematician for the contribution.

# mice 3.16.12

* Fixes an installation problem when `Rprofile` prints to `stdout` on Fedora, R version 4.1.3 (#646, #647). Thanks @brookslogan for the fix.

# mice 3.16.11

* Repairs lost braces in the documentation

# mice 3.16.10

* Adds support for non-syntactic variables names with backticks (#631)
Expand Down
23 changes: 13 additions & 10 deletions R/ampute.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@
#'
#' For an example and more explanation about how the arguments interact with each other,
#' we refer to the vignette
#' [Generate missing values with ampute](https://rianneschouten.github.io/mice_ampute/vignette/ampute.html)
#' The amputation methodology is published in \doi{10.1080/00949655.2018.1491577}.
#' \href{https://rianneschouten.github.io/mice_ampute/vignette/ampute.html}{Generate missing values with ampute}
#' The amputation methodology is published in
#' \doi{10.1080/00949655.2018.1491577}
#'
#' @param data A complete data matrix or data frame. Values should be numeric.
#' Categorical variables should have been transformed to dummies.
Expand Down Expand Up @@ -160,21 +161,23 @@
#' incomplete data sets.* pp. 110-113. Dissertation. Rotterdam: Erasmus University.
#'
#' Schouten, R.M., Lugtig, P and Vink, G. (2018)
#' {Generating missing values for simulation purposes: A multivariate amputation procedure.}.
#' *Journal of Statistical Computation and Simulation*, 88(15): 1909-1930.
#' Generating missing values for simulation purposes: A multivariate
#' amputation procedure.
#' \emph{Journal of Statistical Computation and Simulation}, 88(15): 1909-1930.
#' \doi{10.1080/00949655.2018.1491577}
#'
#' Schouten, R.M. and Vink, G. (2018){The Dance of the Mechanisms: How Observed Information Influences the Validity of Missingness Assumptions}.
#' *Sociological Methods and Research*, 50(3): 1243-1258.
#' Schouten, R.M. and Vink, G. (2018) The Dance of the Mechanisms: How Observed
#' Information Influences the Validity of Missingness Assumptions.
#' \emph{Sociological Methods and Research}, 50(3): 1243-1258.
#' \doi{10.1177/0049124118799376}
#'
#' Van Buuren, S., Brand, J.P.L., Groothuis-Oudshoorn, C.G.M., Rubin, D.B. (2006)
#' {Fully conditional specification in multivariate imputation.}
#' *Journal of Statistical Computation and Simulation*, 76(12): 1049-1064.
#' Fully conditional specification in multivariate imputation.
#' \emph{Journal of Statistical Computation and Simulation}, 76(12): 1049-1064.
#' \doi{10.1080/10629360600810434}
#'
#' Van Buuren, S. (2018)
#' [*Flexible Imputation of Missing Data. Second Edition.*](https://stefvanbuuren.name/fimd)
#' Van Buuren, S. (2018).
#' \emph{Flexible Imputation of Missing Data. Second Edition.}
#' Chapman & Hall/CRC. Boca Raton, FL.
#'
#' Vink, G. (2016) Towards a standardized evaluation of multiple imputation routines.
Expand Down
2 changes: 1 addition & 1 deletion R/as.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ as.mids <- function(long, where = NULL, .imp = ".imp", .id = ".id") {
names <- names(ini$imp)
for (i in seq_along(names)) {
varname <- names[i]
if (!is.null(ini$imp[[varname]])) {
if (nrow(ini$imp[[varname]])) {
for (j in seq_len(m)) {
idx <- imps == j & where[, varname]
ini$imp[[varname]][j] <- long[idx, varname]
Expand Down
2 changes: 1 addition & 1 deletion R/initialize.imp.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ initialize.imp <- function(data, m, ignore, where, blocks, visitSequence,
imp[[j]][, i] <- data.init[wy, j]
} else {
if (is.factor(y)) {
imp[[j]][, i] <- sample(levels(y), nrow(data))
imp[[j]][, i] <- sample(levels(y), nrow(data), replace = TRUE)
} else {
imp[[j]][, i] <- rnorm(nrow(data))
}
Expand Down
5 changes: 3 additions & 2 deletions R/mice-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
#'
#' @section Methodology:
#'
#' The \pkg{mice} software was published in the {Journal of Statistical Software} (Van Buuren and Groothuis-Oudshoorn, 2011). \doi{10.18637/jss.v045.i03}
#' The first application of the method
#' The \pkg{mice} software was published in the
#' \emph{Journal of Statistical Software} (Van Buuren and Groothuis-Oudshoorn, 2011).
#' \doi{10.18637/jss.v045.i03}. The first application of the method
#' concerned missing blood pressure data (Van Buuren et. al., 1999).
#' The term *Fully Conditional Specification* was introduced in 2006 to describe a general class of methods that specify imputations model for multivariate data as a set of conditional distributions (Van Buuren et. al., 2006). Further details on mixes of variables and applications can be found in the book
#' [*Flexible Imputation of Missing Data. Second Edition.*](https://stefvanbuuren.name/fimd/)
Expand Down
6 changes: 3 additions & 3 deletions R/mice.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
#' \doi{10.18637/jss.v045.i03}
#'
#' Van Buuren, S. (2018).
#' [*Flexible Imputation of Missing Data. Second Edition.*](https://stefvanbuuren.name/fimd/sec-FCS.html#sec:MICE)
#' \emph{Flexible Imputation of Missing Data. Second Edition.}
#' Chapman & Hall/CRC. Boca Raton, FL.
#'
#' Van Buuren, S., Brand, J.P.L., Groothuis-Oudshoorn C.G.M., Rubin, D.B. (2006)
Expand All @@ -354,8 +354,8 @@
#' Research*, **16**, 3, 219--242.
#'
#' Van Buuren, S., Boshuizen, H.C., Knook, D.L. (1999) Multiple imputation of
#' missing blood pressure covariates in survival analysis. *Statistics in
#' Medicine*, **18**, 681--694.
#' missing blood pressure covariates in survival analysis.
#' \emph{Statistics in Medicine}, \bold{18}, 681--694.
#'
#' Brand, J.P.L. (1999) *Development, implementation and evaluation of
#' multiple imputation strategies for the statistical analysis of incomplete
Expand Down
4 changes: 3 additions & 1 deletion R/mice.impute.pmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
#' \item{Calculate \eqn{\dot\beta = \hat\beta + \dot\sigma\dot z_1 V^{1/2}}.}
#' \item{Calculate \eqn{\dot\eta(i,j)=|X_{{obs},[i]|}\hat\beta-X_{{mis},[j]}\dot\beta}
#' with \eqn{i=1,\dots,n_1} and \eqn{j=1,\dots,n_0}.}
#' \item{Construct \eqn{n_0} sets \eqn{Z_j}, each containing \eqn{d} candidate donors, from Y_{obs} such that \eqn{\sum_d\dot\eta(i,j)} is minimum for all \eqn{j=1,\dots,n_0}. Break ties randomly.}
#' \item{Construct \eqn{n_0} sets \eqn{Z_j}, each containing \eqn{d}
#' candidate donors, from \eqn{y_{obs}} such that \eqn{\sum_d\dot\eta(i,j)} is
#' minimum for all \eqn{j=1,\dots,n_0}. Break ties randomly.}
#' \item{Draw one donor \eqn{i_j} from \eqn{Z_j} randomly for \eqn{j=1,\dots,n_0}.}
#' \item{Calculate imputations \eqn{\dot y_j = y_{i_j}} for \eqn{j=1,\dots,n_0}.}
#' }
Expand Down
46 changes: 34 additions & 12 deletions R/mice.impute.rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
#' @inheritParams mice.impute.pmm
#' @param ntree The number of trees to grow. The default is 10.
#' @param rfPackage A single string specifying the backend for estimating the
#' random forest. The default backend is the `ranger` package. The only
#' alternative currently implemented is the `randomForest` package, which
#' used to be the default in mice 3.13.10 and earlier.
#' random forest. The default backend is the \code{ranger} package. An
#' alternative is \code{literanger} which predicts faster but does not support
#' all forest types and split rules from \code{ranger}. Also implemented as
#' an alternative is the \code{randomForest} package, which used to be the
#' default in mice 3.13.10 and earlier.
#' @param \dots Other named arguments passed down to
#' `mice:::install.on.demand()`, `randomForest::randomForest()`,
#' `randomForest:::randomForest.default()`, and `ranger::ranger()`.
#' @return Vector with imputed data, same type as `y`, and of length
#' `sum(wy)`
#' \code{mice:::install.on.demand()}, \code{randomForest::randomForest()},
#' \code{randomForest:::randomForest.default()}, \code{ranger::ranger()}, and
#' \code{literanger::train()}.
#' @return Vector with imputed data, same type as \code{y}, and of length
#' \code{sum(wy)}
#' @details
#' Imputation of `y` by random forests. The method
#' calls `randomForrest()` which implements Breiman's random forest
Expand Down Expand Up @@ -43,9 +46,10 @@
#' Van Buuren, S. (2018).
#' [*Flexible Imputation of Missing Data. Second Edition.*](https://stefvanbuuren.name/fimd/sec-cart.html)
#' Chapman & Hall/CRC. Boca Raton, FL.
#' @seealso [mice()], [mice.impute.cart()],
#' [randomForest::randomForest()]
#' [ranger::ranger()]
#' @seealso \code{\link{mice}}, \code{\link{mice.impute.cart}},
#' \code{\link[randomForest]{randomForest}},
#' \code{\link[ranger]{ranger}},
#' \code{\link[literanger]{train}}
#' @family univariate imputation functions
#' @keywords datagen
#' @examples
Expand All @@ -55,7 +59,8 @@
#' }
#' @export
mice.impute.rf <- function(y, ry, x, wy = NULL, ntree = 10,
rfPackage = c("ranger", "randomForest"), ...) {
rfPackage = c("ranger", "randomForest", "literanger"),
...) {
rfPackage <- match.arg(rfPackage)

if (is.null(wy)) wy <- !ry
Expand All @@ -69,11 +74,14 @@ mice.impute.rf <- function(y, ry, x, wy = NULL, ntree = 10,
# Find eligible donors
f <- switch(rfPackage,
randomForest = .randomForest.donors,
ranger = .ranger.donors
ranger = .ranger.donors,
literanger = .literanger.donor
)

forest <- f(xobs, xmis, yobs, ntree, ...)

# Short-circuit when using literanger interface
if (rfPackage == "literanger") return(forest)
# Sample from donors
if (nmis == 1) forest <- array(forest, dim = c(1, ntree))
apply(forest, MARGIN = 1, FUN = function(s) sample(unlist(s), 1))
Expand Down Expand Up @@ -124,3 +132,17 @@ mice.impute.rf <- function(y, ry, x, wy = NULL, ntree = 10,

sapply(seq_len(ntree), FUN = select_donors)
}

# Find eligible donors using the literanger package
.literanger.donor <- function(xobs, xmis, yobs, ntree, ...) {
install.on.demand("literanger", ...)

lr_formals <- names(formals(literanger::train))
dots <- list(...)
dots <- dots[intersect(names(dots), setdiff(lr_formals, c('x', 'y')))]

fit <- do.call(
literanger::train, c(list(x = xobs, y = yobs, n_tree = ntree), dots)
)
predict(object = fit, newdata = xmis, prediction_type = "inbag")$values
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set.seed(1)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/mice)](https://cran.r-project.org/package=mice)
[![](https://cranlogs.r-pkg.org/badges/mice)](https://cran.r-project.org/package=mice)
[![R-CMD-check](https://github.com/amices/mice/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/amices/mice/actions/workflows/R-CMD-check.yaml)
[![](https://img.shields.io/badge/github%20version-3.16.10-orange.svg)](https://amices.org/mice/)
[![](https://img.shields.io/badge/github%20version-3.16.16-orange.svg)](https://amices.org/mice/)
<!-- badges: end -->

## [Multivariate Imputation by Chained Equations](https://amices.org/mice/)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/mice)](https://cran.r-project.org/package=mice)
[![](https://cranlogs.r-pkg.org/badges/mice)](https://cran.r-project.org/package=mice)
[![R-CMD-check](https://github.com/amices/mice/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/amices/mice/actions/workflows/R-CMD-check.yaml)
[![](https://img.shields.io/badge/github%20version-3.16.10-orange.svg)](https://amices.org/mice/)
[![](https://img.shields.io/badge/github%20version-3.16.16-orange.svg)](https://amices.org/mice/)
<!-- badges: end -->

## [Multivariate Imputation by Chained Equations](https://amices.org/mice/)
Expand Down
22 changes: 11 additions & 11 deletions man/D1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions man/D2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit deac372

Please sign in to comment.