meldCD: Meld Two Confidence Distributions

View source: R/meldCD.R

meldCDR Documentation

Meld Two Confidence Distributions

Description

Melding is a very general way of combining two independent confidence interval proceedures to create a confidence interval on a function of the two associated parameters (e.g., difference or ratio).

Usage

meldCD(H1, H2, nullparm = NULL, parmtype = c("difference", "ratio", "oddsratio"), 
    conf.level = 0.95, alternative = c("two.sided", "less", "greater"), 
    estimate = c("median", "mean"), lim = c(-Inf, Inf), parmGrid = NULL,
    nmc = 1e5, ngrid = 1e4, calcmethod = "int", epsilon=1e-8, utol=1e-8)

Arguments

H1

a function representing the confidence distribution for parameter 1 (see details)

H2

a function representing the confidence distribution for parameter 2

nullparm

null parameter value for the parameter defined by parmtype

parmtype

parameter type, 'difference' gives parm2-parm1, 'ratio' gives parm2/parm1 (for 'oddsratio' see details).

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.

conf.level

confidence level of the interval.

estimate

type of estimate derived from each confidence distribution, either 'median' or 'mean'

lim

a vector with limits on the parameters (both parameters should have the same limits)

parmGrid

a vector of a grid of possible values of the parameter, if NULL one is produced based on the lim argument

nmc

number of Monte Carlo replications, used if calcmethod='mc'

ngrid

minimum number of elements in the parameter grid, used if parmGrid=NULL

calcmethod

calculation method, either 'int' (numeric integration) or 'mc' (Monte Carlo)

epsilon

small value for warning check, we want the minimum of the CD over the parameter grid to be greater than epsilon, and the maximum to be less than 1-epsilon

utol

small value for passing to tol option in uniroot for confidence interval calculations

Details

For continuous responses, a confidence distribution (CD) is like a frequentist posterior distribution. We represent the CDs as cumulative distribution functions in the parameter space. The CD gets its name because it is created from the confidence interval process. If (L,U) is the 1-alpha confidence interval for group 1, then H1(L) = alpha/2 and H1(U)=1-alpha/2. Typically, the the CDs can be formulated as one-sided (alternative='greater') p-value functions, or 1-p for alternative='less', where the main function argument is the boundary value on the parameter space between the null and alternative. See binomial example below.

The median of the CD can be used as an estimate of the parameter.

We want inferences on a function of the parameters, say g(parm1, parm2), where when

  • parmtype="difference" then g(parm1,parm2)=parm2-parm1

  • parmtype="ratio" then g(parm1,parm2)=parm2/parm1

  • parmtype="oddsratio" then g(parm1,parm2)=(parm2*(1-parm1))/(parm1*(1-parm2)).

The function g(parm1, parm2) must be increasing in parm2 and decreasing in parm1, so for example normal CDs (or any with a range -Inf to Inf) are not allowed for parmtype='ratio'. The lim argument checks to see if the parmtype is allowed.

Let T1 and T2 be simulated independent random variables associated with the CDs H1 and H2. Then to get a two-sided 1-alpha confidence interval on g(parm1,parm2) we can use quantile(g(T1,T2),probs=c(alpha/2,1-alpha/2)). This is basically how it works when calcmethod='mc'. When calcmethod='int' then numeric integration is used.

For discrete responses, to ensure validity of the resulting confidence intervals, each group uses either a lower or upper CD, depending on the one-sided alternative. Thus, confidence intervals for two-sided alternatives cannot be calculated in one call to the meldCD for discrete data. See Fay, Proschan, and Brittain (2015) and the example.

Value

A list with class "htest" containing the following components:

p.value

the p-value for the test.

conf.int

a confidence interval for the mean appropriate to the specified alternative hypothesis.

estimate

vector of parameter estimates for each group and using the parmtype, uses the median of the CDs for estimates

null.value

the specified hypothesized value of the difference in parameters

alternative

a character string describing the alternative hypothesis.

method

a character string describing the test.

data.name

a character string giving the name(s) of the data.

Warning

The function has not been tested for discrete confidence distributions. Note most confidence distributions for discrete data are not discrete CDs because the parameters are continuous.

Author(s)

Michael P. Fay

References

Fay, MP, Proschan, MA, Brittain, E (2015). Combining One-sample confidence procedures for inference in the two-sample case. Biometrics. 71: 146-156.

See Also

meldtTest and binomMeld.test for special cases.

Examples

x1<-4
n1<-11
x2<- 13
n2<-24


#  we use the upper and lower CDs
# this is needed for discrete data to ensure valid intervals
H1L<-function(theta){ pbeta(theta,x1,n1-x1+1)}
# Note, this is just a p-value function that inputs the null boundary value: 
binom.test(x1,n1,p=.4,alternative="greater")$p.value
H1L(.4)
H1U<-function(theta){ pbeta(theta,x1+1,n1-x1)}
# Note, but this is just a function for 1-p that inputs the null boundary value: 
1-binom.test(x1,n1,p=.4,alternative="less")$p.value
H1U(.4)
H2L<-function(theta){ pbeta(theta,x2,n2-x2+1)}
H2U<-function(theta){ pbeta(theta,x2+1,n2-x2)}

meldCD(H1U,H2L, lim=c(0,1),conf.level=0.975,alternative="greater")
meldCD(H1L,H2U, lim=c(0,1),conf.level=0.975,alternative="less")
# notice that the estimates are different than the usual 
# difference in sample proportions
require(exact2x2)
binomMeld.test(x1,n1,x2,n2, conf.level=0.975, alternative="greater")
# compare to two-.sided from 
binomMeld.test(x1,n1,x2,n2, conf.level=0.95, alternative="two.sided")


asht documentation built on Aug. 24, 2023, 5:08 p.m.