------------------------------------------------------------------------------- help forbpmedianandbpdifmed(Roger Newson) -------------------------------------------------------------------------------

Bonett-Price confidence intervals for medians and their contrasts

bpmedianvarname[if] [in] [ ,level(#)eformfast]

bpdifmedvarname[if] [in] ,by(groupvarname)[level(#)eformfast]where

groupvarnameis the name of a grouping variable, which should only have two non-missing values.

byis allowed; see[R] by.

Description

bpmediancalculates a Bonett-Price confidence interval for a median, using the Bonett-Price standard error, and saves the results as estimation results. These can then be saved in an output dataset (or resultsset), using theparmestpackage (downloadable from SSC), and then input to themetaparmmodule of theparmestpackage to calculate Bonett-Price confidence intervals for a linear contrast between medians of independent groups.bpdifmedcalculates Bonett-Price confidence intervals for the medians of two groups, defined by a grouping variable, and also for their difference or ratio.

Options forbpmedianandbpdifmed

levelspecifies the confidence level to be used for calculating the confidence intervals.

eformspecifies that confidence intervals will be calculated for the exponentiated median(s), and also, in the case ofbpdifmed, for the ratio between the first exponentiated median and the second exponentiated median. Theeformoption is useful if the inputvarnamecontains the logarithms of a primary variable, because, for a continuous positive random variable, the ratio between two exponentiated subpopulation medians of the logged variable is then the ratio between the two corresponding unexponentiated subpopulation medians of the unlogged variable. Ifeformis not specified, then confidence intervals are calculated for the unexponentiated median(s), and also, in the case ofbpdifmed, for the difference between the first median and the second median. Note that, for a real-life variable (which is never perfectly continuous in a finite sample), the median estimate produced when using the logged variable and specifyingeformmay be different from the median estimate produced when using the unlogged variable and not specifyingeform. This is because the unlogged variable may have two mid-range values. In this case, the median estimate produced using the unlogged variable withouteformis the arithmetic mean of the two mid-range values, and the median estimate produced using the logged variable witheformis the geometric mean of the two mid-range values, and is lower than their arithmetic mean.

fastis an option for programmers. It specifies thatbpmedianandbpdifmedwill take no action to restore the original data if the program fails, or if the user presses Break.

Options forbpdifmedonly

by(groupvarname)specifies a grouping variable, which must have exactly 2 non-missing values.bpdifmedwill estimate the difference between the medians, or the ratio between the exponentiated medians, for the dependent variable specified by thevarnamein the two groups.

Use ofpredictafterbpmedianIf

predictis used afterbpmedian, then the predicted values calculated (usingpredictwith no options or with thexboption) will be equal to the estimated median, and the standard errors calculated (usingpredictwith thestdpoption) will be equal to the standard error of the estimated median. Thescoreoption ofpredictis not allowed afterbpmedian.

RemarksThe Bonett-Price variance estimator fot the sample median is introduced in Price and Bonett (2001). The theory behind Bonett-Price confidence intervals for general contrasts of independent sample medians is introduced in Bonett and Price (2002). The special case of confidence intervals for the difference or ratio between the medians of two independent groups is discussed in Price and Bonett (2002). The formulas for these confidence intervals are related to the confidence interval formulas used by

centile,meanandttest, but are not the same formulas as used by either of those commands.Note that the difference (or ratio) between medians is not the same parameter as the Hodges-Lehmann median pairwise difference (or ratio) between values of a variable in two groups, which is estimated by the

cendifmodule of thesomersdpackage, downloadable from SSC. The two population parameters are the same if either the two subpopulation distributions are symmetrical or the two subpopulation distributions differ only in location. The methods ofbpmeddifandcendifstill produce consistent estimates if neither of these assumptions is true. However, under those circumstances, the two methods are estimating different parameters, and are not alternative methods for estimating the same parameter.

Examples

.sysuse auto, clear.bpmedian weight.bpdifmed weight, by(foreign)

.sysuse auto, clear.gene logweight=log(weight).bpmedian logweight, eform.bpdifmed logweight, eform by(foreign)The following example demonstrates the use of

bpmedianwith theparmbyandmetaparmmodules of theparmestpackage, downloadable from SSC. We first estimate medians for length (in inches) in even-numbered US cars, odd-numbered US cars, even-numbered non-US cars, and odd-numbered non-US cars. These medians, with their confidence limits andP-values, are stored in an output dataset (or resultsset), with one observation per car group, which is stored in the memory, overwriting the original input dataset. The new dataset is listed. We then usemetaparmto estimate the difference between differences between non-US cars and US cars with odd and even sequence numbers. This difference between differences (or interaction) is listed, and not saved.

.sysuse auto, clear.gene byte odd=mod(_n,2).parmby "bpmedian length", by(foreign odd) norestore.list.metaparm [iweight=((odd==1)-(odd==0))*((foreign==1)-(foreign==0))],list(,)

Saved results

bpmediansaves the following ine():Scalars

e(N)number of observationse(c)rank of original upper confidence limitMacros

e(cmd)bpmediane(cmdline)command as typede(depvar)name of dependent variablee(properties)b VMatrices

e(b)coefficient vectore(V)variance-covariance matrix of the estimatorsFunctions

e(sample)marks estimation sampleThe scalar

e(c)contains the rank, in the outcome-sorted sample, of the original upper confidence limit, denoted ascin the equations of Price and Bonett (2001). The Bonett-Price standard error is an example of a standard error calculated by the inverse confidence interval method, using an original confidence interval, defined without using a standard error, and extending from theN-c+1th order statistic to thecth order statistic. Theinvcisepackage, downloadable from SSC, is also used to compute standard errors for sample statistics, using the inverse confidence interval method.

bpdifmedsaves the following inr():Scalars

r(N)number of observationsr(N_1)first sample sizer(N_2)second sample sizer(level)confidence levelMacros

r(depvar)name of dependent variabler(by)name ofby()variable defining groups)r(eform)eformif specifiedMatrices

r(cimat)matrix of sample numbers, confidence intervals andP-valuesThe matrix

r(cimat)is displayed as output bybpdifmed. It has 5 columns, containing sample numbers, estimates, lower and upper confidence limits, andP-values, respectively. It has 3 rows, containing this information on the first sample median, the second sample median, and the difference (or ratio) between medians, respectively.

AuthorRoger Newson, National Heart and Lung Institute, Imperial College London, UK. Email: r.newson@imperial.ac.uk

ReferencesBonett, D. G. and Price, R. M. 2002. Statistical inference for a linear function of medians: Confidence intervals, hypothesis testing, and sample size requirements.

Psychological Methods7(3): 370-383.Price, R. M. and Bonett, D. G. 2002. Distribution-free confidence intervals for difference and ratio of medians.

Journal ofStatistical Computation and Simulation72(2): 119-124.Price, R. M. and Bonett, D. G. 2001. Estimating the variance of the sample median.

Journal of Statistical Computation and Simulation68(3): 295-305.

Also seeManual:

[R] centile,[R] mean,[R] ttest,[R] predictOn-line: help forcentile,mean,ttest,predicthelp forparmest,parmby,parmcip,metaparm,somersd,cendif,censlope,invciseif installed