Skip to content

[BUG]: inferred p-value calculation is missing a factor of 2 #670

@j-brody

Description

@j-brody

Please make sure that this is a bug! If you have questions about how to use TwoSampleMR please use the Discussions function instead.

Describe the bug (required)

For 'inferred', the calculation for dat$pval.outcome is missing a factor of 2 in the p-value formula.

Describe the current behaviour you observe (required)

When the outcome p-values are missing, but beta.outcome and se.outcome are present, the following code is used to infer p-values:

if (any(is.na(dat$pval.outcome))) {
if ("beta.outcome" %in% names(dat) && "se.outcome" %in% names(dat)) {
index <- is.na(dat$pval.outcome)
dat$pval.outcome[index] <- stats::pnorm(abs(dat$beta.outcome[index])/dat$se.outcome[index],
lower.tail = FALSE)
dat$pval_origin.outcome[index] <- "inferred"
}
}
However, this assignment does not multiply the result by 2 (for a two-sided test), resulting in half the correct p-value.

Describe the behaviour you expect (required)

dat$pval.outcome[index] <- 2 * stats::pnorm(abs(dat$beta.outcome[index])/dat$se.outcome[index], lower.tail = FALSE)

R code to reproduce the issue (required)

dat <- data.frame(
beta.outcome = c(1.1, 0.5),
se.outcome = c(0.6, 0.3),
pval.outcome = c(NA, NA)
)

if (any(is.na(dat$pval.outcome))) {
if ("beta.outcome" %in% names(dat) && "se.outcome" %in% names(dat)) {
index <- is.na(dat$pval.outcome)
dat$pval.outcome[index] <- stats::pnorm(abs(dat$beta.outcome[index])/dat$se.outcome[index], lower.tail = FALSE)
dat$pval_origin.outcome[index] <- "inferred"
}
}
print(dat)

Compare with:

dat$pval.outcome <- 2 * stats::pnorm(abs(dat$beta.outcome)/dat$se.outcome, lower.tail = FALSE)
print(dat)

Please provide a minimal code snippet that will reproduce this issue

Contribute a solution (optional)

Please submit a pull request and/or briefly describe your proposed solution

System information

Please provide details of your operating system and R version

Additional context

Add any other context about the problem here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions