GetPairs: GetPairs

Description Usage Arguments Details Value Examples

Description

Form all pairs of rows in X and compute Mahalanobis distances based on v.

Usage

1
2
GetPairs(X, u, v, numForTransitionStart = NULL, numForTransitionEnd = NULL,
  onlyIncludeNearestN = NULL, mahalanobisConstantTerm = 1)

Arguments

X

data frame

u

input of interest

v

other inputs

mahalanobisConstantTerm

Weights are (1 / (mahalanobisConstantTerm + Mahalanobis distance))

numForTransitionStart

number of rows to use as the start points of transitions (defaulting to 'NULL', we use all rows)

numForTransitionEnd

number of rows to use as potential end points of transitions (defaulting to 'NULL', we use all rows)

onlyIncludeNearestN

for each transition start, we only include as transition end points the nearest 'onlyIncludeNearestN' rows (defaulting to 'NULL', we use all rows)

Details

To help with computational constraints, you have the option to not form pairs between all rows of X but instead of specify a certain number (numForTransitionStart) to randomly be selected as rows from which transitions start, and another number (numForTransitionEnd) to be randomly selected as where transitions end. We then form all pairs between transition-start rows and transition-end rows.

In order to get a smaller data frame for later manipulations (and maybe just because it's a good idea), you can also specify onlyIncludeNearestN, in which case we return only the nearest onlyIncludeNearestN transition ends for each transition start (instead of all pairs).

Value

a data frame with the inputs v from the first of each pair, u from each half (with ".B" appended to the second), and the Mahalanobis distances between the pairs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
v <- rnorm(100)
u <- v + 0.3*rnorm(100)
qplot(v,u)
X = data.frame(v=v,u=u)
pairsDF <- GetPairs(X, "v", "u")
pairsDFRow1 <- subset(pairsDF, OriginalRowNumber==1)
# When we subset to one "original row number", all of the v's are the same:
print(pairsDFRow1$v)
# ... and u's corresponding to closer v.B (the v in the second element of the pair) have higher weight:
qplot(u.B, Weight, data=pairsDFRow1)

dchudz/predcomps documentation built on May 15, 2019, 1:48 a.m.