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.8 #559

Merged
merged 43 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6c57a0d
Update test-coverage.yaml
remlapmot Aug 21, 2024
cd60959
Bump version to 0.6.8
remlapmot Aug 27, 2024
d999904
Replace ; with newlines
remlapmot Aug 27, 2024
d224bfc
Fix if formatting
remlapmot Aug 27, 2024
ec7d1bc
Amend F to Fstat
remlapmot Aug 27, 2024
914899c
Replace ; with newlines
remlapmot Aug 27, 2024
5cacbc8
Update .lintr
remlapmot Aug 27, 2024
1c6d37d
Use seq_len()
remlapmot Aug 27, 2024
91fe276
Update .lintr
remlapmot Aug 27, 2024
944ebdc
Delete whitespace
remlapmot Aug 27, 2024
84491ef
Add space
remlapmot Aug 27, 2024
496faff
lintr spacing
remlapmot Aug 27, 2024
1d14596
lintr spacing
remlapmot Aug 27, 2024
1e97697
lintr spacing
remlapmot Aug 27, 2024
b1b0d8f
lintr newline after pipe
remlapmot Aug 27, 2024
efcd288
lintr newline after pipe
remlapmot Aug 27, 2024
465517f
lintr spacing
remlapmot Aug 27, 2024
3a7e0ca
Update .lintr
remlapmot Aug 27, 2024
709ec66
Delete whitespace
remlapmot Aug 27, 2024
dae3353
Update .lintr
remlapmot Aug 27, 2024
8a3b9f4
Delete whitespace
remlapmot Aug 27, 2024
68c24b6
Delete whitespace
remlapmot Aug 27, 2024
d6dc6f7
Delete whitespace
remlapmot Aug 27, 2024
5615c23
Delete whitespace
remlapmot Aug 27, 2024
a915f71
Delete whitespace
remlapmot Aug 27, 2024
3c3e8bd
Delete whitespace
remlapmot Aug 27, 2024
dd07a4f
Delete whitespace
remlapmot Aug 27, 2024
b4ead42
Whitespace
remlapmot Aug 27, 2024
599c071
Whitespace
remlapmot Aug 27, 2024
2c7c4e8
Whitespace
remlapmot Aug 27, 2024
a8e930c
Whitespace
remlapmot Aug 27, 2024
370a27a
Whitespace
remlapmot Aug 27, 2024
2e67786
Whitespace
remlapmot Aug 27, 2024
2247130
Whitespace
remlapmot Aug 27, 2024
61803e8
Whitespace
remlapmot Aug 27, 2024
9fb2694
Whitespace
remlapmot Aug 27, 2024
422ac75
Document
remlapmot Aug 27, 2024
8cb10c8
Whitespace
remlapmot Aug 27, 2024
13d1818
Only allow max of 2 check jobs at same time
remlapmot Aug 27, 2024
7829641
Fix line
remlapmot Sep 4, 2024
1520c01
Remove NAs
remlapmot Sep 4, 2024
0cfa573
Remove NAs
remlapmot Sep 4, 2024
f9dfa45
Add NEWS bullets and release date
remlapmot Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:

