Skip to content

Commit

Permalink
Merge pull request #3 from Zadchow/testing
Browse files Browse the repository at this point in the history
version 2.1.0, double y-axis plotting for ggconcurve( )
  • Loading branch information
zadrafi authored Sep 19, 2019
2 parents 8d3502a + da2935d commit 11fd615
Show file tree
Hide file tree
Showing 68 changed files with 821 additions and 502 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: concurve
Type: Package
Date: 2019-07-10
Date: 2019-09-18
Title: Computes and Plots Consonance (Confidence) Intervals, P-Values, and S-Values to Form Consonance and Surprisal Functions
Version: 2.0.1
Version: 2.1.0
Authors@R: c(
person("Zad R.", "Chow", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1545-8199")
Expand All @@ -12,7 +12,7 @@ Authors@R: c(
)
)
Maintainer: Zad R. Chow <[email protected]>
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>.
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>, Greenland S. (2019) <doi:10.1080/00031305.2018.1529625>, Chow ZR, Greenland S. (2019) <arXiv:1909.08579>, and Greenland S, Chow ZR. (2019) <arXiv:1909.08583>.
Imports: parallel,
ggplot2,
metafor,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# concurve 2.1.0

## Major changes
* `ggconcurve()` now plots both the P-values and CI level using both y-axes when the type = "consonance". Previously, this was only possible via `plot_concurve()` (which uses base R graphics) because `ggplot2` had a bug in its last few versions, which inhibited proper transformations in the y-axis.

# concurve 2.0.1

## Major changes
Expand Down
4 changes: 2 additions & 2 deletions R/curve_rev.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reverse Engineer Consonance Functions Using the Point Estimate and Confidence Limits

curve_rev <- function(point, LL, UL, measure = "default") {
curve_rev <- function(point, LL, UL, measure = "default", steps = 10000) {
if (is.numeric(point) != TRUE) {
stop("Error: 'x' must be a numeric vector")
}
Expand All @@ -14,7 +14,7 @@ curve_rev <- function(point, LL, UL, measure = "default") {
stop("Error: 'measure' must be a string such as 'default' or 'ratio'")
}

intrvls <- (1:10000) / 10000
intrvls <- (1:steps) / steps
z <- qnorm(1 - intrvls / 2)

if (measure == "default") {
Expand Down
61 changes: 30 additions & 31 deletions R/ggconcurve.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
ggconcurve <- function(type = "consonance", data, measure = "default", nullvalue = "absent", position = "pyramid",
title = "Consonance Function",
subtitle = "The function contains consonance intervals at every level.",
caption = "Produced with the concurve R package.",
xaxis = "Range of Values",
yaxis = "Consonance Level (%)",
yaxis = "P-value",
color = "#555555",
fill = "#239a98") {
if (type == "consonance") {
Expand All @@ -28,9 +27,6 @@ ggconcurve <- function(type = "consonance", data, measure = "default", nullvalue
if (is.character(subtitle) != TRUE) {
stop("Error: 'subtitle' must be a string.")
}
if (is.character(caption) != TRUE) {
stop("Error: 'caption' must be a string.")
}
if (is.character(xaxis) != TRUE) {
stop("Error: 'xaxis' must be a string.")
}
Expand All @@ -41,53 +37,61 @@ ggconcurve <- function(type = "consonance", data, measure = "default", nullvalue
stop("Error: 'fill' must be a string for the color.")
}
ggplot(data = data) +
geom_point(aes(x = lower.limit, y = intrvl.level * 100),
geom_point(aes(x = lower.limit, y = pvalue),
color = color, fill = fill, alpha = 0.5, shape = 20, size = 0.1
) +
geom_point(aes(x = upper.limit, y = intrvl.level * 100),
geom_point(aes(x = upper.limit, y = pvalue),
color = color, fill = fill, alpha = 0.5, shape = 20, size = 0.1
) +
geom_ribbon(aes(x = lower.limit, ymin = max(intrvl.level * 100), ymax = intrvl.level * 100),
geom_ribbon(aes(x = lower.limit, ymin = min(pvalue), ymax = pvalue),
fill = fill, alpha = 0.30
) +
geom_ribbon(aes(x = upper.limit, ymin = max(intrvl.level * 100), ymax = intrvl.level * 100),
geom_ribbon(aes(x = upper.limit, ymin = min(pvalue), ymax = pvalue),
fill = fill, alpha = 0.30
) +
labs(
title = title,
subtitle = subtitle,
caption = caption,
x = xaxis,
y = yaxis
) +
theme_light() +
theme(
axis.title.x = element_text(size = 13),
axis.title.y = element_text(size = 13)
axis.title.x = element_text(size = 12),
axis.title.y = element_text(size = 12)
) + {
if (measure == "default") scale_x_continuous(breaks = scales::pretty_breaks(n = 10))
} + {
if (measure == "ratio") scale_x_log10(breaks = scales::pretty_breaks(n = 10))
} + {
if (position == "inverted") scale_y_continuous(breaks = seq(0, 100, 5), expand = c(0, 0))
if (position == "inverted") {
scale_y_reverse(
breaks = seq(0, 1, .05),
sec.axis = sec_axis(~ (1 - .) * 100, name = "Levels for CI (%)", breaks = seq(0, 100, 5))
)
}
} + {
if (position == "pyramid") scale_y_continuous(trans = "reverse", breaks = seq(0, 100, 5), expand = c(0, 0))
if (position == "pyramid") {
scale_y_continuous(
breaks = seq(0, 1, .05),
sec.axis = sec_axis(~ (1 - .) * 100, name = "Levels for CI (%)", breaks = seq(0, 100, 5))
)
}
} +
theme(text = element_text(size = 15)) +
theme(text = element_text(size = 11)) +
theme(
plot.title = element_text(size = 16),
plot.subtitle = element_text(size = 12),
plot.caption = element_text(size = 8)
plot.title = element_text(size = 12),
plot.subtitle = element_text(size = 11)
) +
if (nullvalue == "present") {
if (measure == "default") {
annotate("segment",
x = 0, xend = 0, y = 0, yend = 100,
x = 0, xend = 0, y = 0, yend = 1,
color = "#990000", alpha = 0.3, size = .6
)
} else if (measure == "ratio") {
annotate("segment",
x = 1, xend = 1, y = 0, yend = 100,
x = 1, xend = 1, y = 0, yend = 1,
color = "#990000", alpha = 0.3, size = .6
)
}
Expand All @@ -110,9 +114,6 @@ ggconcurve <- function(type = "consonance", data, measure = "default", nullvalue
if (is.character(subtitle) != TRUE) {
stop("Error: 'subtitle' must be a string.")
}
if (is.character(caption) != TRUE) {
stop("Error: 'caption' must be a string.")
}
if (is.character(xaxis) != TRUE) {
stop("Error: 'xaxis' must be a string.")
}
Expand All @@ -136,27 +137,25 @@ ggconcurve <- function(type = "consonance", data, measure = "default", nullvalue
fill = fill, alpha = 0.30
) +
labs(
title = "Surprisal Function",
title = title,
subtitle = subtitle,
caption = caption,
x = xaxis,
y = "S-value (bits of information)"
) +
theme_light() +
theme(
axis.title.x = element_text(size = 13),
axis.title.y = element_text(size = 13)
axis.title.x = element_text(size = 12),
axis.title.y = element_text(size = 12)
) + {
if (measure == "default") scale_x_continuous(breaks = scales::pretty_breaks(n = 10))
} + {
if (measure == "ratio") scale_x_log10(breaks = scales::pretty_breaks(n = 10))
} +
scale_y_continuous(breaks = seq(0, 14, 0.5), expand = c(0, 0)) +
theme(text = element_text(size = 15)) +
theme(text = element_text(size = 11)) +
theme(
plot.title = element_text(size = 16),
plot.subtitle = element_text(size = 12),
plot.caption = element_text(size = 8)
plot.title = element_text(size = 12),
plot.subtitle = element_text(size = 11)
)
}
}
Expand Down
29 changes: 18 additions & 11 deletions R/plot_concurve.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
plot_concurve <- function(type = "consonance",
data,
measure = "default",
intervals = FALSE,
title = "Consonance Function",
xlab = "Theta",
ylab1 = "P-value",
ylab2 = "Confidence Level (%)",
fontsize = 12,
fill = "#239a9880") {

# Overall graph parameters
par(
ps = fontsize,
mar = c(4.5, 5, 3, 5),
font.main = 1,
cex.main = 1.3,
cex.lab = 1.15
cex.main = 1,
cex.lab = 1
)

# Consonance function
Expand Down Expand Up @@ -86,8 +89,11 @@ plot_concurve <- function(type = "consonance",
side = 4, at = c(seq(from = 0, to = 100, by = 10)),
tck = 1, lty = 2, col = "grey", las = 1
)
text(par("usr") + 0.95, 28,
srt = -90, adj = 0, labels = "Consonance Level (%)", cex = 1.05,

# 0.95, 28

text(par("usr") + 1, 15,
srt = -90, adj = 0, labels = ylab2, cex = 1,
xpd = TRUE
)
par(new = T)
Expand All @@ -97,7 +103,7 @@ plot_concurve <- function(type = "consonance",
)

# Labels for interval estimates and maximum likelihood

if (intervals == TRUE) {
text(
x = 1.27, y = 3,
paste(
Expand Down Expand Up @@ -142,6 +148,7 @@ plot_concurve <- function(type = "consonance",
),
cex = 0.93, col = "black"
)
}
}

# Surprisal function
Expand All @@ -154,9 +161,9 @@ plot_concurve <- function(type = "consonance",
xlim = c(min(lower.limit), max(upper.limit)),
panel.first = grid(),
type = "l",
xlab = "Theta",
ylab = "S-value",
main = "Surpisal Function",
xlab = xlab,
ylab = "S-value (bits of information)",
main = title,
yaxt = "n",
las = 1
)
Expand All @@ -166,9 +173,9 @@ plot_concurve <- function(type = "consonance",
xlim = c(min(lower.limit), max(upper.limit)),
panel.first = grid(),
type = "l",
xlab = "Theta",
ylab = "S-value",
main = "Surpisal Function",
xlab = xlab,
ylab = "S-value (bits of information)",
main = title,
yaxt = "n",
las = 1,
log = "x"
Expand Down
6 changes: 4 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ concurve | Graph Interval Functions <img src="man/figures/logo.svg" align="right
# Examples

<img src = "https://res.cloudinary.com/less-likely/image/upload/v1562705215/Site/Figure1.png" align="center" width ="400">
<img src = "https://res.cloudinary.com/less-likely/image/upload/v1562705215/Site/Figure2.png" align="center" width="400">
<img src = "https://res.cloudinary.com/less-likely/image/upload/v1568855498/Site/Figure1.png" align="center" width ="400">
<img src = "https://res.cloudinary.com/less-likely/image/upload/v1568855498/Site/Figure2.png" align="center" width="400">

* * *

Expand Down Expand Up @@ -96,3 +96,5 @@ install_github("zadchow/concurve")
7. Amrhein V, Trafimow D, Greenland S. Inferential Statistics as Descriptive Statistics: There is No Replication Crisis if We Don't Expect Replication. _Am Stat_. 2019
8. Greenland S. Valid P-values Behave Exactly As They Should. Some misleading criticisms of P-values and their resolution with S-values. _Am Stat_. 2019;18(136).
9. Fraser DAS. The p-value Function and Statistical Inference. _Am Stat_. 2019
10. Chow ZR, Greenland S. Semantic and Cognitive Tools to Aid Statistical Inference: Replace Confidence and Significance by Compatibility and Surprise. _arXiv:1909.08579 [stat.ME]_. 2019
11. Greenland S, Chow ZR. To Aid Statistical Inference, Emphasize Unconditional Descriptions of Statistics. _arXiv:1909.08583 [stat.ME]_. 2019
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ status](https://ci.appveyor.com/api/projects/status/v8sp9x96dap2om9s?svg=true)](
# Examples

<img src = "https://res.cloudinary.com/less-likely/image/upload/v1562705215/Site/Figure1.png" align="center" width ="400">
<img src = "https://res.cloudinary.com/less-likely/image/upload/v1562705215/Site/Figure2.png" align="center" width="400">
<img src = "https://res.cloudinary.com/less-likely/image/upload/v1568855498/Site/Figure1.png" align="center" width ="400">
<img src = "https://res.cloudinary.com/less-likely/image/upload/v1568855498/Site/Figure2.png" align="center" width="400">

-----

Expand Down Expand Up @@ -114,3 +114,9 @@ install_github("zadchow/concurve")
S-values. *Am Stat*. 2019;18(136).
9. Fraser DAS. The p-value Function and Statistical Inference. *Am
Stat*. 2019
10. Chow ZR, Greenland S. Semantic and Cognitive Tools to Aid
Statistical Inference: Replace Confidence and Significance by
Compatibility and Surprise. *arXiv:1909.08579 \[stat.ME\]*. 2019
11. Greenland S, Chow ZR. To Aid Statistical Inference, Emphasize
Unconditional Descriptions of Statistics. *arXiv:1909.08583
\[stat.ME\]*. 2019
4 changes: 3 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ navbar:
articles:
text: Articles
menu:
- text: Examples With Simulated Data
- text: Examples in R
href: articles/examples.html
- text: Using Stata
href: articles/stata.html
news:
text: News
href: news/index.html
Expand Down
6 changes: 3 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"@type": "SoftwareSourceCode",
"identifier": "concurve",
"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>.",
"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>, Greenland S. (2019) <doi:10.1080/00031305.2018.1529625>, Chow ZR, Greenland S. (2019) <arXiv:1909.08579>, and Greenland S, Chow ZR. (2019) <arXiv:1909.08583>.",
"name": "concurve: Computes and Plots Consonance (Confidence) Intervals, P-Values, and S-Values to Form Consonance and Surprisal Functions",
"date": "2019-05-10",
"codeRepository": "https://github.com/Zadchow/concurve",
Expand All @@ -16,7 +16,7 @@
],
"issueTracker": "https://github.com/Zadchow/concurve/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "2.0.1",
"version": "2.1.0",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -184,7 +184,7 @@
}
],
"keywords": ["confidence", "compatibility", "consonance", "surprisal", "interval", "function", "curve"],
"fileSize": "3936.013KB",
"fileSize": "3833.993KB",
"contIntegration": [
"https://travis-ci.org/Zadchow/concurve",
"https://ci.appveyor.com/project/Zadchow/concurve",
Expand Down
Loading

0 comments on commit 11fd615

Please sign in to comment.