Title: | Simulation of Mendelian Randomization data |
---|---|
Description: | This package generates simulation data to use in the evaluation of univariable or multivariable Mendelian Randomization methods. MR scenarios can include uncorrelated horizontal pleiotropy, correlated horizontal pleiotropy, weak instruments, winner's curse, and correlated SNP instruments. |
Authors: | Noah Lorincz-Comi [aut, cre] |
Maintainer: | Noah Lorincz-Comi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9000 |
Built: | 2024-11-15 05:07:47 UTC |
Source: | https://github.com/noahlorinczcomi/simmrd |
Helper function
adj_overlap( exposure_overlap_proportions, prop_gwas_overlap_Xs_and_Y, number_of_exposures )
adj_overlap( exposure_overlap_proportions, prop_gwas_overlap_Xs_and_Y, number_of_exposures )
exposure_overlap_proportions |
scalar or matrix of overlap proportions between exposures GWAS |
prop_gwas_overlap_Xs_and_Y |
scalar or vector of overlap proportions between exposures and outcome GWAS |
number_of_exposures |
number of exposures |
adj_overlap( exposure_overlap_proportions = 0.2, prop_gwas_overlap_Xs_and_Y = 0.1, number_of_exposures = 3 )
adj_overlap( exposure_overlap_proportions = 0.2, prop_gwas_overlap_Xs_and_Y = 0.1, number_of_exposures = 3 )
Helper function
ar1(n, rho = 0.5)
ar1(n, rho = 0.5)
n |
The number of rows (and columns) of the matrix |
rho |
rho |
ar1(2)
ar1(2)
Helper function
biggwas(x, G)
biggwas(x, G)
x |
phenotype vector |
G |
genotype matrix |
## Not run: biggwas() ## End(Not run)
## Not run: biggwas() ## End(Not run)
Helper function
classIVs(ix, uhpix, chpix)
classIVs(ix, uhpix, chpix)
ix |
ix |
uhpix |
uhpix |
chpix |
chpix |
## Not run: classIVs() ## End(Not run)
## Not run: classIVs() ## End(Not run)
This function generates simulated individual-level and data given a list of parameters
generate_individual(params)
generate_individual(params)
params |
List of parameters used to generate simulated data |
## Not run: individual_params <- list( sample_size_Xs = 5e4, # exposure GWAS sample sizes sample_size_Y = 5e4, # outcome GWAS sample size prop_gwas_overlap_Xs_and_Y = 0.5, # proportion of exposure and outcome GWAS overlap number_of_exposures = 2, # 4 number of exposures phenotypic_correlation_Xs = 0.2, # phenotypic correlation between exposures genetic_correlation_Xs = 0, # genetic correlation between exposures Xs_variance_explained_by_U = 1/4 - 0.12, # exposures variance explained by confounder Y_variance_explained_by_Xs = c(0, 0.5), # outcome variance explained by exposures signs_of_causal_effects = c(1, 1), # signs of causal effects Y_variance_explained_by_U = 0.1, # outcome variance explained by confounder number_of_causal_SNPs = 200, # number of SNPs causing exposures mafs_of_causal_SNPs = stats::runif(100, 0.1, 0.5), # minor allele frequency of causal SNPs Xs_variance_explained_by_g = 0.12, # exposures variance explained by SNPs number_of_UHP_causal_SNPs = 30, # number of UHP exposure SNPs number_of_CHP_causal_SNPs = 10, # number of CHP exposure SNPs Y_variance_explained_by_UHP = 0.05, # outcome variance explained by UHP SNPs U_variance_explained_by_CHP = 0.05, # outcome variance explained by CHP SNPs LD_causal_SNPs = 'I', # independent causal exposure SNPs number_of_LD_blocks = 1, # number of independent LD blocks MR_standardization = 'Z', # standardization of GWAS summary statistics simtype = 'weak', # simulation performed using weak instruments MVMR_IV_selection_type = 'joint', # P-values for IV selection based on joint test for exposures IV_Pvalue_threshold = 1, # P-value threshold for candidate IVs LD_pruning_r2 = 1, # upper boundary of squared LD correlation N_of_LD_ref = Inf, # size of the LD reference panel fix_Fstatistic_at = 10 # average across exposures using full MVMR IV set ) gwas_data <- generate_individual(individual_params) ## End(Not run)
## Not run: individual_params <- list( sample_size_Xs = 5e4, # exposure GWAS sample sizes sample_size_Y = 5e4, # outcome GWAS sample size prop_gwas_overlap_Xs_and_Y = 0.5, # proportion of exposure and outcome GWAS overlap number_of_exposures = 2, # 4 number of exposures phenotypic_correlation_Xs = 0.2, # phenotypic correlation between exposures genetic_correlation_Xs = 0, # genetic correlation between exposures Xs_variance_explained_by_U = 1/4 - 0.12, # exposures variance explained by confounder Y_variance_explained_by_Xs = c(0, 0.5), # outcome variance explained by exposures signs_of_causal_effects = c(1, 1), # signs of causal effects Y_variance_explained_by_U = 0.1, # outcome variance explained by confounder number_of_causal_SNPs = 200, # number of SNPs causing exposures mafs_of_causal_SNPs = stats::runif(100, 0.1, 0.5), # minor allele frequency of causal SNPs Xs_variance_explained_by_g = 0.12, # exposures variance explained by SNPs number_of_UHP_causal_SNPs = 30, # number of UHP exposure SNPs number_of_CHP_causal_SNPs = 10, # number of CHP exposure SNPs Y_variance_explained_by_UHP = 0.05, # outcome variance explained by UHP SNPs U_variance_explained_by_CHP = 0.05, # outcome variance explained by CHP SNPs LD_causal_SNPs = 'I', # independent causal exposure SNPs number_of_LD_blocks = 1, # number of independent LD blocks MR_standardization = 'Z', # standardization of GWAS summary statistics simtype = 'weak', # simulation performed using weak instruments MVMR_IV_selection_type = 'joint', # P-values for IV selection based on joint test for exposures IV_Pvalue_threshold = 1, # P-value threshold for candidate IVs LD_pruning_r2 = 1, # upper boundary of squared LD correlation N_of_LD_ref = Inf, # size of the LD reference panel fix_Fstatistic_at = 10 # average across exposures using full MVMR IV set ) gwas_data <- generate_individual(individual_params) ## End(Not run)
This function generates simulated summary-level and data given a list of parameters
generate_summary(params)
generate_summary(params)
params |
List of parameters used to generate simulated data |
## Not run: summary_params <- list( sample_size_Xs = 30000, # exposure GWAS sample sizes sample_size_Y = 30000, # outcome GWAS sample size prop_gwas_overlap_Xs_and_Y = 1, # proportion of exposures' and outcome GWAS overlap number_of_exposures = 3, # number of exposures number_of_causal_SNPs = 100, # number of SNPs causing each exposure number_of_UHP_causal_SNPs = 0, # number of UHP causal SNPs number_of_CHP_causal_SNPs = 20, # number of CHP causal SNPs ratio_of_UHP_variance = 0.15, # ratio of UHP variance to valid IV variance ratio_of_CHP_variance = 0.25, # ratio of CHP variance to valid IV variance CHP_correlation = -0.5, # correlation between CHP and valid IV effect sizes simtype = 'winners', # performs IV selection based on P-value fix_Fstatistic_at = 10, # ignored because simtype='winners' prop_gwas_overlap_Xs = 1, # overlap of exposures' GWAS phenotypic_correlation_Xs = 0.3, # phenotypic correlations between exposures genetic_correlation_Xs = 0.15, # genetic correlation between exposures phenotypic_correlations_Xs_and_Y = 0.3, # phenotypic correlations b/w exposures and outcome true_causal_effects = 0.3, # true causal effect sizes Xs_variance_explained_by_g = 0.10, # exposure variance explained by SNPs LD_causal_SNPs = 'ar1(0.5)', # LD between causal exposure SNPs number_of_LD_blocks = 3, # number of independent LD blocks MR_standardization = 'none', # does not standardize GWAS estimates MVMR_IV_selection_type = 'union', # SNPs associated with >0 exposures are candidate IVs IV_Pvalue_threshold = 5e-8, # only SNPs with P<this threshold are candidate IVs LD_pruning_r2 = 1, # the upper LD r2 pruning threshold for candidate IVs N_of_LD_ref = Inf # the sample size of the LD reference panel ) gwas_data <- generate_summary(summary_params) ## End(Not run)
## Not run: summary_params <- list( sample_size_Xs = 30000, # exposure GWAS sample sizes sample_size_Y = 30000, # outcome GWAS sample size prop_gwas_overlap_Xs_and_Y = 1, # proportion of exposures' and outcome GWAS overlap number_of_exposures = 3, # number of exposures number_of_causal_SNPs = 100, # number of SNPs causing each exposure number_of_UHP_causal_SNPs = 0, # number of UHP causal SNPs number_of_CHP_causal_SNPs = 20, # number of CHP causal SNPs ratio_of_UHP_variance = 0.15, # ratio of UHP variance to valid IV variance ratio_of_CHP_variance = 0.25, # ratio of CHP variance to valid IV variance CHP_correlation = -0.5, # correlation between CHP and valid IV effect sizes simtype = 'winners', # performs IV selection based on P-value fix_Fstatistic_at = 10, # ignored because simtype='winners' prop_gwas_overlap_Xs = 1, # overlap of exposures' GWAS phenotypic_correlation_Xs = 0.3, # phenotypic correlations between exposures genetic_correlation_Xs = 0.15, # genetic correlation between exposures phenotypic_correlations_Xs_and_Y = 0.3, # phenotypic correlations b/w exposures and outcome true_causal_effects = 0.3, # true causal effect sizes Xs_variance_explained_by_g = 0.10, # exposure variance explained by SNPs LD_causal_SNPs = 'ar1(0.5)', # LD between causal exposure SNPs number_of_LD_blocks = 3, # number of independent LD blocks MR_standardization = 'none', # does not standardize GWAS estimates MVMR_IV_selection_type = 'union', # SNPs associated with >0 exposures are candidate IVs IV_Pvalue_threshold = 5e-8, # only SNPs with P<this threshold are candidate IVs LD_pruning_r2 = 1, # the upper LD r2 pruning threshold for candidate IVs N_of_LD_ref = Inf # the sample size of the LD reference panel ) gwas_data <- generate_summary(summary_params) ## End(Not run)
Helper function to make LD blocks
makeBlocks(LD_causal_SNPs, number_of_causal_SNPs, nblocks = 1)
makeBlocks(LD_causal_SNPs, number_of_causal_SNPs, nblocks = 1)
LD_causal_SNPs |
the LD structure of the causal SNPs |
number_of_causal_SNPs |
the total number of causal SNPs |
nblocks |
the number of independent LD blocks |
## Not run: makeBlocks() ## End(Not run)
## Not run: makeBlocks() ## End(Not run)
Helper function
parthcorr(x, n)
parthcorr(x, n)
x |
Matrix or numeric value |
n |
Number of rows and columns of the matrix |
## Not run: parthcorr() ## End(Not run)
## Not run: parthcorr() ## End(Not run)
Helper function
parthstd(bx, by, bxse, byse, maf, nx, ny, MR_standardization_type)
parthstd(bx, by, bxse, byse, maf, nx, ny, MR_standardization_type)
bx |
bx |
by |
by |
bxse |
bxse |
byse |
byse |
maf |
Minor allele frequency |
nx |
nx |
ny |
ny |
MR_standardization_type |
Standardization type |
## Not run: parthstd() ## End(Not run)
## Not run: parthstd() ## End(Not run)
Helper function
pfun(x, y, chpix, uhpix, ...)
pfun(x, y, chpix, uhpix, ...)
x |
x |
y |
y |
chpix |
chipx |
uhpix |
uhpix |
... |
Additional arguments passed to |
## Not run: pfun() ## End(Not run)
## Not run: pfun() ## End(Not run)
Plot simulated data.
plot_simdata( data, params = params, exposure_specific_plot = "total", verbose = TRUE )
plot_simdata( data, params = params, exposure_specific_plot = "total", verbose = TRUE )
data |
direct output from |
params |
Named list of parameters |
exposure_specific_plot |
One of |
verbose |
Logical, default |
## Not run: # If you used generate_summary(), execute the following plot_simdata(gwas_data,summary_params) # If you used generate_individual(), execute the following plot_simdata(gwas_data,individual_params) ## End(Not run)
## Not run: # If you used generate_summary(), execute the following plot_simdata(gwas_data,summary_params) # If you used generate_individual(), execute the following plot_simdata(gwas_data,individual_params) ## End(Not run)
Helper function
plot_simdata_lower(data, params = params, showFstat = TRUE)
plot_simdata_lower(data, params = params, showFstat = TRUE)
data |
direct output from |
params |
Named list of parameters |
showFstat |
Logical, default |
## Not run: plot_simdata_lower() ## End(Not run)
## Not run: plot_simdata_lower() ## End(Not run)
Pruning SNPs
pruning(jointPs, R, r2)
pruning(jointPs, R, r2)
jointPs |
joint p-degree of freedom chi-square tests for IVs |
R |
LD correlation matrix for SNPs |
r2 |
upper squared LD r2 threshold for pruning |
## Not run: pruning() ## End(Not run)
## Not run: pruning() ## End(Not run)
Helper function
setf(bxunstd, nX, fix_Fstatistic_at)
setf(bxunstd, nX, fix_Fstatistic_at)
bxunstd |
bxunstd |
nX |
nX |
fix_Fstatistic_at |
Value to fix the F-statistic at |
## Not run: setf() ## End(Not run)
## Not run: setf() ## End(Not run)
Helper function
std(x)
std(x)
x |
Vector to standardise |
std(0:10)
std(0:10)