From 99b232971b4b3e1b409918c0ff35ab70fad4008c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20S=C3=B8rensen?= Date: Tue, 2 Jul 2024 19:05:07 +0200 Subject: [PATCH 1/2] added workaround option when not all variables are provided --- DESCRIPTION | 4 ++-- R/metagam_package.R | 3 +-- R/misc.R | 6 ++++++ R/plot_metagam.R | 5 ++++- man/metagam-package.Rd | 19 +++++++++++++++++++ news.md | 5 +++++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f689b09..1d17f92 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: metagam Type: Package Title: Meta-Analysis of Generalized Additive Models -Version: 0.4.0 +Version: 0.4.0.9000 Authors@R: c(person("Oystein", "Sorensen", email = "oystein.sorensen@psykologi.uio.no", role = c("aut", "cre"), @@ -31,7 +31,7 @@ Imports: ggplot2, metafor, rlang -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Suggests: roxygen2, knitr, diff --git a/R/metagam_package.R b/R/metagam_package.R index 243ad51..c603463 100755 --- a/R/metagam_package.R +++ b/R/metagam_package.R @@ -14,10 +14,9 @@ #' \code{\link{plot_heterogeneity}} can be used to study the meta-analytic fit #' computed by \code{\link{strip_rawdata}}. #' -#' @docType package #' @name metagam-package #' #' @importFrom rlang .data -NULL +_PACKAGE diff --git a/R/misc.R b/R/misc.R index d79b2b2..4d67fe5 100755 --- a/R/misc.R +++ b/R/misc.R @@ -88,6 +88,12 @@ extract_model_fits <- function(model, term_list, grid, type){ Map(function(term, xvar){ newdat <- create_newdat(xvar = xvar, grid = grid, type = type) + missing_vars <- setdiff(names(model$var.summary), colnames(newdat)) + for(mv in missing_vars) { + eval(parse(text = paste0("newdat$", mv, "<- rep(model$var.summary[['", + mv, "']][[1]], nrow(newdat))"))) + } + pred <- stats::predict(model, newdata = newdat, type = type, se.fit = TRUE, terms = term) diff --git a/R/plot_metagam.R b/R/plot_metagam.R index be1bf93..1c237bd 100755 --- a/R/plot_metagam.R +++ b/R/plot_metagam.R @@ -42,7 +42,6 @@ plot.metagam <- function(x, term = NULL, ci = "none", legend = FALSE, metadat <- x$meta_models$predictions } - xvars <- x$term_list[[term]]$xvars metadat <- metadat[, c(xvars, "estimate", "se")] @@ -63,6 +62,10 @@ plot.metagam <- function(x, term = NULL, ci = "none", legend = FALSE, ret$model <- nms[[ind]] ret }) + + common_cols <- Reduce(intersect, lapply(dat, colnames)) + dat <- lapply(dat, function(df) df[, common_cols, drop = FALSE]) + dat <- do.call(rbind, dat) dat <- dat[, c(xvars, "fit", "se.fit", "model")] diff --git a/man/metagam-package.Rd b/man/metagam-package.Rd index 617e72c..6d1c7f9 100755 --- a/man/metagam-package.Rd +++ b/man/metagam-package.Rd @@ -25,3 +25,22 @@ The main functions in the metagam package are described below. computed by \code{\link{strip_rawdata}}. } +\seealso{ +Useful links: +\itemize{ + \item \url{https://lifebrain.github.io/metagam/} + \item \url{https://github.com/Lifebrain/metagam} + \item Report bugs at \url{https://github.com/Lifebrain/metagam/issues} +} + +} +\author{ +\strong{Maintainer}: Oystein Sorensen \email{oystein.sorensen@psykologi.uio.no} (\href{https://orcid.org/0000-0003-0724-3542}{ORCID}) + +Authors: +\itemize{ + \item Andreas M. Brandmaier \email{brandmaier@mpib-berlin.mpg.de} (\href{https://orcid.org/0000-0001-8765-6982}{ORCID}) + \item Athanasia Mo Mowinckel \email{a.m.mowinckel@psykologi.uio.no} (\href{https://orcid.org/0000-0002-5756-0223}{ORCID}) +} + +} diff --git a/news.md b/news.md index 3273e4f..8da3b53 100755 --- a/news.md +++ b/news.md @@ -1,3 +1,8 @@ +# metagam (development versions) + +- Added a workaround which allows not providing the unused variables when the + terms argument is used. + # metagam version 0.4.0 - Added a `meta_only` option to `plot.metagam()`. From 6fcb15729cc978568125b3ae6b78b7d9cab17e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20S=C3=B8rensen?= Date: Tue, 2 Jul 2024 19:09:32 +0200 Subject: [PATCH 2/2] fixed error --- R/metagam_package.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/metagam_package.R b/R/metagam_package.R index c603463..d1147ec 100755 --- a/R/metagam_package.R +++ b/R/metagam_package.R @@ -14,9 +14,8 @@ #' \code{\link{plot_heterogeneity}} can be used to study the meta-analytic fit #' computed by \code{\link{strip_rawdata}}. #' +#' @docType package #' @name metagam-package #' #' @importFrom rlang .data -_PACKAGE - - +NULL