strategy:
fail-fast: false
max-parallel: 2
matrix:
config:
- {os: macos-latest, r: 'release'}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ jobs:

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
Expand Down
7 changes: 4 additions & 3 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ linters: linters_with_defaults(
line_length_linter = NULL,
commented_code_linter = NULL,
indentation_linter = NULL,
trailing_whitespace_linter = NULL,
infix_spaces_linter = NULL,
quotes_linter = NULL,
trailing_blank_lines_linter = NULL,
brace_linter = NULL,
commas_linter = NULL,
whitespace_linter = NULL,
object_name_linter = NULL,
assignment_linter = NULL,
cyclocomp_linter = NULL
cyclocomp_linter = NULL,
object_usage_linter = NULL,
spaces_left_parentheses_linter = NULL,
object_length_linter = NULL
)
encoding: "UTF-8"
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: TwoSampleMR
Title: Two Sample MR Functions and Interface to MR Base Database
Version: 0.6.7
Version: 0.6.8
Authors@R: c(
person("Gibran", "Hemani", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0920-1055")),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# TwoSampleMR v0.6.8

(Release date 2024-09-06)

* Replaced some `unique()` calls in `power_prune()` with `mean()` to ensure scalar `iv.se` values (thanks @phageghost)
* Slightly improved formatting of code base

# TwoSampleMR v0.6.7

(Release date 2024-08-21)
Expand Down
12 changes: 6 additions & 6 deletions R/add_rsq.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Can be applied to exposure_dat, outcome_dat or harmonised_data.
#' Note that it will be beneficial in some circumstances to add the meta data to
#' the data object using [add_metadata()] before running this function.
#' the data object using [add_metadata()] before running this function.
#' Also adds effective sample size for case control data.
#'
#' @param dat exposure_dat, outcome_dat or harmonised_data
Expand Down Expand Up @@ -76,7 +76,7 @@ add_rsq_one <- function(dat, what="exposure")
ind1 <- !is.na(dat[[paste0("pval.", what)]]) & !is.na(dat[[paste0("samplesize.", what)]])
dat[[paste0("rsq.", what)]] <- NA
if(sum(ind1) > 0)
{
{
dat[[paste0("rsq.", what)]][ind1] <- get_r_from_bsen(
dat[[paste0("beta.", what)]][ind1],
dat[[paste0("se.", what)]][ind1],
Expand Down Expand Up @@ -114,7 +114,7 @@ test_r_from_pn <- function()
"Package \"tidyr\" must be installed to use this function.",
call. = FALSE
)
}
}

param <- expand.grid(
n = c(10, 100, 1000, 10000, 100000),
Expand Down Expand Up @@ -228,7 +228,7 @@ compareNA <- function(v1,v2) {

#' Estimate proportion of variance of liability explained by SNP in general population
#'
#' This uses equation 10 in Lee et al. A Better Coefficient of Determination for Genetic Profile Analysis.
#' This uses equation 10 in Lee et al. A Better Coefficient of Determination for Genetic Profile Analysis.
#' Genetic Epidemiology 36: 214–224 (2012) \doi{10.1002/gepi.21614}.
#'
#' @param lor Vector of Log odds ratio.
Expand Down Expand Up @@ -309,7 +309,7 @@ contingency <- function(af, prop, odds_ratio, eps=1e-15)
z <- -c_ / b
} else {
d <- b^2 - 4*a*c_
if (d < eps*eps)
if (d < eps*eps)
{
s <- 0
} else {
Expand All @@ -327,7 +327,7 @@ contingency <- function(af, prop, odds_ratio, eps=1e-15)
#' @param g Vector of 0/1/2
#'
#' @export
#' @return Allele frequency
#' @return Allele frequency
allele_frequency <- function(g)
{
(sum(g == 1) + 2 * sum(g == 2)) / (2 * sum(!is.na(g)))
Expand Down
2 changes: 1 addition & 1 deletion R/enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
a <- lapply(a, as.data.frame)
a <- plyr::rbind.fill(a)
a <- as.data.frame(lapply(a, as.character), stringsAsFactors=FALSE)
return(a)
return(a)

Check warning on line 45 in R/enrichment.R

View check run for this annotation

Codecov / codecov/patch

R/enrichment.R#L45

Added line #L45 was not covered by tests
}


Expand Down
6 changes: 3 additions & 3 deletions R/eve.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ mr_mean_egger <- function(d)
y2 <- ratios * weights2
egger2 <- summary(stats::lm(y2 ~ weights2))
eggeroutliers <- dplyr::tibble(
SNP=d$SNP,
Qj = weights2^2 * (ratios - stats::coefficients(egger2)[1,1] / weights2 - stats::coefficients(egger2)[2,1])^2,
SNP=d$SNP,
Qj = weights2^2 * (ratios - stats::coefficients(egger2)[1,1] / weights2 - stats::coefficients(egger2)[2,1])^2,
Qpval=stats::pchisq(Qj,1,lower.tail=FALSE)
)

Expand Down Expand Up @@ -209,7 +209,7 @@ mr_all <- function(dat, parameters=default_parameters())
m1$estimates <- dplyr::bind_rows(m1$estimates, m2, m3)
}
m1$info <- c(list(
id.exposure = dat$id.exposure[1], id.outcome = dat$id.outcome[1]),
id.exposure = dat$id.exposure[1], id.outcome = dat$id.outcome[1]),
system_metrics(dat)
) %>% dplyr::as_tibble()
return(m1)
Expand Down
22 changes: 11 additions & 11 deletions R/forest_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#' @param decrease (logical) sort the studies by decreasing effect sizes `TRUE`/`FALSE`?
#' @param se_Col (character) name of the column giving the standard error of the effect sizes.
#' @param returnRobj (logical) return the graph as an internal R object `TRUE`/`FALSE`?
#'
#'
#' @keywords internal
#' @return grid object giving the forest plot (or plot as pdf)
mr_forest_plot_grouped <-
Expand Down Expand Up @@ -117,7 +117,7 @@
idx <- idx + 2 + n_std
}
# returns data frame giving spacings, primary annotation (content_list), typeface attributes for the primary annotation (attr_list), and mapping between rows in forest plot and rows in meta-analytic data frame
return( data.frame( spacing_vec = (1 + length(spacing_vec) - spacing_vec), content_list = unlist(content_list), row_list = unlist(row_list), attr_list = unlist(attr_list) ) )
return(data.frame(spacing_vec = (1 + length(spacing_vec) - spacing_vec), content_list = unlist(content_list), row_list = unlist(row_list), attr_list = unlist(attr_list)))

Check warning on line 120 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L120

Added line #L120 was not covered by tests
}


Expand Down Expand Up @@ -162,7 +162,7 @@
data_Fm$eff_col <- log(as.numeric(data_Fm[,eff_col]))
}
# ggplot code to generate the forest plot using geom_segments and geom_points and to make a relatively minimal theme
raw_forest <- ggplot2::ggplot(data = data_Fm, ggplot2::aes( y = space_col, yend = space_col, x = as.numeric(lb_col), xend = as.numeric(ub_col) )) + ggplot2::geom_segment() + ggplot2::geom_point(ggplot2::aes( y = space_col, x = as.numeric(eff_col), size = 4 )) + ggplot2::theme_bw() + ggplot2::theme( axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(), axis.title = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), rect = ggplot2::element_blank(), title = ggplot2::element_text(size = 23), legend.position = 'none') + ggplot2::expand_limits(y = c(data_Fm[,space_col] - 1, data_Fm[,space_col] + 2)) + ggplot2::labs(title = title_text) # returns ggplot2 object with the (un-annotated) forest plot
raw_forest <- ggplot2::ggplot(data = data_Fm, ggplot2::aes(y = space_col, yend = space_col, x = as.numeric(lb_col), xend = as.numeric(ub_col))) + ggplot2::geom_segment() + ggplot2::geom_point(ggplot2::aes(y = space_col, x = as.numeric(eff_col), size = 4)) + ggplot2::theme_bw() + ggplot2::theme(axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(), axis.title = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), rect = ggplot2::element_blank(), title = ggplot2::element_text(size = 23), legend.position = 'none') + ggplot2::expand_limits(y = c(data_Fm[,space_col] - 1, data_Fm[,space_col] + 2)) + ggplot2::labs(title = title_text) # returns ggplot2 object with the (un-annotated) forest plot

