<div dir="ltr"><div><div><div><br></div>Dear Experts,<br><br></div>I have an unbalanced dataset (group1=16 subjects ('better'), group2=12 subjects ('worse'). I would like to perform Monte-Carlo testing of the SMLR between-subject classification analysis (performed on cope images).  I used the permutation_test.py script as an example and tried to adjust it for my unbalanced dataset. <br><br></div>Any feedback on whether the script below makes sense is greatly appreciated.<br><div><br><br>lm = 0.2 # The value was determined through the nested cross-validation procedure<br><br>clf = SMLR(lm=lm, fit_all_weights=False, descr='SMLR(lm=%g)' % lm)<br><br>### how often do we want to shuffle the data<br>repeater = Repeater(count=200)<br><br>### permute the training part of a dataset exactly ONCE<br>permutator = AttributePermutator('targets', limit={'partitions': 1}, count=1)<br><br>### Make sure that each group ("better" and "worse") has the same number of samples<br>par = ChainNode([NFoldPartitioner(cvtype=2, attr='chunks'),<br>                  Sifter([('partitions', 2),<br>                          ('targets', dict(uvalues=['better', 'worse'],<br>               balanced=True))])<br>                 ], space='partitions')<br><br></div><div>### I believe this will apply permutator on each fold created by par.<br></div><div>par_perm = ChainNode([par, permutator], space=par.get_space())<br><br># CV with null-distribution estimation that permutes the training data for<br># each fold independently<br>null_cv = CrossValidation(<br>            clf,<br>            par_perm,<br>            errorfx=mean_mismatch_error)<br><br># Monte Carlo distribution estimator<br>distr_est = MCNullDist(repeater, tail='left', measure=null_cv,<br>                       enable_ca=['dist_samples'])<br><br># actual CV with H0 distribution estimation<br>cv = CrossValidation(clf, par, errorfx=mean_mismatch_error,<br>                     null_dist=distr_est, enable_ca=['stats'])<br><br><br>err = cv(ds_mni_bw)<br><br>p = err.ca.null_prob<br>np.asscalar(p)<br><br><br></div><div>Thank you very much,<br></div><div>Anna.<br></div><div><br><br><br></div></div>