Title: | Regularized Mediation Analysis |
---|---|
Description: | Mediation analysis for multiple mediators by penalized structural equation models with different types of penalties depending on whether there are multiple mediators and only one exposure and one outcome variable (using sparse group lasso) or multiple exposures, multiple mediators, and multiple outcome variables (using lasso, L1, penalties). |
Authors: | Jason Sinnwell [aut, cre] , Daniel Schaid [aut] |
Maintainer: | Jason Sinnwell <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.1.0 |
Built: | 2024-11-13 06:15:44 UTC |
Source: | https://github.com/cran/regmed |
Mediation analysis for multiple mediators by penalized structural equation models with different types of penalties depending on whether there are multiple mediators and only one exposure and one outcome variable (using sparse group lasso) or multiple exposures, multiple mediators, and multiple outcome variables (using lasso, L1, penalties).
The DESCRIPTION file:
Package: | regmed |
Type: | Package |
Title: | Regularized Mediation Analysis |
Version: | 2.1.0 |
Date: | 2023-1-20 |
Authors@R: | c( person("Jason", "Sinnwell", email = "[email protected]", comment=c(ORCID="0000-0003-1964-5522"), role = c("aut","cre"),), person("Daniel", "Schaid", email = "[email protected]", comment=c(ORCID="0000-0003-1457-6433"), role = c("aut"),)) |
Description: | Mediation analysis for multiple mediators by penalized structural equation models with different types of penalties depending on whether there are multiple mediators and only one exposure and one outcome variable (using sparse group lasso) or multiple exposures, multiple mediators, and multiple outcome variables (using lasso, L1, penalties). |
License: | GPL (>= 2) |
Suggests: | testthat, rmarkdown |
Depends: | R (>= 4.1.0), methods, graphics, glasso, igraph |
Imports: | knitr, Rcpp, RcppArmadillo, lavaan, gtools |
LinkingTo: | Rcpp, RcppArmadillo |
NeedsCompilation: | yes |
VignetteBuilder: | knitr |
URL: | https://cran.r-project.org/package=regmed |
Packaged: | 2023-01-20 20:57:01 UTC; sinnwell |
Author: | Jason Sinnwell [aut, cre] (<https://orcid.org/0000-0003-1964-5522>), Daniel Schaid [aut] (<https://orcid.org/0000-0003-1457-6433>) |
Maintainer: | Jason Sinnwell <[email protected]> |
Date/Publication: | 2023-01-20 21:30:02 UTC |
Config/pak/sysreqs: | libglpk-dev libxml2-dev |
Repository: | https://sinnweja.r-universe.dev |
RemoteUrl: | https://github.com/cran/regmed |
RemoteRef: | HEAD |
RemoteSha: | 99e05fccb95f1787f32c08412b5b80421df75bc8 |
Index of help topics:
medsim Simulated dataset for regmed package mvregmed.dat.check Helper function to check x, y, mediator for input to mvregmed functions mvregmed.edges For an object of class mvregmed, create edges for a graph object that can be used for plots, or for creating models input to lavaan function sem mvregmed.fit Multivariate regularized mediation model mvregmed.graph.attributes Setup attributes of graph object for plotting mvregmed.grid Fit a grid of mvregmed models over a vector of lambda penalty parameters mvregmed.grid.bestfit Choose best fit model from a grid search based on minimum Bayesian Information Criterion mvregmed.grid.data Helper function to summarize fits of models across a grid of lambda values mvregmed.grid.update Helper function to update parameters in a grid search mvregmed.init Helper function to setup data and parameters for input to mvregmed.fit and mvregmed.grid mvregmed.lavaan.dat Set up data to input to lavaan sem mvregmed.lavaan.model Setup a model for input to lavaan plot.mvregmed.grid Plot penalty parameter lambda versus BIC for model fits plot.regmed.grid Plots for regmed.grid object. regmed-package Regularized Mediation Analysis regmed.edges For an object of class regmed, create edges for a graph object that can be used for plots, or for creating models input to lavaan function sem regmed.fit Regularized Mediation model for a specified lambda penalty value. regmed.grid Regularized mediation models over a vector grid of lambda penalty values. regmed.grid.bestfit Find best fitting regmed model from regmed.grid object. regmed.lavaan.dat Set up data to input to lavaan sem regmed.lavaan.model Create a lavaan model regmed.prefilter Prefilter to reduce the number of mediators for subsequent analyses summary.mvregmed Summary of mvregmed object
Further information is available in the following vignettes:
regmed |
Regularized_Mediation_Examples (source, pdf) |
Jason Sinnwell [aut, cre] (<https://orcid.org/0000-0003-1964-5522>), Daniel Schaid [aut] (<https://orcid.org/0000-0003-1457-6433>)
Maintainer: Jason Sinnwell <[email protected]>
Schaid, DJ, Sinnwell JP. (2020) Penalized Models for Analysis of Multiple Mediators. Genet Epidemiol 44:408-424.
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Example data simulated from 2 response (y) variables, 10 exposure (x) variables, and 200 mediators (med). The all variables are generated from multivariate standard normal, with varying degrees of association between exposure, mediators, and responses.
data("medsim")
data("medsim")
Three data frames with 100 observsations each:
x
matrix with 10 columns of continuous exposure variables
y
matrix with 2 columns of continuous response variables
med
numeric matrix of 200 columns of simulated mediators between exposures and responses
Assure that x, y, mediator are matrices, check column names and fill in if NULL, and reduce x, y, mediator so no missing values among all three matrices.
mvregmed.dat.check(x, y, mediator, max.cor=0.99)
mvregmed.dat.check(x, y, mediator, max.cor=0.99)
x |
matrix with columns representing "exposure" variable (sometimes called instrumental variable) |
y |
matrix with columns representing outcome variables |
mediator |
matrix with columns representing mediator variables |
max.cor |
maximum correlation within y, x, or mediators, so fitting is more robust |
list with updated x, y, mediator
Daniel Schaid and Jason Sinnwell
Using the names of the alpha, beta, and delta matrices in the fitted object, create directed edges
mvregmed.edges(fit, eps = 0.001)
mvregmed.edges(fit, eps = 0.001)
fit |
The fit as an object of class mvregmed. This can be output from either mvregmed.fit or mvregmed.grid.bestfit. |
eps |
Threshold to determine whether any of alpha, beta, or delta parameters are close to zero to be rounded to zero. |
an object of class mvregmed.edges, which is a list with all.edge which is a data.frame with directed edges that are the names of x, mediator, y that are in the fitted model. Also returns data frames for alpha, beta, delta (each data frame containing vertex labels, row/col indices from which parameters were selected, and coefficient values), as well as names of x, mediator, and y.
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
mvregmed.fit
plot.mvregmed.edges
Fit regularized mediation model for a specified lambda penalty value. Structural equation models for analysis of multiple exposures (x), multiple mediators, and multiple outcome variables (y) are fit with a lasso (L1) penalaty on the model parameters. The model is x-[alpha] -> mediator-[beta] -> outcome, where alpha and beta are the parameters for the indirect effect of x on y, through the mediator. The model also allows a direct effect of x on y: x-[delta]->y.
mvregmed.fit(x, mediator, y, lambda, x.std = TRUE, med.std = TRUE, y.std = TRUE, max.outer = 5000, max.inner = 2, step.multiplier = 0.5, print.iter = FALSE, max.cor=0.99)
mvregmed.fit(x, mediator, y, lambda, x.std = TRUE, med.std = TRUE, y.std = TRUE, max.outer = 5000, max.inner = 2, step.multiplier = 0.5, print.iter = FALSE, max.cor=0.99)
x |
matrix with columns representing "exposure" variable (sometimes called instrumental variable) |
mediator |
matrix with columns representing mediator variables |
y |
matrix with columns representing outcome variables |
lambda |
lambda penalty parameter |
x.std |
logical (TRUE/FALSE) whether to standardize x by dividing by standard devation of x. Note that each column of x will be centered on its mean. |
med.std |
logical (TRUE/FALSE) whether to standardize mediator by dividing by standard devation of mediator. Note that each column of mediator will be centered on its mean. |
y.std |
logical (TRUE/FALSE) whether to standardize y by dividing by standard devation of y. Note that each column of y will be centered on its mean. |
max.outer |
maximum number of outer loop iterations. The outer loop cycles over several inner loops. |
max.inner |
maximum number of iterations for each inner loop. There is an inner loop for each paramemeter in the matrices alpha, beta, delta, and vary. |
step.multiplier |
In inner loop, the step size is shrunk by the step.multiplier to assure that step size is not too large. Generally, the default of 0.5 works well. |
print.iter |
print iteration number during fitting routine |
max.cor |
maximum correlation within y, x, or mediators, so fitting is more robust |
An object of class mvregmed
Daniel Schaid and Jason Sinnwell
Schaid DJ, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized Mediation Models for Multivariate Data. Genet Epidemiol 46:32-50.
data(medsim) mvfit <- mvregmed.fit(x, med[,1:10], y, lambda=.1) summary(mvfit)
data(medsim) mvfit <- mvregmed.fit(x, med[,1:10], y, lambda=.1) summary(mvfit)
Setup attributes of graph object for plotting directed acyclic graph with graph attributes
mvregmed.graph.attributes(fit.edges, x.color = "palegreen", y.color = "palevioletred", med.color = "skyblue", v.size = 30)
mvregmed.graph.attributes(fit.edges, x.color = "palegreen", y.color = "palevioletred", med.color = "skyblue", v.size = 30)
fit.edges |
A data.frame of edges with 1st column a vertex directed to the vertex in the 2nd column. This is all.edge from the list that is output from mvregmed.edges |
x.color |
Color of vertices for x variables |
y.color |
Color of vertices for y variables |
med.color |
Color of vertices for mediators |
v.size |
Size of vertices for plotting |
User can use this as template for taking advantage of more igraph attributes.
List with items 1) output from graph_from_edgelist (see igraph); 2) vertex names; 3)vertex size; 4) vertex colors
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
mvregmed.edges
graph_from_edgelist
For each lambda in an input vector of values, fit a penalized mvregmed model
mvregmed.grid(x, mediator, y, lambda.vec, max.outer = 5000, max.inner = 2, x.std = TRUE, med.std = TRUE, y.std = TRUE, step.multiplier = 0.5, print.iter = FALSE, max.cor=0.99)
mvregmed.grid(x, mediator, y, lambda.vec, max.outer = 5000, max.inner = 2, x.std = TRUE, med.std = TRUE, y.std = TRUE, step.multiplier = 0.5, print.iter = FALSE, max.cor=0.99)
x |
matrix with columns representing "exposure" variable (sometimes called instrumental variable) |
mediator |
matrix with columns representing mediator variables |
y |
matrix with columns representing outcome variables |
lambda.vec |
Vector of values of penalty parameter lambda's |
max.outer |
maximum number of outer loop iterations. The outer loop cycles over several inner loops. |
max.inner |
maximum number of iterations for each inner loop. There is an inner loop for each paramemeter in the matrices alpha, beta, delta, and vary. |
x.std |
logical (TRUE/FALSE) whether to standardize x by dividing by standard devation of x. Note that each column of x will be centered on its mean. |
med.std |
logical (TRUE/FALSE) whether to standardize mediator by dividing by standard devation of mediator. Note that each column of mediator will be centered on its mean. |
y.std |
logical (TRUE/FALSE) whether to standardize y by dividing by standard devation of y. Note that each column of y will be centered on its mean. |
step.multiplier |
In inner loop, the step size is shrunk by the step.multiplier to assure that step size is not too large. Generally, the default of 0.5 works well. |
print.iter |
print iteration number during fitting routine |
max.cor |
maximum correlation within y, x, or mediators, so fitting is more robust |
An object of class mvregmed.grid
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
data(medsim) mvfit.grid <- mvregmed.grid(x, med[,1:10], y, lambda.vec=seq(.3, .04, by=-.01)) summary(mvfit.grid) ## plot(mvfit.grid)
data(medsim) mvfit.grid <- mvregmed.grid(x, med[,1:10], y, lambda.vec=seq(.3, .04, by=-.01)) summary(mvfit.grid) ## plot(mvfit.grid)
Search over all models fit in a grid and choose model with min BIC as best model.
mvregmed.grid.bestfit(fit.grid)
mvregmed.grid.bestfit(fit.grid)
fit.grid |
An object of class mvregmed.grid, output from function mvregmed.grid |
An object of class mvregmed, a single best fitting model.
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
elper function to summarize fits of models across a grid of lambda values
mvregmed.grid.data(fit.lst, lambda.vec)
mvregmed.grid.data(fit.lst, lambda.vec)
fit.lst |
A list of model fits over a grid of lambda values; length of list is length of vector of lambdas. |
lambda.vec |
A vector of penalty lambda values/ |
Create a data.frame of summmary information for each model fit in a grid.
data.frame of summary information
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
After a model is fit with a specific lambda, use the output of the fitted parameters as initial values for the next lambda value, thus using warm starts at each successive lambda value.
mvregmed.grid.update(fit.obj, inits)
mvregmed.grid.update(fit.obj, inits)
fit.obj |
A fitted model of class mvregmed. |
inits |
Initial values from mvregmed.init that are subsequently updated with new values from fit.obj |
A list with the same components as output from mvregmed.init
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Helper function to setup data and parameters for input to mvregmed.fit and mvregmed.grid
mvregmed.init(dat.obj, x.std = TRUE, med.std = TRUE, y.std = TRUE)
mvregmed.init(dat.obj, x.std = TRUE, med.std = TRUE, y.std = TRUE)
dat.obj |
A list that is output from mvregmed.dat.check that contains x, mediator, and y. |
x.std |
logical (TRUE/FALSE) whether to standardize x by dividing by standard devation of x. Note that each column of x will be centered on its mean. |
med.std |
logical (TRUE/FALSE) whether to standardize mediator by dividing by standard devation of mediator. Note that each column of mediator will be centered on its mean. |
y.std |
logical (TRUE/FALSE) whether to standardize y by dividing by standard devation of y. Note that each column of y will be centered on its mean. |
Center and scale (if declared) x, mediator and y. Then regress each mediator on all x to create residuals that are used to create the residual variance matrix for mediators. This variance matrix is penalized by glasso to obtain a matrix of full rank. Variance matrices for x and y variables are also created. Initial values of paramemeter matrices alpha, beta, and delta are created (all intital values = 0).
A list of items used as input to model fitting.
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Set up data to input to lavaan structural equation model (sem)
mvregmed.lavaan.dat(x, mediator, y, max.cor=0.99)
mvregmed.lavaan.dat(x, mediator, y, max.cor=0.99)
x |
matrix of exposure variables |
mediator |
matrix of mediators |
y |
matrix of outcome variables |
max.cor |
maximum correlation within mediators, so that fitting is more robust |
Use the function regmed.dat.check to standardize all variables and subset to subjects without missing data
A dataframe with updated x, mediator, and y
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Set up a model statement (string formula) from mvregmed object for input to lavaan
mvregmed.lavaan.model(fit.edge, fit.mvregmed)
mvregmed.lavaan.model(fit.edge, fit.mvregmed)
fit.edge |
Output from mvregmed.edges |
fit.mvregmed |
A mvregmed object, either from mvregmed.fit or from mvregmed.grid.bestfit |
Loop through all relationships determined important from mrregmed edges object, and create model statement for lavaan, while also specifying covariances pre-estimated by mvregmed. See vignette for examples. The summary method for lavaan supersedes the summary from the lavaan package by simplifying the output to only return the coefficient table, as the covariance estimates were fixd from mvregmed.
Text string to define a model as input to sem
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Plot penalty parameter lambda versus BIC for model fits
## S3 method for class 'mvregmed.grid' plot(x, xlab="lambda", ylab="BIC", pch="*", ...)
## S3 method for class 'mvregmed.grid' plot(x, xlab="lambda", ylab="BIC", pch="*", ...)
x |
An object created by mvregmed.grid |
xlab |
x axis label, by default set to 'lambda' |
ylab |
y axis label, by default set to 'BIC' for this plot |
pch |
plot character, by default set to a star (*) |
... |
optional plot arguments |
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Creates 2 plots: (1) BIC vs. lambda, and (2) Coefficients Alpha and Beta of mediator vs. lambda.
## S3 method for class 'regmed.grid' plot(x, as.log=FALSE, ...)
## S3 method for class 'regmed.grid' plot(x, as.log=FALSE, ...)
x |
regmed.grid object, returned by the |
as.log |
Logical; if TRUE, plot lambda on the log scale |
... |
optional arguments for plot method |
nothing is returned
Dan Schaid, Greg Jenkins, Jason Sinnwell
data(medsim) fit.grid <- regmed.grid(x[,1], med[,1:10], y[,1], lambda.vec= c(seq(from=1, to=0, by = -.1)), frac.lasso=.8) summary(fit.grid)
data(medsim) fit.grid <- regmed.grid(x[,1], med[,1:10], y[,1], lambda.vec= c(seq(from=1, to=0, by = -.1)), frac.lasso=.8) summary(fit.grid)
Using the names of the alpha, beta, and delta matrices in the fitted object, create directed edges
regmed.edges(fit, type="mediators", eps = 0.001)
regmed.edges(fit, type="mediators", eps = 0.001)
fit |
The fit as an object of class mvregmed. This can be output from either mvregmed.fit or mvregmed.grid.bestfit. |
type |
Character string specifying whether to only keep edges for mediators that have a non-zero coefficient with exposure and response variables ("mediator") or all edges ("all"). |
eps |
Threshold to determine whether any of alpha, beta, or delta parameters are close to zero to be rounded to zero. |
a list with class "regmed.edges" containing all.edge which is a data.framewith directed edges that are the names of x, mediator, y that are in the fitted model, with the coefficient for that edge. The plot method will plot the edges using igraph plotting options.
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
Fit regularized mediation model for a specified lambda penalty value. Structural equation models for analysis of multiple mediators are extended by creating a sparse group lasso penalized model such that the penalty considers the natural groupings of the pair of parameters that determine mediation, as well as encourages sparseness of the model parameters. The model is x-[alpha] -> mediator-[beta] -> outcome, where alpha and beta are the parameters for the indirect effect of x on y, through the mediator. The model also allows a direct effect of x on y: x-[delta] -> y.
regmed.fit(x, mediator, y, lambda, frac.lasso=0.8, x.std=TRUE, med.std=TRUE, max.outer=5000, max.inner=100, step.multiplier = 0.5, wt.delta = .5, print.iter=FALSE, max.cor=0.99)
regmed.fit(x, mediator, y, lambda, frac.lasso=0.8, x.std=TRUE, med.std=TRUE, max.outer=5000, max.inner=100, step.multiplier = 0.5, wt.delta = .5, print.iter=FALSE, max.cor=0.99)
x |
vector representing "exposure" variable (sometimes called instrumental variable) |
mediator |
matrix of mediators, rows are observations, columns are different mediators |
y |
vector representing outcome |
lambda |
lambda penalty parameter |
frac.lasso |
fraction of penalty (lambda) that is allocated to L1 penalty (lasso). The remaining fraction, (1-frac.lasso) is allocated to group-lasso penalty, where the group is the pair of parameters alpha and beta that determine mediation (x [alpha] -> mediator -> [beta] y). |
x.std |
logical (TRUE/FALSE) whether to standardize x by dividing by standard devation of x. Note that x will be centered on its mean. |
med.std |
logical (TRUE/FALSE) whether to standardize mediators by dividing each mediator by its standard deviation. Note that mediators will be centered on their means. |
max.outer |
maximum number of outer loop iterations. The outer loop cycles over several inner loops. |
max.inner |
maximum number of iterations for each inner loop. There is an inner loop for each pair of alpha-beta parameters for each mediator, an inner loop for direct effect (delta), and inner loops for residual variances for x and for y. |
step.multiplier |
a value between 0 and 1 for backtracking, to shrink step size. Value of 0.5 is typical default. |
wt.delta |
a weight >=0 for how much weight should be given to shrinking delta parameter, by penalaty lambda*wt.delta. |
print.iter |
print iteration history during fitting routine |
max.cor |
maximum correlation within mediators, so that fitting is more robust |
regmed object, with S3 methods available: plot, print, summary
Dan Schaid, Greg Jenkins, Jason Sinnwell
Schaid, DJ, Sinnwell JP. (2020) Penalized Models for Analysis of Multiple Mediators. Genet Epidemiol 44:408-424.
data(medsim) filter5 <- regmed.prefilter(x[,1], med, y[,1], k=5) fit.regmed <- regmed.fit(x[,1], med[,1:5], y[,1], lambda = 0.2, frac.lasso=.8) summary(fit.regmed)
data(medsim) filter5 <- regmed.prefilter(x[,1], med, y[,1], k=5) fit.regmed <- regmed.fit(x[,1], med[,1:5], y[,1], lambda = 0.2, frac.lasso=.8) summary(fit.regmed)
Fit regularized mediation models over a vector grid of lambda penalty values. Structural equation models for analysis of multiple mediators are extended by creating a sparse group lasso penalized model such that the penalty considers the natural groupings of the pair of parameters that determine mediation, as well as encourages sparseness of the model parameters. The model is x-[alpha] -> mediator-[beta] -> outcome, where alpha and beta are the parameters for the indirect effect of x on y, through the mediator. The model also allows a direct effect of x on y: x-[delta] -> y.
regmed.grid(x, mediator, y, lambda.vec, frac.lasso=0.8, max.outer=5000, max.inner=100, x.std=TRUE, med.std=TRUE, step.multiplier = 0.5, wt.delta = .5, print.iter=FALSE, max.cor=0.99)
regmed.grid(x, mediator, y, lambda.vec, frac.lasso=0.8, max.outer=5000, max.inner=100, x.std=TRUE, med.std=TRUE, step.multiplier = 0.5, wt.delta = .5, print.iter=FALSE, max.cor=0.99)
x |
vector representing "exposure" variable (sometimes called instrumental variable) |
mediator |
matrix of mediators, rows are observations, columns are different mediators |
y |
vector representing outcome |
lambda.vec |
vector of lambda penalty parameters |
frac.lasso |
fraction of penalty (lambda) that is allocated to L1 penalty (lasso). The remaining fraction, (1-frac.lasso) is allocated to group-lasso penalty, where the group is the pair of parameters alpha and beta that determine mediation (x [alpha] -> mediator -> [beta] y). |
max.outer |
maximum number of outer loop iterations. The outer loop cycles over several inner loops. |
max.inner |
maximum number of iterations for each inner loop. There is an inner loop for each pair of alpha-beta parameters for each mediator, an inner loop for direct effect (delta), and inner loops for residual variances for x and for y. |
x.std |
logical (TRUE/FALSE) whether to standardize x by dividing by standard devation of x. Note that x will be centered on its mean. |
med.std |
logical (TRUE/FALSE) whether to standardize mediators by dividing each mediator by its standard deviation. Note that mediators will be centered on their means. |
step.multiplier |
a value between 0 and 1 for backtracking, to shrink step size. Value of 0.5 is typical default. |
wt.delta |
a weight >=0 for how much weight should be given to shrinking delta parameter, by penalaty lambda*wt.delta. |
print.iter |
print iteration history during fitting routine |
max.cor |
maximum correlation within mediators, so fitting is more robust |
Altough outcome y is not required to be scaled by its standard deviation, it can be beneficial to scale y. This helps with setting range of lambda penalty parameters, because when all x, y, and mediators are scaled, it is reasonable to consider lambda values within the range of 0 to 1. See reference for details of algorithm.
regmed.grid object
Dan Schaid, Jason Sinnwell
Schaid, DJ, Sinnwell JP. (2020) Penalized Models for Analysis of Multiple Mediators. Genet Epidemiol 44:408-424.
data(medsim) fit.grid <- regmed.grid(x[,1], med[,1:5], y[,1], lambda.vec= c(seq(from=1, to=0, by = -.1)), frac.lasso=.8) print(fit.grid)
data(medsim) fit.grid <- regmed.grid(x[,1], med[,1:5], y[,1], lambda.vec= c(seq(from=1, to=0, by = -.1)), frac.lasso=.8) print(fit.grid)
Find best fitting regmed model from regmed.grid object using minimum BIC to select model.
regmed.grid.bestfit(fit.grid)
regmed.grid.bestfit(fit.grid)
fit.grid |
a regmed.grid object |
fit |
best fit regmed object based on minimum BIC |
grid |
row out of grid.data of regmed.grid object corresponding to best fit |
Dan Schaid, Greg Jenkins, Jason Sinnwell
Schaid, DJ, Sinnwell JP. (2020) Penalized Models for Analysis of Multiple Mediators. Genet Epidemiol 44:408-424.
Set up data to input to lavaan structural equation model (sem)
regmed.lavaan.dat(x, mediator, y)
regmed.lavaan.dat(x, mediator, y)
x |
vector of exposure variables |
mediator |
matrix of mediator variables |
y |
vector of outcome variable |
Use the function regmed.dat.check to standardize all variables and subset to subjects without missing data
A dataframe with updated x, mediator, and y
Dan Schaid, Jason Sinnwell
Schaid, DJ, Sinnwell JP. (2020) Penalized Models for Analysis of Multiple Mediators. Genet Epidemiol 44:408-424.
Create a lavaan model for input to lavan::sem()
regmed.lavaan.model(fit.edge, fit.regmed)
regmed.lavaan.model(fit.edge, fit.regmed)
fit.edge |
object created by regmed.edges function |
fit.regmed |
object created by regmed.fit from which the fit.edge object was made |
The fit.regmed object is needed for the fixed covariance estimates to be put into the model statement. The summary method supersedes the default summary from the lavaan package to only return the table of coefficients, as the covariances are fixed from regmed.fit.
a character string that descibes the mediation model in format of lavaan model
Dan Schaid, Greg Jenkins, Jason Sinnwell
Use sure independence screening (Fan & Lv, 2008)to reduce the number of potential mediators when the number of potential mediators is large. This is based on ranking marginal correlations and then selecting the highest ranked values such that the number of parameters is less than the sample size. Because mediation depends on the two correlations, cor(x,med) and cor(med, y) we rank the absolute values of their products, |cor(x, med) * cor(med, y)|, and choose the highest k ranked values to determine which potential mediators to include in penalized mediation models. If k is not specified, the default value of k is n/2, where n is the sample size, because each mediator results in two parameters alpha and beta.
regmed.prefilter(x, mediator, y, k = NULL, x.std = TRUE, med.std = TRUE, y.std=TRUE, max.cor=0.99)
regmed.prefilter(x, mediator, y, k = NULL, x.std = TRUE, med.std = TRUE, y.std=TRUE, max.cor=0.99)
x |
vector representing "exposure" variable (sometimes called instrumental variable) |
mediator |
matrix of mediators, rows are observations, columns are different mediators |
y |
vector representing outcome |
k |
Number of potential mediators to select. Default is n/2, where n is sample size. |
x.std |
logical (TRUE/FALSE) whether to standardize x by dividing by standard devation of x. Note that x will be centered on its mean. |
med.std |
logical (TRUE/FALSE) whether to standardize mediators by dividing each mediator by its standard deviation. Note that mediators will be centered on their means. |
y.std |
logical (TRUE/FALSE) whether to standardize y by dividing by standard devation of y. Note that y will be centered on its mean. |
max.cor |
maximum correlation within mediators, so that fitting is more robust |
list with x, mediator, and y, after subsetting to no missing values, applying x.std and med.std, and subsetting mediators to k top choices.
Dan Schaid, Jason Sinnwell
Fan, J., & Lv, J. (2008). Sure independence screening for ultrahigh dimensional feature space. J. R. Statist. Soc.B, 70, 849-911. Schaid, DJ, Sinnwell JP. (2020) Penalized Models for Analysis of Multiple Mediators. Genet Epidemiol 44:408-424.
data(medsim) dim(med) filtered <- regmed.prefilter(x[,1], med, y[,1], k=10) dim(filtered$med)
data(medsim) dim(med) filtered <- regmed.prefilter(x[,1], med, y[,1], k=10) dim(filtered$med)
Summary of non-zero parameter estimates. Optional epsilon (eps) parameter controls rounding to 0.
## S3 method for class 'mvregmed' summary(object, eps=1e-3, ...)
## S3 method for class 'mvregmed' summary(object, eps=1e-3, ...)
object |
mvregmed object returned from mvregmed.fit or mvregmed.grid.bestfit |
eps |
parameters smaller than epsilon (eps) are rounded to zero. |
... |
optional arguments |
Nothing is returned
Daniel Schaid and Jason Sinnwell
Schaid DS, Dikilitas O, Sinnwell JP, Kullo I (2022). Penalized mediation models for multivariate data. Genet Epidemiol 46:32-50.
mvregmed.fit
mvregmed.grid.bestfit