Check warning on line 165 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L165

Added line #L165 was not covered by tests
return(raw_forest)
}

Expand All @@ -180,10 +180,10 @@
data_Fm$text_col <- data_Fm[,text_col]

# A hard rule to set the width of the annotation column, which sometimes truncates very wide columns (complex disease names, numbers with 16 digits, etc)
text_widths <- c(-1, max(10,0.5 * max(sapply( as.character(data_Fm[,text_col]),nchar ))))
text_widths <- c(-1, max(10,0.5 * max(sapply(as.character(data_Fm[,text_col]), nchar))))

Check warning on line 183 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L183

Added line #L183 was not covered by tests

# GGplot rendering of the annotation column
lefttext <- ggplot2::ggplot(data = data_Fm, ggplot2::aes( y = space_col, x = 0, label = text_col, fontface = attr_list )) + ggplot2::geom_text(hjust = 0) + ggplot2::theme_bw() + ggplot2::theme( axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(),axis.text.x = ggplot2::element_text(colour = "white"),axis.ticks.x = ggplot2::element_line(colour = "white"), axis.title = ggplot2::element_blank(), rect = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), title = ggplot2::element_text(size = 23) ) + ggplot2::expand_limits(x = text_widths, y = c(data_Fm[,space_col] - 1, data_Fm[,space_col] + 2)) + ggplot2::labs(title = title_text, size = 40) # returns two-item list with left_text, the GGplot annotations, and text_widths, the x-axis limits of the plot
lefttext <- ggplot2::ggplot(data = data_Fm, ggplot2::aes(y = space_col, x = 0, label = text_col, fontface = attr_list)) + ggplot2::geom_text(hjust = 0) + ggplot2::theme_bw() + ggplot2::theme(axis.text.y = ggplot2::element_blank(), axis.ticks.y = ggplot2::element_blank(), axis.text.x = ggplot2::element_text(colour = "white"), axis.ticks.x = ggplot2::element_line(colour = "white"), axis.title = ggplot2::element_blank(), rect = ggplot2::element_blank(), panel.grid = ggplot2::element_blank(), title = ggplot2::element_text(size = 23)) + ggplot2::expand_limits(x = text_widths, y = c(data_Fm[, space_col] - 1, data_Fm[, space_col] + 2)) + ggplot2::labs(title = title_text, size = 40) # returns two-item list with left_text, the GGplot annotations, and text_widths, the x-axis limits of the plot

