Distance term for ergm (Minkowski and spherical distances) - #660
Distance term for ergm (Minkowski and spherical distances)#660CarterButts wants to merge 5 commits into
Conversation
|
Thanks, Carter! Definitely worth including. My thoughts so far:
|
|
Hi, Pavel. To your points:
|
|
I can only answer briefly at the moment: The There might be a simpler way to do it, but If you really want to access the network attribute via a nodal attribute API, you can: for example, |
|
OK, making those changes (and adding a few more features). Will update.... |
|
@krivit OK, I have made the suggested changes, and added some new functionality. Among other things, I switched from |
…ing a matrix (if accepted). references #660
|
@CarterButts This is superb, thank you! So much good functionality, plus the base case that is most useful for our students ( Forgive me if you already mentioned this. Clearly log distance is commonly used in practice given its superior properties over distance in many practical applications. And I see that you have a scale factor feature in there also. Do folks ever do other transformations in practice, particularly powers? E.g. taking the sqrt of distance? (I realize 2D Euclidean distance already involves taking a sqrt, but that doesn't preclude one from doing it again). If so, is this functionality in there in a way I'm not seeing? Or is it just not done in practice? Thanks! |
|
I should add that I pulled your branch and played with it a bit, including trying out some made-up examples just to ensure I understood the syntax fully. Not a deep set of tests, but at least one more pair of eyes saying the basic parts work as expected. |
|
@sgoodreau Glad that this can be useful! To your question, we have usually (so far) seen spatial interaction functions (i.e., marginal tie probabilities, as a function of distance) with forms like so the conditional log odds of the i,j edge are approximately linear in the log of the rescaled distance added to the offset. Now, consider an ERGM with an edge term and an edgecov of the form We can immediately recognize this as equivalent to the above expression. So what this tells is is that adding a term for the log of the scaled base distance plus an offset yields a power law distance dependence, with the ERGM coefficient (Note that this is approximating what we have called an "attenuated power law" in our work. It has power law tails, but is locally concave down near the origin. The other obvious family, BTW, we can contrast this with what happens when we have a term like and since, in the sparse regime, the log odds is approximately the log probability, Very different: if On reflection, though, for this exponential model, I was more concerned in the code with changing the metric (the power that goes into how we define the distance), and not the |
|
@sgoodreau OK, added the |
|
@CarterButts, thank you much. That is all the functionality I was thinking of (and more), so we're good to go on my end. @martinamorris or @smjenness did you have anything else you were thinking of? |
… check, the term passes its checks, and the examples run correctly. A NEWS item has been added, and the term is also documented (and a test has been added).
functionality (including vertex based attributes, scaling, and the ability to combine spherical and Minkowski metrics), updated docs and tests, and tested everything. Seems to be working fine.
… test, as well. Seems to work fine, and passes tests.
|
Thanks, everyone, but particularly @CarterButts! I've rebased this over some changes to I am going to make a few more changes, including putting it into the template that makes it work for valued ERGMs as well. For future reference, when proposing pull requests, please do not make changes to the master branch of your fork, but rather create a unique branch name, since it's confusing and potentially dangerous to have multiple A few more items for discussion in the meantime,
|
|
Hi, Pavel -
No; they overlap in one special case, but are not in general redundant.
It seems to me more natural to just have a single term, for several reasons. (1) in geospatial work it is not uncommon for users to switch between lat/lon and projected geometries in different settings, and having a single term makes it clear where one should go for the functionality in either case. (2) a lot of the basic functionality involved in getting the attributes and processing the distances is shared, so this minimizes code replication. And perhaps more importantly, (3) you may in some cases want to merge spherical and non-spherical distance elements (as in the case of elevation, but perhaps also Blau spaces), and the current Relatedly, it's hard to suggest an alias, because I'm not sure what the motivating use case is. I have no particular objection if it serves a purpose (other than not multiplying terms beyond necessity, and potentially setting up name conflicts).
The
Not currently, though they could be added. I can indeed see these being useful for non-physical spaces.... |
|
I am in the process of converting the code to work for both binary and valued ERGMs. Please don't make any further edits until I push. In the meantime, more discussion items: 5. 6. Usually, vertex attribute specifiers that implement the API are named |
BTW, can you clarify? |
I don't understand what this means, sorry. Let me clarify my perspective of EpiModel's user base's needs. Typical use case woud be to have two nodal attributes representing coordinates in 2D space. Their names are arbitrary, but let's call them Is what you are saying here consistent with that? |
|
@sgoodreau indeed, this is what the current term does. Actually, the current term lets you do any of the following:
So the user can employ whichever is most convenient. (I usually want to work with coordinate matrices, for instance, but you've said that your folks would rather do it via vertex attributes. Everyone wins!) That's why I'm a bit confused.... |
|
Overlooked this before, but:
Please don't do that, because |
The most idiomatic way to pass each vertex's coordinates to is via vertex attributes. There are two ways I could have integrated this change into this branch, merging or rebasing. Since it's a development branch, I have done the latter to keep the log a bit cleaner. |
|
1. and 2.: I am not necessarily against these explanations, but I want to explore possibilities before we finalise this, particularly since this term will hopefully be used outside of the geospatial context. Do we want to assume a nontrivial value for radius? For example, what if someone is using miles. What if we instead allowed a number or a character placeholder, e.g., "earth.km", "earth.mi", "unit", etc.? 3. Unless I am misreading the current implementation, 4. This would also help address some of #481 as well. Now that I think about it, do we want to have a user interface more like R's 5. and 6. To recap (and this is also for @sgoodreau), nodal attributes UI (i.e., how the end-user can use it) lets you: |
This update adds a term called
distancethat can be used for binary ERGMs (directed or undirected). The term includes support forThis functionality was previously in an ergm userterms package, but given recent demand from Steve, Sam, and Martina, I dusted the package off, upgraded it, and then integrated the functionality into the
ergmpackage.The function is fully documented (with examples), and includes some basic tests. I have confirmed that the package w/the term passes
R CMD check, the tests pass, and the examples work correctly. I think all is copacetic, but let me know if there are things that require fixin'.