Skip to content

Instantly share code, notes, and snippets.

@kylebgorman
Created September 28, 2013 00:56
Show Gist options
  • Save kylebgorman/6737200 to your computer and use it in GitHub Desktop.
Save kylebgorman/6737200 to your computer and use it in GitHub Desktop.
Define the search space for the matching procedure
# compute means
mu <- mean(covariate)
mu.group <- tapply(covariate, condition, mean)
# locate observations driving the correlation
correlate <- ((covariate < mu.group) == (mu.group < mu))
# compute order, filtering out non-correlates
ord <- order(covariate)
ord <- ord[correlate[ord]]
# split on condition and reverse for those above
search.space <- split(ord, condition[ord])
for (name in names(search.space)) {
if (covariate[search.space[[name]][1]] > mu)
search.space[[name]] <- rev(search.space[[name]])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment