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

[BUG] Markov model attribution may sometimes not work as intended due to the way it is computed #41

Closed
taksqth opened this issue Oct 27, 2021 · 0 comments · Fixed by #42
Assignees
Labels
bug Something isn't working

Comments

@taksqth
Copy link
Contributor

taksqth commented Oct 27, 2021

Sometimes when calling mam.attribution_markov() the procedure may produce a warning stating a Singular Matrix Error and when that happens the attributed values are not reliable (it is possible that negative numbers are produced, which doesn't make much sense in this context). This happens due to way that the removal effect is computed, which requires an eigenvector factorization to get an infinite power for the transition matrix. This eigenvector matrix may not be inversible, which leads to the error. The exact kind of scenarios where this may happen are not clear and may even be due to numeric errors, as they usually seem to happen when some channels have much less interactions than others.

Fortunately, further research on the topic is not needed, because what we want is the probability that the user will eventually reach the (absorbing) conversion state from the starting state from our constructed transition matrix. Computing the infinite power was a first (naive) implementation to get that, but it is possible to compute those absorving properties via the following code (as described in the wikipedia article):

Q = matrix[:-2,:-2] # Those indices follow from the construction, where we have the conversion 
R = matrix[:-2,-2:] # and non-conversion states as the last 2
    
N = np.linalg.inv(np.identity(len(Q)) - Q)
return (N @ R)[0,1] # We also assume the first row represents the starting state

The matrix N is called the fundamental matrix and it can be proven that it will always exist (Theorem 2.2.2 in [1]), given the properties of how we expect the conversion matrixes to be constructed in MAM.

We should, therefore, change the implementation to use this new method.

[1] Kassir, A. (2018). Absorbing Markov Chains with Random Transition Matrices and Applications. UC Irvine. ProQuest ID: Kassir_uci_0030D_15141. Merritt ID: ark:/13030/m50k7645. Retrieved from https://escholarship.org/uc/item/52h7q78h

@taksqth taksqth added the bug Something isn't working label Oct 27, 2021
@taksqth taksqth self-assigned this Oct 27, 2021
taksqth added a commit to taksqth/Marketing-Attribution-Models that referenced this issue Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant