Package: robusta-stats
ROBUSTAAuthor:Eitan Hemedrobusta is a statistics package in Python3 providing an interface to
many common statistical analyses, performed using throughRandRPY2.PLEASE NOTErobusta is under active development and is supplied as-is with no guarantees.InstallationInstall with pip usingpip install robusta-stats, see alsoInstallation.DocumentationSeehere.UsageFor the most recent, thorough tutorial in the different features of robusta, head on toGoogle Colab.Some of the features are shown below.Importing the library and loading dataThis could take ~15 seconds as many R libraries are imported under the hood. If you begin with an empty R environment the first you import robusta should take at least a couple of minutes, as R dependencies will be installed.importrobustaasrstFirst, define a helper function used to pretty-print output of dataframes when converting the notebook to .md (credit).fromtabulateimporttabulateimportIPython.displayasddefmd_print_df(df):md=tabulate(df,headers='keys',tablefmt='pipe')md=md.replace('|    |','|%s|'%(df.index.nameifdf.index.nameelse''))returnd.Markdown(md)First off, we need data. Using robusta we can import R built-in and some imported datasets. You can get a full list of the datasets, similarly to calling todata()with no input arguments in R.md_print_df(rst.get_available_datasets().tail())PackageItemDescription284ARToolHiggins1990Table5Split-plot Experiment Examining Effect of Moisture and Fertilizer on Dry Matter in Peat Pots285ARToolHiggins1990Table1.artAligned Rank Transformed Version of Higgins1990Table1286ARToolHiggins1990Table1Synthetic 3x3 Factorial Randomized Experiment287ARToolElkinABCSynthetic 2x2x2 Within-Subjects Experiment288ARToolElkinABSynthetic 2x2 Within-Subjects ExperimentWe can import a dataset usingrst.load_datasetiris=rst.load_dataset('iris')md_print_df(iris.head())dataset_rownamesSepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies015.13.51.40.2setosa124.931.40.2setosa234.73.21.30.2setosa344.63.11.50.2setosa4553.61.40.2setosaRunning statistical analysesAnalyses are performed through using designated model objects that also store the . The model objects are returned through calls to the function API. In this example we create a model (m) object by callingt2samples.mwill be used to fit the statistical model, returning theresultsobject.Here is a paired-samples t-test using the Students' sleep dataset previously loaded:# Create the modelm=rst.groupwise.T2Samples(data=rst.load_dataset('sleep'),independent='group',dependent='extra',subject='ID',paired=True,tail='less')# Dataframe format of the resultsmd_print_df(m.report_table())tdfp-valueCohen-d LowCohen-dCohen-d High1-4.0621390.00141645-2.11801-1.28456-0.414622# Textual report of the results - copy and paste into your results section!m.report_text()'t(9) = -4.06, p = 0.001'We can reset the models in order to update the model parameters and re-fit it. In this example, we run the same model an an independent samples t-test:m.reset(paired=False,assume_equal_variance=True,refit=True)md_print_df(m.report_table())tdfp-valueCohen-d LowCohen-dCohen-d High1-1.86081180.0395934-1.73882-0.8321810.0954595Bayesian t-testsbayes_t2samplesandbayes_t1sampleallow you to calculate Bayes factors or sample from the posterior distribution:m=rst.groupwise.BayesT2Samples(data=rst.load_dataset('mtcars'),subject='dataset_rownames',dependent='mpg',independent='am',prior_scale=0.5,paired=False)md_print_df(m.report_table())modelbferror0Alt., r=0.571.38617.97835e-07# Test different null intervals and prior values:m.reset(prior_scale=0.1,null_interval=[0,0.5],refit=True)print(f'{m.report_text()}\n\n')md_print_df(m.report_table())Alt., r=0.1 [BF1:0 = 18.64, Error = 0.001%]modelbferror0Alt., r=0.118.64112.33663e-05Analysis of varianceuseAnovato run between, within or mixed-design ANOVA, we load the anxiety dataset for the next demonstrations.For non-parametric ANOVAs seeKruskalWallisTest,FriedmanTestandAlignedRanksTest# Load the dataset and modify it from a 'wide' to 'long' format dataframeanxiety=rst.load_dataset('anxiety').set_index(['id','group']).filter(regex='^t[1-3]$').stack().reset_index().rename(columns={0:'score','level_2':'time'})md_print_df(anxiety.head())idgrouptimescore01grp1t114.111grp1t214.421grp1t314.132grp1t114.542grp1t214.6m=rst.groupwise.Anova(data=anxiety,subject='id',dependent='score',between='group',within='time')md_print_df(m.report_table())R[write to console]: Contrasts set to contr.sum for the following variables: groupTermp-valuePartial Eta-SquaredFdf1df21group0.0190.1724.352422time0.0010.904394.911.7975.243group:time0.0010.84110.193.5875.24Similarly, we run the model usign only the between subject term (group). As the model was already generated we can simpyl drop the within-subject term:m.reset(within=None,refit=True)md_print_df(m.report_table())R[write to console]: Contrasts set to contr.sum for the following variables: groupTermp-valuePartial Eta-SquaredFdf1df21group0.0190.1724.35242R and many other statistical packages (e.g.,statsmodelssupport a formula interface to fit statistical models. Here it is shown that a model can also be specified by the formula kwargs rather than specifyingdependent,betweenetc. The formula indicates that the score column is regressed by the time variable, with observations nested within the id column.m.reset(formula='score~time|id',refit=True)md_print_df(m.report_table())Termp-valuePartial Eta-SquaredFdf1df21time0.0010.60166.231.1550.55We can also run a similar, bayesian ANOVA usingBayesAnovacomparing the
specified terms to the null model:m=rst.groupwise.BayesAnova(data=anxiety,within='time',dependent='score',subject='id')md_print_df(m.report_table())modelbferror0time496.1297.82496e-05Work in progress and planned featuresrobusta includes several other features that are either under development or planned for the future.Currently under workRegressions and correlations modulesPlannedSequential analysis plots (inspired byJASP)How to contributeAll help is welcome, but currently there are no specific guidelines. Please contactEitan Hemed