Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TwoSampleMR 0.6.10 #597

Merged
merged 16 commits into from
Mar 3, 2025
13 changes: 9 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Package: TwoSampleMR
Title: Two Sample MR Functions and Interface to MRC Integrative Epidemiology Unit OpenGWAS Database
Version: 0.6.9
Title: Two Sample MR Functions and Interface to MRC Integrative
Epidemiology Unit OpenGWAS Database
Version: 0.6.10
Authors@R: c(
person("Gibran", "Hemani", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0920-1055")),
Expand Down Expand Up @@ -40,7 +41,6 @@ Imports:
magrittr,
MASS,
meta,
mr.raps,
MRMix,
MRPRESSO,
pbapply,
Expand All @@ -54,8 +54,10 @@ Suggests:
car,
markdown,
MendelianRandomization,
mr.raps,
MRInstruments,
randomForest,
rsnps,
testthat,
tidyr
VignetteBuilder:
Expand All @@ -64,7 +66,10 @@ Remotes:
gqi/MRMix,
mrcieu/MRInstruments,
MRPRESSO=rondolab/MR-PRESSO,
WSpiller/RadialMR
qingyuanzhao/mr.raps,
WSpiller/RadialMR,
ropensci/rsnps
Additional_repositories: https://mrcieu.r-universe.dev
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# TwoSampleMR v0.6.10

(Release date 2025-03-03)

* The **mr.raps** package was archived from CRAN on 2025-03-01.
A later version (0.4.1) than was on CRAN (0.2) is available from its GitHub repo <https://github.com/qingyuanzhao/mr.raps>.
We believe this later version still works as expected in **TwoSampleMR**.
However, version 0.4.1 depends upon **rsnps** package which is itself now only available on its GitHub repo.
Hence, we have added both packages to our <https://mrcieu.r-universe.dev/> and added that to the `Additional_repositories` field in the DESCRIPTION.
We have also moved mr.raps to the soft dependency list (Suggests list) and added rsnps to our Suggests list, both with remotes.
* Fix to `default_parameters()` helpfile

# TwoSampleMR v0.6.9

(Release date 2025-02-05)
Expand Down
17 changes: 14 additions & 3 deletions R/mr.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#' }
mr <- function(dat, parameters=default_parameters(), method_list=subset(mr_method_list(), use_by_default)$obj)
{

if ("mr_raps" %in% method_list) {
if (!(requireNamespace("mr.raps", quietly = TRUE))) {
stop("You can install mr.raps with install.packages('mr.raps', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))")
}
}

mr_tab <- plyr::ddply(dat, c("id.exposure", "id.outcome"), function(x1)
{
# message("Performing MR analysis of '", x1$id.exposure[1], "' on '", x18WII58$id.outcome[1], "'")
Expand Down Expand Up @@ -232,7 +239,7 @@ mr_method_list <- function()

#' List of parameters for use with MR functions
#'
#' The default is `list(test_dist = "z", nboot = 1000, Cov = 0, penk = 20, phi = 1, alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, loss.function = "huber")`.
#' The default is `list(test_dist = "z", nboot = 1000, Cov = 0, penk = 20, phi = 1, alpha = 0.05, Qthresh = 0.05, over.dispersion = TRUE, loss.function = "huber", shrinkage = FALSE)`.
#'
#' @export
default_parameters <- function()
Expand All @@ -246,8 +253,8 @@ default_parameters <- function()
alpha = 0.05,
Qthresh = 0.05,
over.dispersion = TRUE,
loss.function = "huber",
shrinkage = FALSE
loss.function = "huber",
shrinkage = FALSE
)
}

Expand Down Expand Up @@ -974,6 +981,10 @@ mr_ivw_fe <- function(b_exp, b_out, se_exp, se_out, parameters=default_parameter
#' @export
mr_raps <- function(b_exp, b_out, se_exp, se_out, parameters = default_parameters()) {

if (!(requireNamespace("mr.raps", quietly = TRUE))) {
stop("You can install mr.raps with install.packages('mr.raps', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))")
}

data <- data.frame(beta.exposure = b_exp,
beta.outcome = b_out,
se.exposure = se_exp,
Expand Down
2 changes: 1 addition & 1 deletion man/default_parameters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions tests/testthat/test_mr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Test mr()

# dat <- make_dat("ieu-a-2", "ieu-a-7")
load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR"))

test_that("Test mr(): MR Egger, Weighted median, Inverse variance weighted, Simple mode, Weighted mode", {
res <- mr(dat)
expect_equal(nrow(res), 5L)
expect_equal(ncol(res), 9L)
expect_equal(res[1, "b"], 0.5025, tolerance = 1e-3)
expect_equal(res[2, "b"], 0.3870, tolerance = 1e-3)
expect_equal(res[3, "b"], 0.4459, tolerance = 1e-3)
expect_equal(res[4, "b"], 0.3402, tolerance = 1e-3)
expect_equal(res[5, "b"], 0.3791, tolerance = 1e-1)
})

test_that("mr.raps", {
res2 <- suppressWarnings(mr(dat, method_list = "mr_raps"))
expect_equal(nrow(res2), 1L)
expect_equal(ncol(res2), 9L)
expect_equal(res2[1, "b"], 0.4647, tolerance = 1e-3)
})

test_that("mr.raps over.dispersion option", {
params <- default_parameters()
params$over.dispersion <- FALSE
res3 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params))
expect_equal(nrow(res3), 1L)
expect_equal(ncol(res3), 9L)
expect_equal(res3[1, "b"], 0.4682, tolerance = 1e-3)
})

test_that("mr.raps loss.function option", {
params <- default_parameters()
params$loss.function <- "tukey"
res4 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params))
expect_equal(nrow(res4), 1L)
expect_equal(ncol(res4), 9L)
expect_equal(res4[1, "b"], 0.4788, tolerance = 1e-3)
})

test_that("mr.raps shrinkage option", {
params <- default_parameters()
params$shrinkage <- TRUE
res5 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params))
expect_equal(nrow(res5), 1L)
expect_equal(ncol(res5), 9L)
expect_equal(res5[1, "b"], 0.4647, tolerance = 1e-3)
})
Loading