Reputation: 22893
I need to fit my data into a Beta distribution and retrieve the alpha parameter. I'm trying to use R from python (rpy2) and my code looks like:
from rpy2 import *
from rpy2.robjects.packages import importr
MASS = importr('MASS') #myVector is a Numpy array with values between 0 and 1
MASS.fitdistr(myVector,"beta")
But I get this error:
Error in function (x, densfun, start, ...) :
'start' must be a named list
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 function (x, densfun, start, ...) :
'start' must be a named list
I can't seem to find any good documentation for R with detailed examples, so I only found this:
start A named list giving the parameters to be optimized with initial values. This can be omitted for some of the named distributions (see Details). ... Additional parameters, either for densfun or for optim. In particular, it can be used to specify bounds via lower or upper or both. If arguments of densfun (or the density function corresponding to a character-string specification) are included they will be held fixed.
I really have no clue as to:
start=list(shape1=0.5, shape2=0.5)
won't do the trickAny hint?
Upvotes: 1
Views: 10632
Reputation: 22893
Ok, after a little bit more of digging, I found a solution:
from rpy2.robjects import DataFrame
starter= DataFrame({'shape1':0.5,'shape2':0.5})
x = MASS.fitdistr(myValues, "beta", start=starter))
Upvotes: 2