Skip to content

Commit 3bb67c2

Browse files
authored
Merge pull request #1 from Zadchow/testing
v 2.0
2 parents edf5658 + 83d0759 commit 3bb67c2

91 files changed

Lines changed: 2309 additions & 1482 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

0 Bytes
Binary file not shown.

DESCRIPTION

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: concurve
22
Type: Package
3-
Date: 2019-05-16
3+
Date: 2019-07-10
44
Title: Computes and Plots Consonance (Confidence) Intervals, P-Values, and S-Values to Form Consonance and Surprisal Functions
5-
Version: 1.1.0
5+
Version: 2.0
66
Authors@R: c(
77
person("Zad R.", "Chow", , "zad@lesslikely.com", role = c("aut", "cre"),
88
comment = c(ORCID = "0000-0003-1545-8199")
@@ -13,9 +13,11 @@ Authors@R: c(
1313
)
1414
Maintainer: Zad R. Chow <zad@lesslikely.com>
1515
Description: Allows one to compute consonance (confidence) intervals for various statistical tests along with their corresponding P-values and S-values. The intervals can be plotted to create consonance and surprisal functions allowing one to see what effect sizes are compatible with the test model at various consonance levels rather than being limited to one interval estimate such as 95%. These methods are discussed by Poole C. (1987) <doi:10.2105/AJPH.77.2.195>, Schweder T, Hjort NL. (2002) <doi:10.1111/1467-9469.00285>, Singh K, Xie M, Strawderman WE. (2007) <arXiv:0708.0976>, Rothman KJ, Greenland S, Lash TL. (2008, ISBN:9781451190052), Amrhein V, Trafimow D, Greenland S. (2019) <doi:10.1080/00031305.2018.1543137>, and Greenland S. (2019) <doi:10.1080/00031305.2018.1529625>.
16-
Imports: ggplot2,
16+
Imports: parallel,
17+
ggplot2,
1718
metafor,
18-
dplyr,
19+
dplyr,
20+
tibble,
1921
survival,
2022
survminer,
2123
scales

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
exportPattern("^[[:alpha:]]+")
2+
import(parallel)
23
import(ggplot2)
34
import(dplyr)
5+
import(tibble)
46
import(survival)
57
import(survminer)
68
import(metafor)
79
import(scales)
810
importFrom("stats", "coef", "confint", "confint.default", "confint.lm",
911
"lm", "quantile", "t.test", "cor.test", "qnorm")
12+
importFrom("graphics", "axis", "par", "polygon", "text")
13+
importFrom("stats", "logLik", "model.frame", "model.matrix",
14+
"model.response", "na.fail")
1015
importFrom("utils", "head")

NEWS.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
# concurve 2.0
2+
3+
## Major changes
4+
5+
* The `plotpint()` function which plotted consonance functions has been repackaged into `ggconcurve()`.
6+
* The `plotsint()` function which plotted surprisal functions has been repackaged into `ggconcurve()`.
7+
* Functions can now also be plotted with base R via the `plot_concurve()` function.
8+
* Consonance functions can be plotted as a pyramid (right side up) or inverted (upside down) via the "position" item in `ggconcurve()`.
9+
* Null values (for means & ratios) can be plotted via the `ggconcurve()` function to show how much of the interval surrounds it.
10+
* Log transformations included in all the plotting functions for ratio measures.
11+
* Parallel programming has now been implemented into the computations via the `mclapply()` function from the *parallel* package.
12+
13+
114
# concurve 1.08
215

316
## Major changes
417

5-
* Can produce consonance and surprisal functions for correlations via the `corrintervals` function.
6-
* Now able to construct consonance and surprisal functions from the point estiate, and confidence limits via the `reveng` function.
7-
* Graphs produced via the `plotpint` or `plotsint` function now able to take custom titles, subtitles, x-axis titles, and captions.
18+
* Can produce consonance and surprisal functions for correlations via the `corrintervals()` function.
19+
* Now able to construct consonance and surprisal functions from the point estiate, and confidence limits via the `rev_eng()` function.
20+
* Graphs produced via the `plotpint()` or `plotsint()` function now able to take custom titles, subtitles, x-axis titles, and captions.
821

922
# concurve 1.07
1023

R/.DS_Store

0 Bytes
Binary file not shown.

R/corrintervals.R renamed to R/curve_corr.R

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
corrintervals <- function(x, y, alternative, method, steps = 10000) {
2-
3-
if(is.numeric(x) != TRUE){
1+
curve_corr <- function(x, y, alternative, method, steps = 10000) {
2+
if (is.numeric(x) != TRUE) {
43
stop("Error: 'x' must be a numeric vector")
54
}
6-
if(is.numeric(y) != TRUE){
5+
if (is.numeric(y) != TRUE) {
76
stop("Error: 'y' must be a numeric vector")
87
}
9-
if(is.numeric(steps) != TRUE){
8+
if (is.numeric(steps) != TRUE) {
109
stop("Error: 'steps' must be a numeric vector")
1110
}
1211

13-
intrvls <- (0:steps)/steps
14-
results <- lapply(intrvls, FUN = function(i) cor.test(x, y, alternative = alternative, method = method,
15-
exact = NULL, conf.level = i, continuity = FALSE)$conf.int[])
16-
df<-data.frame(do.call(rbind, results))
12+
intrvls <- (0:steps) / steps
13+
results <- mclapply(intrvls, FUN = function(i) cor.test(x, y,
14+
alternative = alternative, method = method,
15+
exact = NULL, conf.level = i, continuity = FALSE
16+
)$conf.int[])
17+
df <- data.frame(do.call(rbind, results))
1718
intrvl.limit <- c("lower.limit", "upper.limit")
1819
colnames(df) <- intrvl.limit
1920
df$intrvl.level <- intrvls
2021
df$pvalue <- 1 - intrvls
2122
df$svalue <- -log2(df$pvalue)
22-
df<-head(df, -1)
23+
df <- head(df, -1)
2324
return(df)
2425
}
2526

R/curve_gen.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# General Consonance Functions Using Profile Likelihood, Wald, or the bootstrap method for linear models.
2+
3+
curve_gen <- function(model, var, method = "default", replicates = 1000, steps = 10000) {
4+
if (is.list(model) != TRUE) {
5+
stop("Error: 'model' must be an object with a statistical model")
6+
}
7+
if (is.character(method) != TRUE) {
8+
stop("Error: 'method' must be a character vector")
9+
}
10+
if (is.numeric(replicates) != TRUE) {
11+
stop("Error: 'replicates' must be a numeric vector")
12+
}
13+
if (is.numeric(steps) != TRUE) {
14+
stop("Error: 'steps' must be a numeric vector")
15+
}
16+
intrvls <- (0:steps) / steps
17+
if (method == "default") {
18+
results <- mclapply(intrvls, FUN = function(i) confint(object = model, level = i)[var, ])
19+
} else if (method == "Wald") {
20+
results <- mclapply(intrvls, FUN = function(i) confint.default(object = model, level = i)[var, ])
21+
} else if (method == "lm") {
22+
results <- mclapply(intrvls, FUN = function(i) confint.lm(object = model, level = i)[var, ])
23+
} else if (method == "boot") {
24+
effect <- coef(model)[[var]]
25+
boot_dist <- replicate(replicates,
26+
expr = coef(lm(model$call$formula,
27+
data = model$model[sample(nrow(model$model), replace = T), ]
28+
))[[var]]
29+
) - effect
30+
results <- mclapply(intrvls, FUN = function(i) effect - quantile(boot_dist, probs = (1 + c(i, -i)) / 2))
31+
}
32+
33+
df <- data.frame(do.call(rbind, results))
34+
intrvl.limit <- c("lower.limit", "upper.limit")
35+
colnames(df) <- intrvl.limit
36+
df$intrvl.level <- intrvls
37+
df$pvalue <- 1 - intrvls
38+
df$svalue <- -log2(df$pvalue)
39+
df <- head(df, -1)
40+
return(df)
41+
}
42+
43+
# RMD Check
44+
utils::globalVariables(c("df", "lower.limit", "upper.limit", "intrvl.level", "pvalue", "svalue"))

R/curve_mean.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Mean Interval Consonance Function
2+
3+
curve_mean <- function(x, y, data, paired = F, method = "default", replicates = 1000, steps = 10000) {
4+
if (is.numeric(x) != TRUE) {
5+
stop("Error: 'x' must be a numeric vector")
6+
}
7+
if (is.numeric(y) != TRUE) {
8+
stop("Error: 'y' must be a numeric vector")
9+
}
10+
if (is.data.frame(data) != TRUE) {
11+
stop("Error: 'data' must be a data frame")
12+
}
13+
if (is.numeric(replicates) != TRUE) {
14+
stop("Error: 'replicates' must be a numeric vector")
15+
}
16+
if (is.numeric(steps) != TRUE) {
17+
stop("Error: 'steps' must be a numeric vector")
18+
}
19+
intrvls <- (0:steps) / steps
20+
if (method == "default") {
21+
results <- mclapply(intrvls, FUN = function(i) t.test(x, y, data = data, paired = paired, conf.level = i)$conf.int[])
22+
} else if (method == "boot") {
23+
diff <- mean(x) - mean(y)
24+
if (paired) {
25+
diffs <- x - y
26+
boot_dist <- replicate(replicates,
27+
expr = mean(diffs[sample(length(diffs), replace = T)])
28+
) - diff
29+
} else {
30+
boot_dist <- replicate(replicates,
31+
expr = mean(sample(x, length(x), replace = T)) -
32+
mean(sample(y, length(y), replace = T))
33+
) - diff
34+
}
35+
results <- mclapply(intrvls, FUN = function(i) diff - quantile(boot_dist, probs = (1 + c(i, -i)) / 2))
36+
}
37+
df <- data.frame(do.call(rbind, results))
38+
intrvl.limit <- c("lower.limit", "upper.limit")
39+
colnames(df) <- intrvl.limit
40+
df$intrvl.level <- intrvls
41+
df$pvalue <- 1 - intrvls
42+
df$svalue <- -log2(df$pvalue)
43+
df <- head(df, -1)
44+
return(df)
45+
}
46+
47+
# RMD Check
48+
utils::globalVariables(c("df", "lower.limit", "upper.limit", "intrvl.level", "pvalue", "svalue"))

R/metaintervals.R renamed to R/curve_meta.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# Meta-analytic Consonance Function
22

3-
metaintervals<-function(x, measure = "default", steps = 10000) {
4-
if(is.list(x) != TRUE){
3+
curve_meta <- function(x, measure = "default", steps = 10000) {
4+
if (is.list(x) != TRUE) {
55
stop("Error: 'x' must be a list from 'metafor'")
66
}
7-
if(is.character(measure) != TRUE){
7+
if (is.character(measure) != TRUE) {
88
stop("Error: 'measure' must be a string such as 'default' or 'ratio'")
99
}
10-
if(is.numeric(steps) != TRUE){
10+
if (is.numeric(steps) != TRUE) {
1111
stop("Error: 'steps' must be a numeric vector")
1212
}
13-
intrvls <- (0:steps)/steps
14-
results <- lapply(intrvls, FUN = function(i) confint.default(object = x, fixed = TRUE, random = FALSE, level = i)[])
15-
df<-data.frame(do.call(rbind, results))
13+
intrvls <- (0:steps) / steps
14+
results <- mclapply(intrvls, FUN = function(i) confint.default(object = x, fixed = TRUE, random = FALSE, level = i)[])
15+
df <- data.frame(do.call(rbind, results))
1616
intrvl.limit <- c("lower.limit", "upper.limit")
1717
colnames(df) <- intrvl.limit
1818
df$intrvl.level <- intrvls
1919
df$pvalue <- 1 - intrvls
2020
df$svalue <- -log2(df$pvalue)
21-
if(measure == "default") {
21+
if (measure == "default") {
2222
df$lower.limit <- df$lower.limit
2323
df$upper.limit <- df$upper.limit
24-
} else if(measure == "ratio") {
24+
} else if (measure == "ratio") {
2525
df$lower.limit <- exp(df$lower.limit)
2626
df$upper.limit <- exp(df$upper.limit)
2727
}
28-
df<-head(df, -1)
28+
df <- head(df, -1)
2929
return(df)
3030
}
3131

R/curve_rev.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Reverse Engineer Consonance Functions Using the Point Estimate and Confidence Limits
2+
3+
curve_rev <- function(point, LL, UL, measure = "default") {
4+
if (is.numeric(point) != TRUE) {
5+
stop("Error: 'x' must be a numeric vector")
6+
}
7+
if (is.numeric(LL) != TRUE) {
8+
stop("Error: 'y' must be a numeric vector")
9+
}
10+
if (is.numeric(UL) != TRUE) {
11+
stop("Error: 'y' must be a numeric vector")
12+
}
13+
if (is.character(measure) != TRUE) {
14+
stop("Error: 'measure' must be a string such as 'default' or 'ratio'")
15+
}
16+
17+
intrvls <- (1:10000) / 10000
18+
z <- qnorm(1 - intrvls / 2)
19+
20+
if (measure == "default") {
21+
se <- (UL / LL) / 3.92
22+
LL <- mclapply(z, FUN = function(i) point + (i * se))
23+
UL <- mclapply(z, FUN = function(i) point - (i * se))
24+
df <- data.frame(do.call(rbind, UL), do.call(rbind, LL))
25+
intrvl.limit <- c("lower.limit", "upper.limit")
26+
colnames(df) <- intrvl.limit
27+
}
28+
29+
else if (measure == "ratio") {
30+
se <- log(UL / LL) / 3.92
31+
logpoint <- log(point)
32+
logLL <- mclapply(z, FUN = function(i) logpoint + (i * se))
33+
logUL <- mclapply(z, FUN = function(i) logpoint - (i * se))
34+
df <- data.frame(do.call(rbind, logUL), do.call(rbind, logLL))
35+
intrvl.limit <- c("lower.limit", "upper.limit")
36+
colnames(df) <- intrvl.limit
37+
df$lower.limit <- exp(df$lower.limit)
38+
df$upper.limit <- exp(df$upper.limit)
39+
}
40+
41+
df$intrvl.level <- 1 - intrvls
42+
df$pvalue <- 1 - (1 - intrvls)
43+
df$svalue <- -log2(df$pvalue)
44+
df <- head(df, -1)
45+
return(df)
46+
}
47+
48+
# RMD Check
49+
utils::globalVariables(c("df", "lower.limit", "upper.limit", "intrvl.level", "pvalue", "svalue"))

0 commit comments

Comments
 (0)