Check warning on line 186 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L186

Added line #L186 was not covered by tests
return(list(left_text = lefttext, text_widths = text_widths))
}

Expand All @@ -203,7 +203,7 @@

for (i in seq_along(col_names)) {
# loop to get the widths of each annotation column and to group the annotation objects together
col <- anot_col( data_Fm = data_Fm, text_col = col_names[i], space_col = space_col, title_text = title_list[[i]] )
col <- anot_col(data_Fm = data_Fm, text_col = col_names[i], space_col = space_col, title_text = title_list[[i]])

Check warning on line 206 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L206

Added line #L206 was not covered by tests
relative_widths[i] <- col$text_widths[2] - col$text_widths[1]
output[[col_names[i]]] <- ggplotGrob(col$left_text)
}
Expand Down Expand Up @@ -246,7 +246,7 @@
width_vec <- c(left_RW,0.34,right_RW)
width_vec <- width_vec / sum(width_vec)
# convert the grid objects (now grouped) into a table of grid objects that can be plotted using grid.draw
grp_FP <- gtable::gtable_matrix( name = "groupplot", grobs = matrix(grob_Bag, nrow = 1), widths = unit(width_vec, "npc"), heights = unit(1,"npc") )
grp_FP <- gtable::gtable_matrix(name = "groupplot", grobs = matrix(grob_Bag, nrow = 1), widths = unit(width_vec, "npc"), heights = unit(1,"npc"))

Check warning on line 249 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L249

Added line #L249 was not covered by tests

# return the grid object table, to be plotted
return(grp_FP)
Expand All @@ -263,18 +263,18 @@


## order and structure effect sizes and CIs for forest plot
space1 <- spacer( exposure = exposure_Name, eff_col = eff_Col, outcome = outcome_Name, Data_Fm = data, decrease = decrease)
space1 <- spacer(exposure = exposure_Name, eff_col = eff_Col, outcome = outcome_Name, Data_Fm = data, decrease = decrease)

Check warning on line 266 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L266

Added line #L266 was not covered by tests

expand_data <- space_Out(data_Fm = data, space_Fm = space1)

## Make the forest plot
fo1 <- ggforest( data_Fm = expand_data, space_col = 'spacing_vec', eff_col = eff_Col, lb_col = "lb" ,ub_col = "ub", log_ES = log_ES, title_text = forest_Title )
fo1 <- ggforest(data_Fm = expand_data, space_col = 'spacing_vec', eff_col = eff_Col, lb_col = "lb" ,ub_col = "ub", log_ES = log_ES, title_text = forest_Title)

Check warning on line 271 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L271

Added line #L271 was not covered by tests

## Construct left-hand-side annotations
left <- anot_side( data_Fm = expand_data, space_col = 'spacing_vec', col_names = left_Col_Names, title_list = left_Col_Titles )
left <- anot_side(data_Fm = expand_data, space_col = 'spacing_vec', col_names = left_Col_Names, title_list = left_Col_Titles)

Check warning on line 274 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L274

Added line #L274 was not covered by tests

## Construct right-hand-side annotations
right <- anot_side( data_Fm = expand_data, space_col = 'spacing_vec', col_names = right_Col_Names, title_list = right_Col_Titles )
right <- anot_side(data_Fm = expand_data, space_col = 'spacing_vec', col_names = right_Col_Names, title_list = right_Col_Titles)

Check warning on line 277 in R/forest_plot.R

View check run for this annotation

Codecov / codecov/patch

R/forest_plot.R#L277

Added line #L277 was not covered by tests

## group all plots together
group <- group_Plots(forst_Pt = fo1, left_Hs = left, right_Hs = right)
Expand Down
Loading
Loading