Title: | Meta-Analysis of Generalized Additive Models |
---|---|
Description: | Meta-analysis of generalized additive models and generalized additive mixed models. A typical use case is when data cannot be shared across locations, and an overall meta-analytic fit is sought. 'metagam' provides functionality for removing individual participant data from models computed using the 'mgcv' and 'gamm4' packages such that the model objects can be shared without exposing individual data. Furthermore, methods for meta-analysing these fits are provided. The implemented methods are described in Sorensen et al. (2020), <doi:10.1016/j.neuroimage.2020.117416>, extending previous works by Schwartz and Zanobetti (2000) and Crippa et al. (2018) <doi:10.6000/1929-6029.2018.07.02.1>. |
Authors: | Oystein Sorensen [aut, cre] , Andreas M. Brandmaier [aut] , Athanasia Mo Mowinckel [aut] |
Maintainer: | Oystein Sorensen <[email protected]> |
License: | GPL-3 |
Version: | 0.4.0.9000 |
Built: | 2024-10-31 18:38:36 UTC |
Source: | https://github.com/Lifebrain/metagam |
The main functions in the metagam package are described below.
The function strip_rawdata
takes a
fit produced by functions in packages mgcv
or gamm4
and
removes all individual participants data.
The function metagam
takes a list of
fits produced by strip_rawdata
and computes meta-analytic
fits.
The functions plot_dominance
and
plot_heterogeneity
can be used to study the meta-analytic fit
computed by strip_rawdata
.
Maintainer: Oystein Sorensen [email protected] (ORCID)
Authors:
Andreas M. Brandmaier [email protected] (ORCID)
Athanasia Mo Mowinckel [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/Lifebrain/metagam/issues
Meta-analysis of generalized additive models
metagam( models, grid = NULL, grid_size = 100, type = "iterms", terms = NULL, method = "FE", nsim = NULL, ci_alpha = 0.05, restrict_range = NULL )
metagam( models, grid = NULL, grid_size = 100, type = "iterms", terms = NULL, method = "FE", nsim = NULL, ci_alpha = 0.05, restrict_range = NULL )
models |
List of generalized additive models, each of which has been
returned by |
grid |
Grid of values of the explanatory variables over which to compute
the estimated smooth terms. Defaults to |
grid_size |
Numeric value giving the number of elements to use in the
grid of explanatory variables when |
type |
Type of prediction to use. Defaults to |
terms |
Character vector of terms, smooth or parametric, to be included
in function estimate. Only used if |
method |
Method of meta analysis, passed on to |
nsim |
Number of simulations to conduct in order to compute p-values and
simultaneous confidence bands for the meta-analytic fit. Defaults to
|
ci_alpha |
Significance level for simultaneous confidence bands. Ignored
if |
restrict_range |
Character vector of explanatory variables to restrict
such that only values within the range for each cohort contribute to the
meta-analysis. Default to |
It is currently assumed that all models have been fit with the same smooth terms, although they do not need to have the same basis functions or knot placement. Future versions will also include meta-analysis of parametric terms in the models.
p-values are truncated below at 1e-16 before computing meta-analytic p-values to ensure that no values are identically zero, which would imply that the alternative hypothesis be true with no uncertainty.
An object of type metagam.
library(metagam) library(mgcv) ## Create 5 datasets set.seed(1234) datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE)) ## Fit a GAM in each dataset, then use strip_rawdata() to remove ## individual participant data models <- lapply(datasets, function(dat){ ## This uses the gam() function from mgcv model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat) ## This uses strip_rawdata() from metagam strip_rawdata(model) }) ## Next, we meta-analyze the models. ## It is often most convenient to analyze a single term at a time. We focus on s(x1). meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30) ## We can print some information summary(meta_analysis) ## We can plot the meta-analytic fit together with the individual fits plot(meta_analysis) plot(meta_analysis, ci = "pointwise") ## We can also compute p-values and simultaneous confidence intervals, by setting the nsim argument. ## For details, see the separate vignette. ## Not run: meta_analysis <- metagam(models, terms = "s(x0)", grid_size = 30, nsim = 1000) summary(meta_analysis) plot(meta_analysis, ci = "both") plot(meta_analysis, ci = "simultaneous") ## End(Not run)
library(metagam) library(mgcv) ## Create 5 datasets set.seed(1234) datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE)) ## Fit a GAM in each dataset, then use strip_rawdata() to remove ## individual participant data models <- lapply(datasets, function(dat){ ## This uses the gam() function from mgcv model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat) ## This uses strip_rawdata() from metagam strip_rawdata(model) }) ## Next, we meta-analyze the models. ## It is often most convenient to analyze a single term at a time. We focus on s(x1). meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30) ## We can print some information summary(meta_analysis) ## We can plot the meta-analytic fit together with the individual fits plot(meta_analysis) plot(meta_analysis, ci = "pointwise") ## We can also compute p-values and simultaneous confidence intervals, by setting the nsim argument. ## For details, see the separate vignette. ## Not run: meta_analysis <- metagam(models, terms = "s(x0)", grid_size = 30, nsim = 1000) summary(meta_analysis) plot(meta_analysis, ci = "both") plot(meta_analysis, ci = "simultaneous") ## End(Not run)
When a random effects meta analysis has been used, this function visualizes how the between-study standard deviation depends on the explanatory variable.
plot_between_study_sd(x)
plot_between_study_sd(x)
x |
Object returned from |
A ggplot
object.
library("mgcv") set.seed(1233) shifts <- c(0, .5, 1, 0, -1) datasets <- lapply(shifts, function(x) { ## Simulate data dat <- gamSim(scale = .1, verbose = FALSE) ## Add a shift dat$y <- dat$y + x * dat$x2^2 ## Return data dat }) models <- lapply(datasets, function(dat){ b <- gam(y ~ s(x2, bs = "cr"), data = dat) strip_rawdata(b) }) meta_analysis <- metagam(models, method = "REML") plot_between_study_sd(meta_analysis)
library("mgcv") set.seed(1233) shifts <- c(0, .5, 1, 0, -1) datasets <- lapply(shifts, function(x) { ## Simulate data dat <- gamSim(scale = .1, verbose = FALSE) ## Add a shift dat$y <- dat$y + x * dat$x2^2 ## Return data dat }) models <- lapply(datasets, function(dat){ b <- gam(y ~ s(x2, bs = "cr"), data = dat) strip_rawdata(b) }) meta_analysis <- metagam(models, method = "REML") plot_between_study_sd(meta_analysis)
Plots the (relative) contribution of the individual GAMs to each data point on a given axis. It shows whether and how parts of the axis are dominated by certain individual GAMs.
plot_dominance(x, term = NULL, relative = TRUE, width = NULL)
plot_dominance(x, term = NULL, relative = TRUE, width = NULL)
x |
Object returned by |
term |
Character specifying which smooth term to plot. Default to
|
relative |
Logical specifying whether to have relative or absolute
scales. Defaults to |
width |
Width of bars. Default to |
A ggplot object.
# See the vignette, either at https://lifebrain.github.io/metagam/articles/articles/dominance.html # or by typing the following in the console: # vignette("Dominance")
# See the vignette, either at https://lifebrain.github.io/metagam/articles/articles/dominance.html # or by typing the following in the console: # vignette("Dominance")
Heterogeneity Plot
plot_heterogeneity(x, term = NULL, type = "Q", alpha_thresh = 0.05)
plot_heterogeneity(x, term = NULL, type = "Q", alpha_thresh = 0.05)
x |
Object returned by |
term |
Character specifying which smooth term to plot. Defaults to |
type |
Character specifying which type of plot. Either |
alpha_thresh |
Significance level. Defaults to |
This plot visualizes the heterogeneity along the given axis, using Cochran's Q test.
A ggplot object.
# See the vignette, either at https://lifebrain.github.io/metagam/articles/heterogeneity.html # or by typing the following in the console: # vignette("heterogeneity")
# See the vignette, either at https://lifebrain.github.io/metagam/articles/heterogeneity.html # or by typing the following in the console: # vignette("heterogeneity")
Plot the meta-analytic estimate of a smooth term along with the separate fits in each cohort.
## S3 method for class 'metagam' plot(x, term = NULL, ci = "none", legend = FALSE, only_meta = FALSE, ...)
## S3 method for class 'metagam' plot(x, term = NULL, ci = "none", legend = FALSE, only_meta = FALSE, ...)
x |
Object returned by |
term |
The smooth term to plot. Defaults to |
ci |
Type of confidence bands to plot around the meta-analytic fit.
Defaults to "none", which means the no bands are plotted. Other options are
"simultaneous", "pointwise", and "both". Simultaneous confidence bands
require that |
legend |
Logical specifying whether or not to plot a legend. Defaults to
|
only_meta |
Logical specifying whether to include the fits for each
study, or to only plot the meta-analytic fit. Defaults to |
... |
Other arguments to plot. |
The function is called for its side effect of producing a plot.
library(metagam) library(mgcv) ## Create 5 datasets set.seed(1234) datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE)) ## Fit a GAM in each dataset, then use strip_rawdata() to remove ## individual participant data models <- lapply(datasets, function(dat){ ## This uses the gam() function from mgcv model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat) ## This uses strip_rawdata() from metagam strip_rawdata(model) }) ## Next, we meta-analyze the models. ## It is often most convenient to analyze a single term at a time. We focus on s(x1). meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30) ## We can print some information summary(meta_analysis) ## We can plot the meta-analytic fit together with the individual fits plot(meta_analysis) plot(meta_analysis, ci = "pointwise") ## We can also compute p-values and simultaneous confidence intervals, by setting the nsim argument. ## For details, see the separate vignette. ## Not run: meta_analysis <- metagam(models, terms = "s(x0)", grid_size = 30, nsim = 1000) summary(meta_analysis) plot(meta_analysis, ci = "both") plot(meta_analysis, ci = "simultaneous") ## End(Not run)
library(metagam) library(mgcv) ## Create 5 datasets set.seed(1234) datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE)) ## Fit a GAM in each dataset, then use strip_rawdata() to remove ## individual participant data models <- lapply(datasets, function(dat){ ## This uses the gam() function from mgcv model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat) ## This uses strip_rawdata() from metagam strip_rawdata(model) }) ## Next, we meta-analyze the models. ## It is often most convenient to analyze a single term at a time. We focus on s(x1). meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30) ## We can print some information summary(meta_analysis) ## We can plot the meta-analytic fit together with the individual fits plot(meta_analysis) plot(meta_analysis, ci = "pointwise") ## We can also compute p-values and simultaneous confidence intervals, by setting the nsim argument. ## For details, see the separate vignette. ## Not run: meta_analysis <- metagam(models, terms = "s(x0)", grid_size = 30, nsim = 1000) summary(meta_analysis) plot(meta_analysis, ci = "both") plot(meta_analysis, ci = "simultaneous") ## End(Not run)
Print method for metagam objects.
## S3 method for class 'metagam' print(x, ...)
## S3 method for class 'metagam' print(x, ...)
x |
Object of class metagam. |
... |
Other arguments (not used). |
The function invisibly returns its input argument x
.
Print method for striprawdata
## S3 method for class 'striprawdata' print(x, ...)
## S3 method for class 'striprawdata' print(x, ...)
x |
Object of class |
... |
Other arguments. |
The function invisibly returns its argument.
Print output from summary of metagam fit.
## S3 method for class 'summary.metagam' print(x, digits = 8, ...)
## S3 method for class 'summary.metagam' print(x, digits = 8, ...)
x |
A summary.metagam object |
digits |
Number of digits to print for meta-analytic p-values |
... |
Other arguments |
The function invisibly returns its input argument x
.
This function removes all individual participant data from a generalized additive model object, while keeping aggregated quantities. The resulting object can be shared without exposing individual participant data.
strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'list' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'gamm' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'bam' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'gam' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...)
strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'list' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'gamm' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'bam' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...) ## S3 method for class 'gam' strip_rawdata(model, path = NULL, save_ranges = TRUE, ...)
model |
A model fitted using |
path |
Optional path in which to save the object as a |
save_ranges |
Logical specifying whether to save the ranges of each
variable used by the model. For numeric variables this amounts to the minimum
and maximum, and for factors all levels are saved. The values will be in the
list element |
... |
Other arguments (not used). |
Thin plate regression splines (bs='tp'
and bs='ts'
) and Duchon splines bs='ds'
are currently not supported, since for these splines mgcv
requires the unique values of the explanatory variables for each smooth term for the predict
method to work. Future updates to this package will fix this.
Model object with individual participant data removed.
strip_rawdata(list)
: Strip rawdata from list object returned by gamm4
strip_rawdata(gamm)
: Strip rawdata from gamm object
strip_rawdata(bam)
: Strip rawdata from gam object
strip_rawdata(gam)
: Strip rawdata from gam object
library(metagam) library(mgcv) ## Create 5 datasets set.seed(1234) datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE)) ## Fit a GAM in each dataset, then use strip_rawdata() to remove ## individual participant data models <- lapply(datasets, function(dat){ ## This uses the gam() function from mgcv model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat) ## This uses strip_rawdata() from metagam strip_rawdata(model) }) ## Next, we meta-analyze the models. ## It is often most convenient to analyze a single term at a time. We focus on s(x1). meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30) ## We can print some information summary(meta_analysis) ## We can plot the meta-analytic fit together with the individual fits plot(meta_analysis) plot(meta_analysis, ci = "pointwise") ## We can also compute p-values and simultaneous confidence intervals, by setting the nsim argument. ## For details, see the separate vignette. ## Not run: meta_analysis <- metagam(models, terms = "s(x0)", grid_size = 30, nsim = 1000) summary(meta_analysis) plot(meta_analysis, ci = "both") plot(meta_analysis, ci = "simultaneous") ## End(Not run)
library(metagam) library(mgcv) ## Create 5 datasets set.seed(1234) datasets <- lapply(1:5, function(x) gamSim(scale = 5, verbose = FALSE)) ## Fit a GAM in each dataset, then use strip_rawdata() to remove ## individual participant data models <- lapply(datasets, function(dat){ ## This uses the gam() function from mgcv model <- gam(y ~ s(x0, bs = "cr") + s(x1, bs = "cr") + s(x2, bs = "cr"), data = dat) ## This uses strip_rawdata() from metagam strip_rawdata(model) }) ## Next, we meta-analyze the models. ## It is often most convenient to analyze a single term at a time. We focus on s(x1). meta_analysis <- metagam(models, terms = "s(x1)", grid_size = 30) ## We can print some information summary(meta_analysis) ## We can plot the meta-analytic fit together with the individual fits plot(meta_analysis) plot(meta_analysis, ci = "pointwise") ## We can also compute p-values and simultaneous confidence intervals, by setting the nsim argument. ## For details, see the separate vignette. ## Not run: meta_analysis <- metagam(models, terms = "s(x0)", grid_size = 30, nsim = 1000) summary(meta_analysis) plot(meta_analysis, ci = "both") plot(meta_analysis, ci = "simultaneous") ## End(Not run)
Summary method for metagam objects
## S3 method for class 'metagam' summary(object, ...)
## S3 method for class 'metagam' summary(object, ...)
object |
A metagam object as returned by |
... |
other arguments (not used). |
A list of class summary.metagam
containing the following information:
meta_pvals
: dataframe with p-values from each individual fit. These can be meta-analytically
combined using the metap
package.
terms
: smooth terms that have been meta-analyzed.
method
: method used for meta-analysis. See the metafor
package for detailed description.
intercept
: logical specifying whether or not the intercept has been included in the meta-analysis.
cohorts
: Number of datasets ("cohorts") used in the meta-analysis.
Summary method for GAMs stripped for rawdata
## S3 method for class 'striprawdata' summary(object, ...)
## S3 method for class 'striprawdata' summary(object, ...)
object |
Object returned by |
... |
Other arguments. |
The function returns its input argument, which is printed to the console.