Pair-up and Compute Differences

```
pairUpDiff(
x,
major = NULL,
minor = NULL,
group,
refgroup,
lower = NULL,
upper = NULL,
minkeep = NULL,
sortdiff = TRUE,
conf.int = 0.95
)
```

a list of two objects both sorted by descending values of differences in `x`

. The `X`

object is a data frame that contains the original variables sorted by descending differences across `group`

and in addition a variable `subscripts`

denoting the subscripts of original observations with possible re-sorting and dropping depending on `sortdiff`

and `minkeep`

. The `D`

data frame contains sorted differences (`diff`

), `major`

, `minor`

, `sd`

of difference, `lower`

and `upper`

confidence limits for the difference, `mid`

, the midpoint of the two `x`

values involved in the difference, `lowermid`

, the midpoint minus 1/2 the width of the confidence interval, and `uppermid`

, the midpoint plus 1/2 the width of the confidence interval. Another element returned is `dropped`

which is a vector of `major`

/ `minor`

combinations dropped due to `minkeep`

.

- x
a numeric vector

- major
an optional factor or character vector

- minor
an optional factor or character vector

- group
a required factor or character vector with two levels

- refgroup
a character string specifying which level of

`group`

is to be subtracted- lower
an optional numeric vector giving the lower

`conf.int`

confidence limit for`x`

- upper
similar to

`lower`

but for the upper limit- minkeep
the minimum value of

`x`

required to keep the observation. An observation is kept if either`group`

has`x`

exceeding or equalling`minkeep`

. Default is to keep all observations.- sortdiff
set to

`FALSE`

to avoid sorting observations by descending between-`group`

differences- conf.int
confidence level; must have been the value used to compute

`lower`

and`upper`

if they are provided

Frank Harrell

This function sets up for plotting half-width confidence intervals for differences, sorting by descending order of differences within major categories, especially for dot charts as produced by `dotchartpl()`

. Given a numeric vector `x`

and a grouping (superpositioning) vector `group`

with exactly two levels, computes differences in possibly transformed `x`

between levels of `group`

for the two observations that are equal on `major`

and `minor`

. If `lower`

and `upper`

are specified, using `conf.int`

and approximate normality on the transformed scale to backsolve for the standard errors of estimates, and uses approximate normality to get confidence intervals on differences by taking the square root of the sum of squares of the two standard errors. Coordinates for plotting half-width confidence intervals are also computed. These intervals may be plotted on the same scale as `x`

, having the property that they overlap the two `x`

values if and only if there is no "significant" difference at the `conf.int`

level.

```
x <- c(1, 4, 7, 2, 5, 3, 6)
pairUpDiff(x, c(rep('A', 4), rep('B', 3)),
c('u','u','v','v','z','z','q'),
c('a','b','a','b','a','b','a'), 'a', x-.1, x+.1)
```

Run the code above in your browser using DataLab