Skip to content

Commit

Permalink
v0.6.5 rr mn bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jan 14, 2022
1 parent b015fe5 commit 2aa1e76
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClinicalTrialUtilities"
uuid = "535c2557-d7d0-564d-8ff9-4ae146c18cfe"
authors = ["Vladimir Arnautov (mail@pharmcat.net)"]
version = "0.6.4"
version = "0.6.5"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
20 changes: 10 additions & 10 deletions src/ci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ end
a = n2*(lim-1)
b = n1*lim+n2-(x1+x2)*(lim-1)
c = -(x1+x2)
p2d = (-b+sqrt(b^2-4*a*c))/(2*a)
p2d = (-b+sqrt(b^2-4*a*c))/2a
p1d = p2d*lim/(1+p2d*(lim-1))
score = ((n1*(px-p1d))^2)*(1/(n1*p1d*(1-p1d))+1/(n2*p2d*(1-p2d)))*(n1+n2-1)/(n1+n2)
ci = lim
Expand All @@ -494,7 +494,7 @@ end
a = n2*-1)
b = φ*n1+n2-(x1+x2)*-1)
c = -(x1 + x2)
p2 = (-b+sqrt(b*b-4*a*c))/a/2
p2 = (-b+sqrt(b*b - 4a * c))/2a
p1 = p2*φ/(1+p2*-1))
return p1, p2
end
Expand Down Expand Up @@ -666,10 +666,10 @@ end
b = -(1 + theta + p1 + theta * p2 + Δ*(theta + 2))
c = Δ^2 + Δ*(2 * p1 + theta + 1) + p1 + theta * p2
d = -p1*Δ*(1 + Δ)
v = (b/a/3)^3 - b*c/(6*a*a) + d/2/a
u = sign(v) * sqrt((b/3/a)^2 - c/3/a)
v = (b/3a)^3 - b*c/(6*a*a) + d/2a
u = sign(v) * sqrt((b/3a)^2 - c/3a)
w = (pi + acos(v/u^3))/3
p1n = 2*u*cos(w) - b/3/a
p1n = 2u*cos(w) - b/3a
p2n = p1n - Δ
return p1n * (1-p1n)/n1 + p2n * (1 - p2n)/n2
end
Expand Down Expand Up @@ -720,18 +720,18 @@ end
#Miettinen-Nurminen Score interval
#Miettinen, O. and Nurminen, M. (1985), Comparative analysis of two rates. Statist. Med., 4: 213-226. doi:10.1002/sim.4780040211
@inline function mlemnrr(φ, x1::Int, n1::Int, x2::Int, n2::Int)
a = (n1+n2)*φ
b = -*(x1+n2)+x2+n1)
a = (n1 + n2) * φ
b = - *(x2 + n1) + x1 + n2)
c = x1 + x2
p2 = (-b-sqrt(b*b-4*a*c))/2/a
p1 = p2*φ
p2 = (-b-sqrt(b*b-4a*c))/2a
p1 = p2 * φ
return p1, p2
end
@inline function mnrrval(φ, x1::Int, n1::Int, x2::Int, n2::Int, z)
p1 = x1/n1
p2 = x2/n2
pmle1, pmle2 = mlemnrr(φ, x1, n1, x2, n2)
return ((p1 - φ*p2)^2)/((pmle1*(1-pmle1)/n1 + φ*φ*pmle2*(1-pmle2)/n2)*((n1+n2-1)/(n1+n2)))-z
return ((p1 - φ*p2)^2)/((pmle1*(1-pmle1)/n1 + φ*φ*pmle2*(1-pmle2)/n2)*(n1+n2)/(n1+n2-1)) - z
end
function proprrmnci(x1::Int, n1::Int, x2::Int, n2::Int, alpha)
z = quantile(Chisq(1), 1 - alpha)
Expand Down
10 changes: 5 additions & 5 deletions test/citest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ println(" ---------------------------------- ")
#-- mn

ci = ClinicalTrialUtilities.rrpropci(30, 100, 40, 90; alpha=0.05, method=:mn)
@test ci.lower 0.46636099123297575 atol=1E-6
@test ci.upper 0.9799258384796817 atol=1E-6
@test ci.lower 0.461480914884656 atol=1E-6
@test ci.upper 0.9801801210729479 atol=1E-6
@test ci.estimate 0.675 atol=1E-6
@test ci.estimate StatsBase.confint(ClinicalTrialUtilities.RiskRatio(ClinicalTrialUtilities.Proportion(30, 100),
ClinicalTrialUtilities.Proportion(40, 90)); level = 0.95, method = :mn).estimate
Expand All @@ -161,11 +161,11 @@ println(" ---------------------------------- ")

ci = ClinicalTrialUtilities.rrpropci(0, 100, 90, 90; alpha=0.05, method=:mn)
@test ci.lower 0.0
@test ci.upper 0.018137090385952483 atol=1E-6
@test ci.upper 0.03680596180211699 atol=1E-6
@test ci.estimate 0.0

ci = ClinicalTrialUtilities.rrpropci(100, 100, 0, 90; alpha=0.05, method=:mn)
@test ci.lower 44.84369729432598 atol=1E-2 #v 44.8498645475395
ci = ClinicalTrialUtilities.rrpropci(100, 100, 0, 70; alpha=0.05, method=:mn)
@test ci.lower 19.32220093816104 atol=1E-2 #v 44.8498645475395
@test ci.upper Inf
@test ci.estimate Inf

Expand Down

2 comments on commit 2aa1e76

@PharmCat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/52428

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.5 -m "<description of version>" 2aa1e76f3c2f976b985681bb1cefa299b7f04fec
git push origin v0.6.5

Please sign in to comment.