pairUpDiff
pairUpDiff.RdPair-up and Compute Differences
Usage
pairUpDiff(
x,
major = NULL,
minor = NULL,
group,
refgroup,
lower = NULL,
upper = NULL,
minkeep = NULL,
sortdiff = TRUE,
conf.int = 0.95
)Arguments
- 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
groupis to be subtracted- lower
an optional numeric vector giving the lower
conf.intconfidence limit forx- upper
similar to
lowerbut for the upper limit- minkeep
the minimum value of
xrequired to keep the observation. An observation is kept if eithergrouphasxexceeding or equallingminkeep. Default is to keep all observations.- sortdiff
set to
FALSEto avoid sorting observations by descending between-groupdifferences- conf.int
confidence level; must have been the value used to compute
lowerandupperif they are provided
Value
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.
Details
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.
Examples
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)
#> $X
#> x major minor group lower upper subscripts
#> 1 1 A u a 0.9 1.1 1
#> 2 4 A u b 3.9 4.1 2
#> 3 7 A v a 6.9 7.1 3
#> 4 2 A v b 1.9 2.1 4
#> 7 6 B q a 5.9 6.1 7
#> 5 5 B z a 4.9 5.1 5
#> 6 3 B z b 2.9 3.1 6
#>
#> $D
#> diff major minor sd lower upper mid lowermid uppermid
#> A:u 3 A u 0.0722 2.86 3.14 2.5 2.43 2.57
#> A:v -5 A v 0.0722 -5.14 -4.86 4.5 4.43 4.57
#> B:q NA B q NA NA NA NA NA NA
#> B:z -2 B z 0.0722 -2.14 -1.86 4.0 3.93 4.07
#>
#> $dropped
#> NULL
#>