I'm trying to feed the Dirichlet density function with some sample data and estimated alpha vector using R in Python (library rpy2), but I don't understand the error that I got:
>>> q['dirichlet2b'] = DirichletReg.ddirichlet(np.asarray(mySample),np.asarray(listOfAlphas), log=False, sum_up=True) Error in rowSums(alpha) : 'x' must be an array of at least two dimensions Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 82, in __call__ return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/rpy2/robjects/functions.py", line 34, in __call__ res = super(Function, self).__call__(*new_args, **new_kwargs) rpy2.rinterface.RRuntimeError: Error in rowSums(alpha) : 'x' must be an array of at least two dimensions
The function I'm dealing with is declared as:
ddirichlet(x, alpha, log = FALSE, sum.up = FALSE) .
Its implementation is here.
From the documentation:
alpha the Dirichlet distribution’s parameters. Can be a vector (one set of parameters for all observations) or a matrix (a different set of parameters for each observa- tion), see details Details:
Usually, alpha is a vector thus the same parameters will be used for all observations. If alpha is a matrix, a complete set of alpha-parameters must be supplied for each observation.
So In a test I am running, these are the values of the two variables:
>>> mySample [0.23947368421052631, 0.29122807017543861, 0.13596491228070176, 0.24473684210526317] >>> listOfAlphas [0.96321625726816873, 0.010664397021223898, 0.0073408705340313662, 0.011574312890446362]
Why should I need a matrix of alphas for my observations? What exactly is needed to feed a Dirichlet density function?