-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added computation of MDRR for logistic models.
- Loading branch information
Showing
6 changed files
with
62 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: CohortMethod | ||
Type: Package | ||
Title: New-User Cohort Method with Large Scale Propensity and Outcome Models | ||
Version: 5.3.0 | ||
Date: 2024-05-31 | ||
Version: 5.4.0 | ||
Date: 2024-09-27 | ||
Authors@R: c( | ||
person("Martijn", "Schuemie", , "[email protected]", role = c("aut", "cre")), | ||
person("Marc", "Suchard", role = c("aut")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
library(testthat) | ||
library(CohortMethod) | ||
|
||
test_that("Logistic regression power calculations", { | ||
alpha <- 0.05 # Significance level | ||
power <- 0.80 # Desired power | ||
p_null <- 0.1 # Baseline probability of event | ||
n <- 400 # Sample size | ||
|
||
mdrr <- CohortMethod:::computeMdrrFromAggregateStats(pTarget = NA, | ||
totalEvents = n * p_null, | ||
totalSubjects = n, | ||
alpha = alpha, | ||
power = power, | ||
twoSided = TRUE, | ||
modelType = "logistic") | ||
|
||
|
||
|
||
# Estimate the coefficient (log(odds ratio)) | ||
beta <- log(mdrr) | ||
|
||
# Estimate the standard error (for a simple logistic model, it's based on p_null and sample size) | ||
se_beta <- sqrt((1 / (n * p_null * (1 - p_null)))) | ||
|
||
# Wald Z statistic | ||
z_value <- beta / se_beta | ||
|
||
# Determine power using normal distribution | ||
z_critical <- qnorm(1 - alpha / 2) | ||
power_achieved <- pnorm(z_value - z_critical) | ||
|
||
expect_equal(power_achieved, power, tolerance = 1e-3) | ||
}) |