Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
albfranc authored and cran-robot committed Nov 13, 2023
0 parents commit 05e7c6c
Show file tree
Hide file tree
Showing 66 changed files with 2,179 additions and 0 deletions.
29 changes: 29 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Package: OVL.CI
Type: Package
Title: Inference on the Overlap Coefficient: The Binormal Approach and
Alternatives
Version: 0.1.0
Authors@R: c(
person("Alba M. Franco-Pereira", role = c("aut", "cre","cph"), email = "albfranc@ucm.es"),
person("Christos T. Nakas", role = "aut"),
person("Benjamin Reiser", role = "aut"),
person("M.Carmen Pardo", role = "aut"))
Maintainer: Alba M. Franco-Pereira <albfranc@ucm.es>
Description: Provides functions to construct confidence intervals for the Overlap Coefficient (OVL). OVL measures the similarity between two distributions through the overlapping area of their distribution functions. Given its intuitive description and ease of visual representation by the straightforward depiction of the amount of overlap between the two corresponding histograms based on samples of measurements from each one of the two distributions, the development of accurate methods for confidence interval construction can be useful for applied researchers. Implements methods based on the work of Franco-Pereira, A.M., Nakas, C.T., Reiser, B., and Pardo, M.C. (2021) <doi:10.1177/09622802211046386>.
License: GPL-2
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.2.3
Imports: ks
Depends: R (>= 2.10)
Suggests: testthat (>= 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2023-11-12 16:53:32 UTC; Alba
Author: Alba M. Franco-Pereira [aut, cre, cph],
Christos T. Nakas [aut],
Benjamin Reiser [aut],
M.Carmen Pardo [aut]
Repository: CRAN
Date/Publication: 2023-11-13 17:43:18 UTC
65 changes: 65 additions & 0 deletions MD5
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
e4693a75c15136c611c1c141dc544d27 *DESCRIPTION
fa12e29c608d52123c6b8d3dbf2f0823 *NAMESPACE
0c2e62b0d72e6a0551283341ec8a0998 *NEWS.md
8e38ab4379e0b3e525fb37e36d7e8cb8 *R/OVL.BCAN.R
381d2e9d1989d745e3c44d7415b3d110 *R/OVL.BCPB.R
99a9cc7f52b84e30ab6f75b96392bf1d *R/OVL.BCbias.R
af3a24f1975bde18c645613bff6e2a87 *R/OVL.D.R
aae02bd310cdefccd88d8d8b2aad629c *R/OVL.DBC.R
e5b5d6a00e1986340dd91b8f7cbc5799 *R/OVL.DBCL.R
7d776aacb5cef1b4dc5c03bfbc0ec441 *R/OVL.K.R
d718047b1b7c30ebcbd4a18a3bc2b25b *R/OVL.KPB.R
ca6609cddf4d0d8dfd1be6873f7f6d16 *R/OVL.LogitBCAN.R
72b766dd7353168b1a46db8c789398a9 *R/OVL.LogitD.R
d55a6eac1870ccaf358abe9199e85b84 *R/OVL.LogitDBC.R
0a7d2a01e4cc72eb970d2f9a97be52eb *R/OVL.LogitDBCL.R
43f95b5e963626a41368533b1d86f955 *R/OVL.LogitK.R
600560b92662f3dd3c08f0e22f4f4be0 *R/U.R
bae069d1f9e27687f69605e4b9469c5f *R/data.R
bf00caa715d2be358808e020bec3259f *R/kernel.e.R
31e00a594097b38e50263b5b2bbca4a5 *R/kernel.e.density.R
5a01a85c875c9485ebf6597673d89de2 *R/kernel.g.R
7cb6c5614f809a95054df4c3bb18e7d9 *R/kernel.g.density.R
7d13dcf59de07e02ad5fd84fadeedd49 *R/likbox.R
26c1b4419cd79a7464fc1249798b4bfd *R/ssdd.R
7eee0a7f3cc81096a899072a976722c8 *data/test_data.rda
bcae6dd9b935842231abb4c2a30bf247 *man/OVL.BCAN.Rd
23927fdb3bc565c2734593dbb21fd756 *man/OVL.BCPB.Rd
f938f01d1bf949989432c297e7c2e63d *man/OVL.BCbias.Rd
d9d882ccf74c3fbd928a493144c26be1 *man/OVL.D.Rd
ddb795ed876c20476f2882ce609174b9 *man/OVL.DBC.Rd
936bdd965e87ddf342778bc95100a773 *man/OVL.DBCL.Rd
3f1ad66c0b7bedb9b8f407c774c17af7 *man/OVL.K.Rd
25e89329e070345c8771ff100e062ccb *man/OVL.KPB.Rd
451732f5736a56208e541564ce033754 *man/OVL.LogitBCAN.Rd
30d80ea73c4a4abf479eae4ab192467f *man/OVL.LogitD.Rd
ed7806ac24b0bce557645c91d0aa477c *man/OVL.LogitDBC.Rd
fb1e4fb3fce74d8d0bdf5865073aebde *man/OVL.LogitDBCL.Rd
c5908017923831a971cec4762937c432 *man/OVL.LogitK.Rd
ac5470b9fa1fe99564a8857f17d15e02 *man/U.Rd
030665cbc18d4f4b32112112e84b90fa *man/kernel.e.Rd
e63927e2d63eed634f1c710f3491dfd6 *man/kernel.e.density.Rd
6984b7bd0743dc5185b53a9e6db56199 *man/kernel.g.Rd
a0b6cf653cafd967b0c91d841302b40e *man/kernel.g.density.Rd
437c5765eea839ba54502d38f179e8c0 *man/likbox.Rd
4745b5a43310ba3971dcc21447f3d1ef *man/ssdd.Rd
a93d956b35b257c99ab0653d43fd1045 *man/test_data.Rd
1541877e3ad3597dcd343d1887d34a95 *tests/testthat.R
311d5d83a972c47d7efe76ede8e1746f *tests/testthat/test_LogitBCAN.R
7d1db2627ef2c902d0733227b2b0901d *tests/testthat/test_LogitD.R
e1de623750c15a2fd603c3a50643099a *tests/testthat/test_LogitDBC.R
c85719a247861cac7bf714714e35f948 *tests/testthat/test_LogitDBCL.R
01865427b372c3e1081b2e82cc256187 *tests/testthat/test_LogitK.R
dc31b6b901f04bc2bc7bce47a815d7c1 *tests/testthat/test_OVL.BCAN.R
c8a983e6ebbb68ec03843999dd60e0ea *tests/testthat/test_OVL.BCPB.R
648684e3db976dc53621a8068603bcef *tests/testthat/test_OVL.BCbias.R
288e757336e564a8db02a3038f0f7f10 *tests/testthat/test_OVL.D.R
475b7cefff82c567645a7fcda97bb2b8 *tests/testthat/test_OVL.DBC.R
3f7d7674a3186d84780e69efd6e2940c *tests/testthat/test_OVL.DBCL.R
a497531acd068a8a3aa4d75058ccba1e *tests/testthat/test_OVL.K.R
65edfaf662539d7e9adc0b6b516edd9b *tests/testthat/test_OVL.KPB.R
93f7df1a44feb75a781e4015a5b0249c *tests/testthat/test_U.R
159686dca949c862929151b725b28917 *tests/testthat/test_kernel.e&kernel.e.R
d8dff68dd26194571dfa88ab46f3a9fe *tests/testthat/test_kernel.e.density&test_kernel.g.density.R
1798206d2c8fa86a88cc572fd8241772 *tests/testthat/test_likbox.R
478a717537523956a3d1efffaa078195 *tests/testthat/test_ssdd.R
29 changes: 29 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by roxygen2: do not edit by hand

export(OVL.BCAN)
export(OVL.BCPB)
export(OVL.BCbias)
export(OVL.D)
export(OVL.DBC)
export(OVL.DBCL)
export(OVL.K)
export(OVL.KPB)
export(OVL.LogitBCAN)
export(OVL.LogitD)
export(OVL.LogitDBC)
export(OVL.LogitDBCL)
export(OVL.LogitK)
export(U)
export(kernel.e)
export(kernel.e.density)
export(kernel.g)
export(kernel.g.density)
export(likbox)
export(ssdd)
importFrom(stats,dnorm)
importFrom(stats,optim)
importFrom(stats,pnorm)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stats,var)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OVL.CI 0.1.0

