Skip to content

Commit b1d5cd7

Browse files
authored
Merge pull request #597 from remlapmot/mrraps
TwoSampleMR 0.6.10
2 parents 55f00ff + 7a8ed53 commit b1d5cd7

File tree

5 files changed

+85
-8
lines changed

5 files changed

+85
-8
lines changed

DESCRIPTION

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Package: TwoSampleMR
2-
Title: Two Sample MR Functions and Interface to MRC Integrative Epidemiology Unit OpenGWAS Database
3-
Version: 0.6.9
2+
Title: Two Sample MR Functions and Interface to MRC Integrative
3+
Epidemiology Unit OpenGWAS Database
4+
Version: 0.6.10
45
Authors@R: c(
56
person("Gibran", "Hemani", , "[email protected]", role = c("aut", "cre"),
67
comment = c(ORCID = "0000-0003-0920-1055")),
@@ -40,7 +41,6 @@ Imports:
4041
magrittr,
4142
MASS,
4243
meta,
43-
mr.raps,
4444
MRMix,
4545
MRPRESSO,
4646
pbapply,
@@ -54,8 +54,10 @@ Suggests:
5454
car,
5555
markdown,
5656
MendelianRandomization,
57+
mr.raps,
5758
MRInstruments,
5859
randomForest,
60+
rsnps,
5961
testthat,
6062
tidyr
6163
VignetteBuilder:
@@ -64,7 +66,10 @@ Remotes:
6466
gqi/MRMix,
6567
mrcieu/MRInstruments,
6668
MRPRESSO=rondolab/MR-PRESSO,
67-
WSpiller/RadialMR
69+
qingyuanzhao/mr.raps,
70+
WSpiller/RadialMR,
71+
ropensci/rsnps
72+
Additional_repositories: https://mrcieu.r-universe.dev
6873
Encoding: UTF-8
6974
Roxygen: list(markdown = TRUE)
7075
RoxygenNote: 7.3.2

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# TwoSampleMR v0.6.10
2+
3+
(Release date 2025-03-03)
4+
5+
* The **mr.raps** package was archived from CRAN on 2025-03-01.
6+
A later version (0.4.1) than was on CRAN (0.2) is available from its GitHub repo <https://github.com/qingyuanzhao/mr.raps>.
7+
We believe this later version still works as expected in **TwoSampleMR**.
8+
However, version 0.4.1 depends upon **rsnps** package which is itself now only available on its GitHub repo.
9+
Hence, we have added both packages to our <https://mrcieu.r-universe.dev/> and added that to the `Additional_repositories` field in the DESCRIPTION.
10+
We have also moved mr.raps to the soft dependency list (Suggests list) and added rsnps to our Suggests list, both with remotes.
11+
* Fix to `default_parameters()` helpfile
12+
113
# TwoSampleMR v0.6.9
214

315
(Release date 2025-02-05)

R/mr.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
#' }
1313
mr <- function(dat, parameters=default_parameters(), method_list=subset(mr_method_list(), use_by_default)$obj)
1414
{
15+
16+
if ("mr_raps" %in% method_list) {
17+
if (!(requireNamespace("mr.raps", quietly = TRUE))) {
18+
stop("You can install mr.raps with install.packages('mr.raps', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))")
19+
}
20+
}
21+
1522
mr_tab <- plyr::ddply(dat, c("id.exposure", "id.outcome"), function(x1)
1623
{
1724
# message("Performing MR analysis of '", x1$id.exposure[1], "' on '", x18WII58$id.outcome[1], "'")
@@ -232,7 +239,7 @@ mr_method_list <- function()
232239

233240
#' List of parameters for use with MR functions
234241
#'
235-
#' 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")`.
242+
#' 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)`.
236243
#'
237244
#' @export
238245
default_parameters <- function()
@@ -246,8 +253,8 @@ default_parameters <- function()
246253
alpha = 0.05,
247254
Qthresh = 0.05,
248255
over.dispersion = TRUE,
249-
loss.function = "huber",
250-
shrinkage = FALSE
256+
loss.function = "huber",
257+
shrinkage = FALSE
251258
)
252259
}
253260

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

984+
if (!(requireNamespace("mr.raps", quietly = TRUE))) {
985+
stop("You can install mr.raps with install.packages('mr.raps', repos = c('https://mrcieu.r-universe.dev', 'https://cloud.r-project.org'))")
986+
}
987+
977988
data <- data.frame(beta.exposure = b_exp,
978989
beta.outcome = b_out,
979990
se.exposure = se_exp,

man/default_parameters.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_mr.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Test mr()
2+
3+
# dat <- make_dat("ieu-a-2", "ieu-a-7")
4+
load(system.file("extdata", "test_commondata.RData", package="TwoSampleMR"))
5+
6+
test_that("Test mr(): MR Egger, Weighted median, Inverse variance weighted, Simple mode, Weighted mode", {
7+
res <- mr(dat)
8+
expect_equal(nrow(res), 5L)
9+
expect_equal(ncol(res), 9L)
10+
expect_equal(res[1, "b"], 0.5025, tolerance = 1e-3)
11+
expect_equal(res[2, "b"], 0.3870, tolerance = 1e-3)
12+
expect_equal(res[3, "b"], 0.4459, tolerance = 1e-3)
13+
expect_equal(res[4, "b"], 0.3402, tolerance = 1e-3)
14+
expect_equal(res[5, "b"], 0.3791, tolerance = 1e-1)
15+
})
16+
17+
test_that("mr.raps", {
18+
res2 <- suppressWarnings(mr(dat, method_list = "mr_raps"))
19+
expect_equal(nrow(res2), 1L)
20+
expect_equal(ncol(res2), 9L)
21+
expect_equal(res2[1, "b"], 0.4647, tolerance = 1e-3)
22+
})
23+
24+
test_that("mr.raps over.dispersion option", {
25+
params <- default_parameters()
26+
params$over.dispersion <- FALSE
27+
res3 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params))
28+
expect_equal(nrow(res3), 1L)
29+
expect_equal(ncol(res3), 9L)
30+
expect_equal(res3[1, "b"], 0.4682, tolerance = 1e-3)
31+
})
32+
33+
test_that("mr.raps loss.function option", {
34+
params <- default_parameters()
35+
params$loss.function <- "tukey"
36+
res4 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params))
37+
expect_equal(nrow(res4), 1L)
38+
expect_equal(ncol(res4), 9L)
39+
expect_equal(res4[1, "b"], 0.4788, tolerance = 1e-3)
40+
})
41+
42+
test_that("mr.raps shrinkage option", {
43+
params <- default_parameters()
44+
params$shrinkage <- TRUE
45+
res5 <- suppressWarnings(mr(dat, method_list = "mr_raps", parameters = params))
46+
expect_equal(nrow(res5), 1L)
47+
expect_equal(ncol(res5), 9L)
48+
expect_equal(res5[1, "b"], 0.4647, tolerance = 1e-3)
49+
})

0 commit comments

Comments
 (0)