Alcampopiano / hypothesize

Robust statistics in Python
https://alcampopiano.github.io/hypothesize/
BSD 3-Clause "New" or "Revised" License
62 stars 3 forks source link

trim_mean not defined for 'est' #10

Closed paul-hawkins closed 4 years ago

paul-hawkins commented 4 years ago

On Python 3.7 on Windows 10 (Anaconda/Jupyter notebook)

for compare_groups_with_single_factor.bootdpci the only arugment to the est function allowable is trim_mean:

https://alcampopiano.github.io/hypothesize/function_guide/#bootdpci

est: function

Measure of location (currently only trim_mean is supported)

However on

import hypothesize as hypo
hypo.compare_groups_with_single_factor.bootdpci(xdf,est=trim_mean)

NameError: name 'trim_mean' is not defined

If other estimators, such as numpy.mean, are used

hypo.compare_groups_with_single_factor.bootdpci(xdf,est=np.mean)

the following error is thrown:


analysis is being done on difference scores each confidence interval has probability coverage of 1-alpha.
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-39-c2264eb089c1> in <module>
      1 # https://alcampopiano.github.io/hypothesize/function_guide/#bootdpci
----> 2 hypo.compare_groups_with_single_factor.bootdpci(xdf,est=np.mean)

~\anaconda3\envs\oepython37\lib\site-packages\hypothesize\compare_groups_with_single_factor\_compare_groups_with_single_factor.py in bootdpci(x, est, nboot, alpha, dif, BA, SR, *args)
   1024 
   1025     results=rmmcppb(x, est, *args, nboot=nboot,alpha=alpha,
-> 1026                    SR=SR, dif=dif, BA=BA)
   1027 
   1028     col_names = ['con_num', 'psihat', 'p_value', 'p_crit', 'ci_lower', 'ci_upper']

~\anaconda3\envs\oepython37\lib\site-packages\hypothesize\compare_groups_with_single_factor\_compare_groups_with_single_factor.py in rmmcppb(x, est, alpha, con, dif, nboot, BA, hoch, SR, seed, *args)
    322 
    323         temp=rmmcppbd(x,est, *args, alpha=alpha,con=con,
--> 324                       nboot=nboot,hoch=True)
    325 
    326         if called_directly:

~\anaconda3\envs\oepython37\lib\site-packages\hypothesize\compare_groups_with_single_factor\_compare_groups_with_single_factor.py in rmmcppbd(x, est, alpha, con, nboot, hoch, seed, *args)
    646 
    647     for ic in range(ncon):
--> 648       output[ic, 1] = tmeans[ic]
    649       output[ic, 0] = ic
    650       output[ic, 2] = test[ic]

IndexError: invalid index to scalar variable.
Alcampopiano commented 4 years ago

Hi Paul,

Thanks for the report and for using the library!

A couple things that might help.

  1. trim_mean has to be imported first.
  2. est is a actually a positional argument. This is stated in the docs for bootdpci, but perhaps it could be made more clear:

Note that arguments up to and including args are positional arguments

If you import trim_mean and specify it as positional, it should work. Example:

from hypothesize.utilities import trim_mean
results=bootdpci(df, trim_mean, .2)

Also, in the docs there is a button you can click that allows you to see an example of every function being run. Example:

This can be a helpful way of seeing how the functions can be run and playing around with them straight away. Everything seems to work as expected in that context.

Does this help?

Alcampopiano commented 4 years ago

@paul-hawkins Closing but feel free to reopen if you feel I've not addressed this issue.