diff --git a/.zenodo.json b/.zenodo.json index 8c38369..27624cc 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "multimput: Using Multiple Imputation to Address Missing Data", - "version": "0.2.14", + "version": "0.2.15", "license": "GPL-3.0", "upload_type": "software", "description": "
Accompanying package for the paper: Working with population totals in the presence of missing data comparing imputation methods in terms of bias and precision. Published in 2017 in the Journal of Ornithology volume 158 page 603–615 (doi:10.1007/s10336-016-1404-9).<\/p>", diff --git a/CITATION.cff b/CITATION.cff index ad79081..4eac473 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -32,4 +32,4 @@ identifiers: value: 10.5281/zenodo.598331 - type: url value: https://inbo.github.io/multimput/ -version: 0.2.14 +version: 0.2.15 diff --git a/DESCRIPTION b/DESCRIPTION index ce550ad..48102d4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: multimput Title: Using Multiple Imputation to Address Missing Data -Version: 0.2.14 +Version: 0.2.15 Authors@R: c( person("Thierry", "Onkelinx", , "thierry.onkelinx@inbo.be", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-8804-4216", affiliation = "Research Institute for Nature and Forest (INBO)")), diff --git a/NEWS.md b/NEWS.md index 5558023..3f1bbe7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# multimput 0.2.15 + +* Bugfix in `hurdle_impute()` when selecting single covariates. + # multimput 0.2.14 * In case all imputed values are identical, `model_impute()` only runs a single diff --git a/R/hurdle_impute.R b/R/hurdle_impute.R index 79cff98..0113480 100644 --- a/R/hurdle_impute.R +++ b/R/hurdle_impute.R @@ -54,23 +54,31 @@ hurdle_impute <- function(presence, count) { # prepare covariates cv_count <- count@Data[ - , !colnames(count@Data) %in% c(count@Response, count@Minimum) + , !colnames(count@Data) %in% c(count@Response, count@Minimum), drop = FALSE ] cv_presence <- presence@Data[ - , !colnames(presence@Data) %in% c(presence@Response, presence@Minimum) + , !colnames(presence@Data) %in% c(presence@Response, presence@Minimum), + drop = FALSE ] common <- colnames(cv_count)[colnames(cv_count) %in% colnames(cv_presence)] common <- common[apply(cv_count[, common] == cv_presence[, common], 2, all)] extra_count <- colnames(cv_count)[!colnames(cv_count) %in% common] extra_presence <- colnames(cv_presence)[!colnames(cv_presence) %in% common] - ren_count <- cv_count[, extra_count[extra_count %in% extra_presence]] + ren_count <- cv_count[ + , extra_count[extra_count %in% extra_presence], drop = FALSE + ] colnames(ren_count) <- sprintf("count_%s", colnames(ren_count)) - ren_presence <- cv_presence[, extra_presence[extra_presence %in% extra_count]] + ren_presence <- cv_presence[ + , extra_presence[extra_presence %in% extra_count], drop = FALSE + ] colnames(ren_presence) <- sprintf("presence_%s", colnames(ren_presence)) cv <- cbind( - cv_count[, common], - cv_count[, extra_count[!extra_count %in% extra_presence]], ren_count, - cv_presence[, extra_presence[!extra_presence %in% extra_count]], + cv_count[, common, drop = FALSE], + cv_count[, extra_count[!extra_count %in% extra_presence], drop = FALSE], + ren_count, + cv_presence[ + , extra_presence[!extra_presence %in% extra_count], drop = FALSE + ], ren_presence ) if (nrow(count@Extra) == 0) { @@ -80,11 +88,16 @@ hurdle_impute <- function(presence, count) { count@Extra[[count@Response]], nrow = nrow(count@Extra), ncol = ncol(count_resp) ) - ren_count <- count@Extra[, extra_count[extra_count %in% extra_presence]] + ren_count <- count@Extra[ + , extra_count[extra_count %in% extra_presence], drop = FALSE + ] colnames(ren_count) <- sprintf("count_%s", colnames(ren_count)) cv_extra <- cbind( - count@Extra[, common], - count@Extra[, extra_count[!extra_count %in% extra_presence]], ren_count + count@Extra[, common, drop = FALSE], + count@Extra[ + , extra_count[!extra_count %in% extra_presence], drop = FALSE + ], + ren_count ) c( extra_presence[!extra_presence %in% extra_count], diff --git a/R/impute_inla.R b/R/impute_inla.R index 32ed156..312c023 100644 --- a/R/impute_inla.R +++ b/R/impute_inla.R @@ -108,10 +108,8 @@ setMethod( prob = hyperpar[[grep("zero-probability", colnames(hyperpar))]], size = hyperpar[[grep("size for nbinomial", colnames(hyperpar))]] ), - .f = function(n, eta, prob, size) { - rzinb0( - n = length(missing_obs), mu = exp(eta), prob = prob, size = size - ) + .f = function(eta, prob, size, n = length(missing_obs)) { + rzinb0(mu = exp(pmin(eta, 20)), prob = prob, size = size, n = n) } ), zeroinflatednbinomial1 = pmap_dfr( @@ -120,10 +118,8 @@ setMethod( prob = hyperpar[[grep("zero-probability", colnames(hyperpar))]], size = hyperpar[[grep("size for nbinomial", colnames(hyperpar))]] ), - .f = function(n, eta, prob, size) { - rzinb1( - n = length(missing_obs), mu = exp(eta), prob = prob, size = size - ) + .f = function(eta, prob, size, n = length(missing_obs)) { + rzinb1(mu = exp(eta), prob = prob, size = size, n = n) } ), zeroinflatedpoisson0 = map2_dfr( diff --git a/inst/CITATION b/inst/CITATION index d7d84f6..d37f57c 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -2,12 +2,12 @@ citHeader("To cite `multimput` in publications please use:") # begin checklist entry bibentry( bibtype = "Manual", - title = "multimput: Using Multiple Imputation to Address Missing Data. Version 0.2.14", + title = "multimput: Using Multiple Imputation to Address Missing Data. Version 0.2.15", author = c( author = c(person(given = "Thierry", family = "Onkelinx"), person(given = "Koen", family = "Devos"), person(given = "Paul", family = "Quataert"))), - year = 2024, + year = 2025, url = "https://inbo.github.io/multimput/", abstract = "Accompanying package for the paper: Working with population totals in the presence of missing data comparing imputation methods in terms of bias and precision. Published in 2017 in the Journal of Ornithology volume 158 page 603–615 (doi:10.1007/s10336-016-1404-9).", - textVersion = "Onkelinx, Thierry; Devos, Koen; Quataert, Paul (2024) multimput: Using Multiple Imputation to Address Missing Data. Version 0.2.14. https://inbo.github.io/multimput/", + textVersion = "Onkelinx, Thierry; Devos, Koen; Quataert, Paul (2025) multimput: Using Multiple Imputation to Address Missing Data. Version 0.2.15. https://inbo.github.io/multimput/", keywords = "missing data, multiple imputation, Rubin", doi = "10.5281/zenodo.598331", ) diff --git a/multimput.Rproj b/multimput.Rproj index e4a061f..4406325 100644 --- a/multimput.Rproj +++ b/multimput.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 67edd119-a857-4812-acf7-b7a36277956a RestoreWorkspace: Default SaveWorkspace: Default