Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify match_on.function()'s expectations of its 1st argument #205

Open
benthestatistician opened this issue May 19, 2021 · 3 comments
Open

Comments

@benthestatistician
Copy link
Collaborator

match_on.function() expects its first argument to be a function with 3 arguments, index, data and z. But in many cases, including each of my uses of it as well as the example discussed inline in the documentation, only the first two are used. This adds a disorienting element to our explanation:

...This may sound complicated, but is simple to use. For example, a function that returned the absolute difference between two units using a vector of data would be f <- function(index, data, z) { abs(data[index[,1]] - data[index[,2]]) }.

  1. I suspect that we could simply do without the z= argument.
  2. Alternatively, I'd think we could accommodate functions passed to match_on() that either do or do not take a z= argument, provided that we insist they take index and data arguments. In particular, before this point in makedist.R
dists <- distancefn(cbind(treatmentids, controlids), data, z)

we check whether any(names(formals(distancefn))=="z") and if not then instead do

dists <- distancefn(cbind(treatmentids, controlids), data)

Either way this is an API change appropriate to a major version bump (#134) .

@benthestatistician
Copy link
Collaborator Author

Would you see any reason to hesitate with either of the options proposed in this issue, (1) or (2), if they didn't break the current tests? @markmfredrickson @josherrickson

@benthestatistician benthestatistician changed the title simplify match_on.function()'s expectations of it 1st argument simplify match_on.function()'s expectations of its 1st argument May 19, 2021
@josherrickson
Copy link
Collaborator

Anything that simplifies match_on.function gets my support. What about also supporting a version that just takes in a pair of points and returns a distance between them; handling the index internally? I feel like that would live up to the promise of "just define any distance metric" better than having users worry about vectorization of functions.

@markmfredrickson
Copy link
Owner

No argument about removing z. I'm sure I had a reason for that at some point, but looking at the test file doesn't include any examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants