Learn R Programming

tolerance (version 3.0.0)

DiffProp: Difference Between Two Proportions Distribution

Description

Density (mass), distribution function, quantile function, and random generation for the difference between two proportions. This is determined by taking the difference between two independent beta distributions.

Usage

ddiffprop(x, k1, k2, n1, n2, a1 = 0.5, a2 = 0.5,
          log = FALSE, ...)
pdiffprop(q, k1, k2, n1, n2, a1 = 0.5, a2 = 0.5,
          lower.tail = TRUE, log.p = FALSE, ...)
qdiffprop(p, k1, k2, n1, n2, a1 = 0.5, a2 = 0.5,
          lower.tail = TRUE, log.p = FALSE, ...)
rdiffprop(n, k1, k2, n1, n2, a1 = 0.5, a2 = 0.5)

Value

ddiffprop gives the density (mass), pdiffprop gives the distribution function, qdiffprop gives the quantile function, and rdiffprop generates random deviates.

Arguments

x, q

Vector of quantiles.

p

Vector of probabilities.

n

The number of observations. If length>1, then the length is taken to be the number required.

k1, k2

The number of successes drawn from groups 1 and 2, respectively.

n1, n2

The sample sizes for groups 1 and 2, respectively.

a1, a2

The shift parameters for the beta distributions. For the fiducial approach, we know that the lower and upper limits are set at a1 = a2 = 0 and a1 = a2 = 1, respectively, for the true p1 and p2. While computations can be performed on real values outside the unit interval, a warning message will be returned if such values are specified. For practical purposes, the default value of 0.5 should be used for each parameter.

log, log.p

Logical vectors. If TRUE, then the probabilities are given as log(p).

lower.tail

Logical vector. If TRUE, then probabilities are \(P[X\le x]\), else \(P[X>x]\).

...

Additional arguments passed to the Appell F1 function.

Details

The difference between two proportions distribution has a fairly complicated functional form. Please see the article by Chen and Luo (2011), who corrected a typo in the article by Nadarajah and Kotz (2007), for the functional form of this distribution.

References

Chen, Y. and Luo, S. (2011), A Few Remarks on 'Statistical Distribution of the Difference of Two Proportions', Statistics in Medicine, 30, 1913--1915.

Nadarajah, S. and Kotz, S. (2007), Statistical Distribution of the Difference of Two Proportions, Statistics in Medicine, 26, 3518--3523.

See Also

runif and .Random.seed about random number generation.

Examples

Run this code
## Randomly generated data from the difference between
## two proportions distribution.

set.seed(100)
x <- rdiffprop(n = 100, k1 = 2, k2 = 10, n1 = 17, n2 = 13)
hist(x, main = "Randomly Generated Data", prob = TRUE)

x.1 <- sort(x)
y <- ddiffprop(x = x.1, k1 = 2, k2 = 10, n1 = 17, n2 = 13)
lines(x.1, y, col = 2, lwd = 2)

plot(x.1, pdiffprop(q = x.1, k1 = 2, k2 = 10, n1 = 17, 
     n2 = 13), type = "l", xlab = "x", 
     ylab = "Cumulative Probabilities")

qdiffprop(p = 0.20, k1 = 2, k2 = 10, n1 = 17, n2 = 13, 
          lower.tail = FALSE)
qdiffprop(p = 0.80, k1 = 2, k2 = 10, n1 = 17, n2 = 13)

Run the code above in your browser using DataLab