Title: | Functions to Plot Confidence Interval |
---|---|
Description: | Plot confidence interval from the objects of statistical tests such as t.test(), var.test(), cor.test(), prop.test() and fisher.test() ('htest' class), Tukey test [TukeyHSD()], Dunnett test [glht() in 'multcomp' package], logistic regression [glm()], and Tukey or Games-Howell test [posthocTGH() in 'userfriendlyscience' package]. Users are able to set the styles of lines and points. This package contains the function to calculate odds ratios and their confidence intervals from the result of logistic regression. |
Authors: | Toshiaki Ara |
Maintainer: | Toshiaki Ara <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0 |
Built: | 2024-11-10 05:45:24 UTC |
Source: | https://github.com/toshi-ara/ciplot |
A function to plot confidential interval for
such as htest
, TukeyHSD
,
glht
(multcomp),
glm
(logistic regression only!)
and posthocTGH
(userfriendlyscience) objects.
CIplot(x, ...) ## Default S3 method: CIplot(x, xlog = FALSE, xlim = NULL, xlab = NULL, yname = TRUE, las = 0, pch = 21, pcol = 1, pcolbg = "white", pcex = 1, conf.level = 0.95, cilty = 1, cilwd = 1, cicol = 1, v, vlty = 2, vlwd = 1, vcol = 1, main = NULL, ...) ## S3 method for class 'htest' CIplot(x, xlog = FALSE, xlim = NULL, xlab = NULL, yname = FALSE, v = NULL, ...) ## S3 method for class 'TukeyHSD' CIplot(x, xlab = "Differences in mean", v = 0, ...) ## S3 method for class 'glht' CIplot(x, xlab = "Differences in mean", v = 0, ...) ## S3 method for class 'glm' CIplot(x, conf.level = 0.95, xlog = TRUE, xlab = "Odds Ratio", v = 1, ...) ## S3 method for class 'ORci' CIplot(x, xlog = TRUE, xlab = "Odds Ratio", v = 1, ...) ## S3 method for class 'posthocTGH' CIplot(x, xlab = "Differences in mean", v = 0, ...)
CIplot(x, ...) ## Default S3 method: CIplot(x, xlog = FALSE, xlim = NULL, xlab = NULL, yname = TRUE, las = 0, pch = 21, pcol = 1, pcolbg = "white", pcex = 1, conf.level = 0.95, cilty = 1, cilwd = 1, cicol = 1, v, vlty = 2, vlwd = 1, vcol = 1, main = NULL, ...) ## S3 method for class 'htest' CIplot(x, xlog = FALSE, xlim = NULL, xlab = NULL, yname = FALSE, v = NULL, ...) ## S3 method for class 'TukeyHSD' CIplot(x, xlab = "Differences in mean", v = 0, ...) ## S3 method for class 'glht' CIplot(x, xlab = "Differences in mean", v = 0, ...) ## S3 method for class 'glm' CIplot(x, conf.level = 0.95, xlog = TRUE, xlab = "Odds Ratio", v = 1, ...) ## S3 method for class 'ORci' CIplot(x, xlog = TRUE, xlab = "Odds Ratio", v = 1, ...) ## S3 method for class 'posthocTGH' CIplot(x, xlab = "Differences in mean", v = 0, ...)
x |
|
... |
other options for x-axis. |
xlog |
(logical) if |
xlim |
the x limits (x1, x2) of the plot. |
xlab |
a title for the plot. |
yname |
If |
las |
numeric in 0,1,2,3; the style of axis labels.
Default is 0. see also |
pch |
plotting 'character', i.e., symbol to use. |
pcol |
color code or name of the points. |
pcolbg |
background (fill) color for the open plot symbols given by 'pch = 21:25'. |
pcex |
character (or symbol) expansion of points. |
conf.level |
|
cilty |
line types of conficence intervals. |
cilwd |
line width of conficence intervals. |
cicol |
color code or name of conficence intervals. |
v |
the x-value(s) for vertical line. |
vlty |
line types of vertical line. |
vlwd |
line width of vertical line. |
vcol |
color code or name of vertical line. |
main |
a main title for the plot. |
CIplot
was made based on plot.TukeyHSD
.
# File src/library/stats/R/TukeyHSD.R # Part of the R package, https://www.R-project.org # # Copyright (C) 2000-2001 Douglas M. Bates # Copyright (C) 2002-2015 The R Core Team
plot
, axis
, points
, par
.
##### default (matrix or data.frame) require(graphics) x <- matrix(c(3, 1, 5, 4, 2, 6), 2, 3, byrow = TRUE) colnames(x) <- c("esti", "lwr", "upr") rownames(x) <- c("A", "B") CIplot(x, xlab = "difference", v = 2, las = 1) ##### 'htest' objects require(graphics) ## t test set.seed(1234) a <- rnorm(10, 10, 2); b <- rnorm(10, 8, 2) x <- t.test(a, b) CIplot(x) ## binomial test x <- binom.test(5, 20) CIplot(x, xlim = c(0, 1)) ## Fisher's exact test x <- matrix(c(10, 7, 8, 9), 2, 2, byrow = TRUE) res <- fisher.test(x) CIplot(res, xlog = TRUE) ##### 'TukeyHSD' objects require(graphics) ## Tukey test aov1 <- aov(breaks ~ tension + wool, data = warpbreaks) x <- TukeyHSD(aov1) oldpar <- par(no.readonly = TRUE) par(mfrow = c(1, 2)) CIplot(x, las = 1) par(oldpar) ## example of line type and color aov1 <- aov(breaks ~ tension, data = warpbreaks) x <- TukeyHSD(aov1) CIplot(x, las = 1, pcol = 2:4, pcolbg = 2:4, cicol = 2:4, vlty = 1, vcol = "gray") ##### 'glht' objects require(graphics) ## Tukey test require(multcomp) aov1 <- aov(breaks ~ tension, data = warpbreaks) x <- glht(aov1, linfct = mcp(tension = "Tukey")) CIplot(x, las = 1) ## Dunnett test x <- glht(aov1, linfct = mcp(tension = "Dunnett")) CIplot(x, las = 1) ##### 'glm' object: logistic regression only! ## odds ratio require(graphics) require(MASS) data(birthwt) x <- glm(low ~ age + lwt + smoke + ptl + ht + ui, data = birthwt, family = binomial) CIplot(x, las = 1) ##### 'posthocTGH' object ## Tukey or Games-Howell methos require(graphics) if (require(userfriendlyscience)) { x <- posthocTGH(warpbreaks$breaks, warpbreaks$tension) CIplot(x, las = 1) }
##### default (matrix or data.frame) require(graphics) x <- matrix(c(3, 1, 5, 4, 2, 6), 2, 3, byrow = TRUE) colnames(x) <- c("esti", "lwr", "upr") rownames(x) <- c("A", "B") CIplot(x, xlab = "difference", v = 2, las = 1) ##### 'htest' objects require(graphics) ## t test set.seed(1234) a <- rnorm(10, 10, 2); b <- rnorm(10, 8, 2) x <- t.test(a, b) CIplot(x) ## binomial test x <- binom.test(5, 20) CIplot(x, xlim = c(0, 1)) ## Fisher's exact test x <- matrix(c(10, 7, 8, 9), 2, 2, byrow = TRUE) res <- fisher.test(x) CIplot(res, xlog = TRUE) ##### 'TukeyHSD' objects require(graphics) ## Tukey test aov1 <- aov(breaks ~ tension + wool, data = warpbreaks) x <- TukeyHSD(aov1) oldpar <- par(no.readonly = TRUE) par(mfrow = c(1, 2)) CIplot(x, las = 1) par(oldpar) ## example of line type and color aov1 <- aov(breaks ~ tension, data = warpbreaks) x <- TukeyHSD(aov1) CIplot(x, las = 1, pcol = 2:4, pcolbg = 2:4, cicol = 2:4, vlty = 1, vcol = "gray") ##### 'glht' objects require(graphics) ## Tukey test require(multcomp) aov1 <- aov(breaks ~ tension, data = warpbreaks) x <- glht(aov1, linfct = mcp(tension = "Tukey")) CIplot(x, las = 1) ## Dunnett test x <- glht(aov1, linfct = mcp(tension = "Dunnett")) CIplot(x, las = 1) ##### 'glm' object: logistic regression only! ## odds ratio require(graphics) require(MASS) data(birthwt) x <- glm(low ~ age + lwt + smoke + ptl + ht + ui, data = birthwt, family = binomial) CIplot(x, las = 1) ##### 'posthocTGH' object ## Tukey or Games-Howell methos require(graphics) if (require(userfriendlyscience)) { x <- posthocTGH(warpbreaks$breaks, warpbreaks$tension) CIplot(x, las = 1) }
glm
objectCalculate odds ratios and their confidence intervals
from glm
object
ORci(x, conf.level = 0.95)
ORci(x, conf.level = 0.95)
x |
|
conf.level |
the confidence interval. Default is 0.95. |
an object ORci
and matirix
classes with four columns.
odds ratio
lower conficence intarval
upper conficence intarval
P value by logistic regression
require(graphics) require(MASS) data(birthwt) x <- glm(low ~ age + lwt + smoke + ptl + ht + ui, data = birthwt, family = binomial) OR1 <- ORci(x) CIplot(OR1, las = 1)
require(graphics) require(MASS) data(birthwt) x <- glm(low ~ age + lwt + smoke + ptl + ht + ui, data = birthwt, family = binomial) OR1 <- ORci(x) CIplot(OR1, las = 1)
ORci
objectPrint odds ratios and their confidence intervals of ORci
object.
## S3 method for class 'ORci' print(x, ...)
## S3 method for class 'ORci' print(x, ...)
x |
|
... |
other options for print such as |
glm
, ORci
.
require(MASS) data(birthwt) x <- glm(low ~ age + lwt + smoke + ptl + ht + ui, data = birthwt, family = binomial) OR1 <- ORci(x) print(OR1, digits = 3)
require(MASS) data(birthwt) x <- glm(low ~ age + lwt + smoke + ptl + ht + ui, data = birthwt, family = binomial) OR1 <- ORci(x) print(OR1, digits = 3)