* Added a `NEWS.md` file to track changes to the package.
85 changes: 85 additions & 0 deletions R/OVL.BCAN.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#' @title OVL.BCAN
#' @description Parametric approach using a bootstrap-based approach to estimate the variance
#' @param x controls
#' @param y cases
#' @param alpha confidence level
#' @param B bootstrap size
#' @param h_ini initial value in the optimization problem
#' @return confidence interval
#' @export OVL.BCAN
#' @importFrom stats dnorm optim pnorm qnorm quantile sd var
#' @examples
#' controls = rnorm(50,6,1)
#' cases = rnorm(100,6.5,0.5)
#' OVL.BCAN (controls,cases)
OVL.BCAN<-function(x,y,alpha=0.05,B=100,h_ini=-0.6){
x_aux<-x
y_aux<-y
all_values<-c(x_aux,y_aux)
if (any(all_values<=0)){
x<-x_aux+abs(min(all_values))+(max(all_values)-min(all_values))/2
y<-y_aux+abs(min(all_values))+(max(all_values)-min(all_values))/2
} else {
x<-x_aux
y<-y_aux
}
xo<-x
yo<-y
hhat<-optim(h_ini,likbox,data=c(xo,yo),n=length(xo),method="BFGS")$par
if (abs(hhat)<1e-5){
x<-log(xo)
y<-log(yo)
} else {
x<-((xo^hhat)-1)/hhat
y<-((yo^hhat)-1)/hhat
}
if(ssdd(x)<ssdd(y)){
muestra1<-x
muestra2<-y
} else {
muestra1<-y
muestra2<-x
}
mu1_hat<-mean(muestra1)
mu2_hat<-mean(muestra2)
sigma1_hat<-ssdd(muestra1)
sigma2_hat<-ssdd(muestra2)
x1<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)-sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
x2<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)+sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
OVL<-1+pnorm((x1-mu1_hat)/sigma1_hat)-pnorm((x1-mu2_hat)/sigma2_hat)-pnorm((x2-mu1_hat)/sigma1_hat)+pnorm((x2-mu2_hat)/sigma2_hat)
OVL_ib<-numeric(B)
for (b in 1:B){
xo_ib<-sample(xo,replace=TRUE,size=length(x))
yo_ib<-sample(yo,replace=TRUE,size=length(y))
hhat<-optim(h_ini,likbox,data=c(xo_ib,yo_ib),n=length(xo_ib),method="BFGS")$par
if (abs(hhat)<1e-5){
x<-log(xo_ib)
y<-log(yo_ib)
} else {
x<-((xo_ib^hhat)-1)/hhat
y<-((yo_ib^hhat)-1)/hhat
}
if(ssdd(x)<ssdd(y)){
muestra1<-x
muestra2<-y
} else {
muestra1<-y
muestra2<-x
}
mu1_hat<-mean(muestra1)
mu2_hat<-mean(muestra2)
sigma1_hat<-ssdd(muestra1)
sigma2_hat<-ssdd(muestra2)
x1<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)-sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
x2<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)+sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
OVL_ib[b]<-1+pnorm((x1-mu1_hat)/sigma1_hat)-pnorm((x1-mu2_hat)/sigma2_hat)-pnorm((x2-mu1_hat)/sigma1_hat)+pnorm((x2-mu2_hat)/sigma2_hat)
}
var_OVL<-var(OVL_ib,na.rm=TRUE)
IC1<-OVL-qnorm(1-alpha/2)*sqrt(var_OVL)
IC1_aux<-IC1
if(IC1<0){IC1<-0}else{IC1<-IC1_aux}
IC2<-OVL+qnorm(1-alpha/2)*sqrt(var_OVL)
IC2_aux<-IC2
if(IC2>1){IC2<-1}else{IC2<-IC2_aux}
return(list(IC1,IC2))
}
81 changes: 81 additions & 0 deletions R/OVL.BCPB.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#' @title OVL.BCPB
#' @description Parametric approach using a bootstrap percentil approach to estimate the variance
#' @param x controls
#' @param y cases
#' @param alpha confidence level
#' @param B bootstrap size
#' @param h_ini initial value in the optimization problem
#' @return confidence interval
#' @export OVL.BCPB
#' @importFrom stats dnorm optim pnorm qnorm quantile sd var
#' @examples
#' controls = rnorm(50,6,1)
#' cases = rnorm(100,6.5,0.5)
#' OVL.BCPB (controls,cases)
OVL.BCPB<-function(x,y,alpha=0.05,B=100,h_ini=-0.6){
x_aux<-x
y_aux<-y
all_values<-c(x_aux,y_aux)
if (any(all_values<=0)){
x<-x_aux+abs(min(all_values))+(max(all_values)-min(all_values))/2
y<-y_aux+abs(min(all_values))+(max(all_values)-min(all_values))/2
} else {
x<-x_aux
y<-y_aux
}
xo<-x
yo<-y
hhat<-optim(h_ini,likbox,data=c(xo,yo),n=length(xo),method="BFGS")$par
if (abs(hhat)<1e-5){
x<-log(xo)
y<-log(yo)
} else {
x<-((xo^hhat)-1)/hhat
y<-((yo^hhat)-1)/hhat
}
if(ssdd(x)<ssdd(y)){
muestra1<-x
muestra2<-y
} else {
muestra1<-y
muestra2<-x
}
mu1_hat<-mean(muestra1)
mu2_hat<-mean(muestra2)
sigma1_hat<-ssdd(muestra1)
sigma2_hat<-ssdd(muestra2)
x1<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)-sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
x2<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)+sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
OVL<-1+pnorm((x1-mu1_hat)/sigma1_hat)-pnorm((x1-mu2_hat)/sigma2_hat)-pnorm((x2-mu1_hat)/sigma1_hat)+pnorm((x2-mu2_hat)/sigma2_hat)
OVL_ib<-numeric(B)
for (b in 1:B){
xo_ib<-sample(xo,replace=TRUE)
yo_ib<-sample(yo,replace=TRUE)
hhat<-optim(h_ini,likbox,data=c(xo_ib,yo_ib),n=length(xo_ib),method="BFGS")$par
if (abs(hhat)<1e-5){
x<-log(xo_ib)
y<-log(yo_ib)
} else {
x<-((xo_ib^hhat)-1)/hhat
y<-((yo_ib^hhat)-1)/hhat
}
if(ssdd(x)<ssdd(y)){
muestra1<-x
muestra2<-y
} else {
muestra1<-y
muestra2<-x
}
mu1_hat<-mean(muestra1)
mu2_hat<-mean(muestra2)
sigma1_hat<-ssdd(muestra1)
sigma2_hat<-ssdd(muestra2)

x1<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)-sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
x2<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)+sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
OVL_ib[b]<-1+pnorm((x1-mu1_hat)/sigma1_hat)-pnorm((x1-mu2_hat)/sigma2_hat)-pnorm((x2-mu1_hat)/sigma1_hat)+pnorm((x2-mu2_hat)/sigma2_hat)
}
IC1<-quantile(OVL_ib,alpha/2,na.rm=TRUE)
IC2<-quantile(OVL_ib,1-alpha/2,na.rm=TRUE)
return(list(IC1,IC2))
}
84 changes: 84 additions & 0 deletions R/OVL.BCbias.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#' @title OVL.BCbias
#' @description Parametric approach using a bootstrap bias-corrected approach
#' @param x controls
#' @param y cases
#' @param alpha confidence level
#' @param B bootstrap size
#' @param h_ini initial value in the optimization problem
#' @return confidence interval
#' @export OVL.BCbias
#' @importFrom stats dnorm optim pnorm qnorm quantile sd var
#' @examples
#' controls = rnorm(50,6,1)
#' cases = rnorm(100,6.5,0.5)
#' OVL.BCAN (controls,cases)
OVL.BCbias<-function(x,y,alpha=0.05,B=100,h_ini=-0.6){
x_aux<-x
y_aux<-y
all_values<-c(x_aux,y_aux)
if (any(all_values<=0)){
x<-x_aux+abs(min(all_values))+(max(all_values)-min(all_values))/2
y<-y_aux+abs(min(all_values))+(max(all_values)-min(all_values))/2
} else {
x<-x_aux
y<-y_aux
}
xo<-x
yo<-y
hhat<-optim(h_ini,likbox,data=c(xo,yo),n=length(xo),method="BFGS")$par
if (abs(hhat)<1e-5){
x<-log(xo)
y<-log(yo)
} else {
x<-((xo^hhat)-1)/hhat
y<-((yo^hhat)-1)/hhat
}
if(ssdd(x)<ssdd(y)){
muestra1<-x
muestra2<-y
} else {
muestra1<-y
muestra2<-x
}
mu1_hat<-mean(muestra1)
mu2_hat<-mean(muestra2)
sigma1_hat<-ssdd(muestra1)
sigma2_hat<-ssdd(muestra2)
x1<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)-sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
x2<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)+sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
OVL<-1+pnorm((x1-mu1_hat)/sigma1_hat)-pnorm((x1-mu2_hat)/sigma2_hat)-pnorm((x2-mu1_hat)/sigma1_hat)+pnorm((x2-mu2_hat)/sigma2_hat)
OVL_ib<-numeric(B)
for (b in 1:B){
xo_ib<-sample(xo,replace=TRUE)
yo_ib<-sample(yo,replace=TRUE)
hhat<-optim(h_ini,likbox,data=c(xo_ib,yo_ib),n=length(xo_ib),method="BFGS")$par
if (abs(hhat)<1e-5){
x<-log(xo_ib)
y<-log(yo_ib)
} else {
x<-((xo_ib^hhat)-1)/hhat
y<-((yo_ib^hhat)-1)/hhat
}
if(ssdd(x)<ssdd(y)){
muestra1<-x
muestra2<-y
} else {
muestra1<-y
muestra2<-x
}
mu1_hat<-mean(muestra1)
mu2_hat<-mean(muestra2)
sigma1_hat<-ssdd(muestra1)
sigma2_hat<-ssdd(muestra2)
x1<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)-sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
x2<-((mu1_hat*sigma2_hat^2-mu2_hat*sigma1_hat^2)+sigma1_hat*sigma2_hat*sqrt((mu1_hat-mu2_hat)^2+(sigma1_hat^2-sigma2_hat^2)*log(sigma1_hat^2/sigma2_hat^2)))/(sigma2_hat^2-sigma1_hat^2)
OVL_ib[b]<-1+pnorm((x1-mu1_hat)/sigma1_hat)-pnorm((x1-mu2_hat)/sigma2_hat)-pnorm((x2-mu1_hat)/sigma1_hat)+pnorm((x2-mu2_hat)/sigma2_hat)
}
z0<-qnorm(mean(OVL_ib<=OVL,na.rm=TRUE))
alpha1<-pnorm(2*z0+qnorm(alpha/2))
alpha2<-pnorm(2*z0+qnorm(1-alpha/2))
IC1<-quantile(OVL_ib,alpha1,na.rm=TRUE)
IC2<-quantile(OVL_ib,alpha2,na.rm=TRUE)
return(list(IC1,IC2))
}

0 comments on commit 05e7c6c

Please sign in to comment.