Package: samplingsimulatorpy
samplingsimulatorpysamplingsimulatorpyis a Python package intended to assist those teaching or learning basic statistical inference.AuthorsNameGitHubHolly Williamshwilliams10Lise BraatenlisebraatenTao Guotguo9Yue (Alex) JiangYueJiangMDSVOverviewThis package allows users to generate virtual populations which can be sampled from in order to compare and contrast sample vs sampling distributions for different sample sizes.  The package also allows users to sample from the generated virtual population (or any other population), plot the distributions, and view summaries for the parameters of interest.Installation:pip install -i https://test.pypi.org/simple/ samplingsimulatorpyFunction Descriptionsgenerate_virtual_popcreates a virtual population.Inputs: distribution function (i.e.np.random.lognormal,np.random.binomial, etc), the parameters required by the distribution function, and the size of the population.Outputs: the virtual population as a tibbledraw_samplesgenerates samples of different sizesInputs: population to sample from, the sample size, and the number of samplesOutputs: returns a tibble with the sample number in one column and value in a second column.plot_sample_histcreates sample distributions for different sample sizes.Inputs: population to sample from, the samples to plot, and a vector of the sample sizesOutputs: returns a grid of sample distribution plotsplot_sampling_distcreates sampling distributions for different sample sizes.Inputs: population to sample from, the samples to plot, and a vector of the sample sizesOutputs: returns a grid of sampling distribution plotsstat_summary: returns a summary of the statistical parameters of interestInputs: population, samples, parameter(s) of interestOutputs: summary tibbleHow do these fit into the Python ecosystem?To the best of our knowledge, there is currently no existing Python package with the specific functionality to create virtual populations and make the specific sample and sampling distributions described above. We do make use of many existing Python packages and expand on them to make very specific functions. These include:scipy.statsto get distribution functionsnp.randomto generate random samplesAltairto create plotsPythonpandasalready includes some summary statistics functions such as.describe(), however our package will be more customizable.  Our summary will only include the statistical parameters of interest and will provide a comparison between the sample, sampling, and true population parameters.Dependenciespython = "^3.7"pandas = "^1.0.1"numpy = "^1.18.1"altair = "^4.0.1"Usagegenerate_virtual_popfrom samplingsimulatorpy import generate_virtual_pop
generate_virtual_pop(size, distribution_func, *para)Arguments:size: The number of samplesdistribution_func: The distribution that we are generating samples from*para: The arguments required for the distribution functionExample:pop = generate_virtual_pop(100, np.random.normal, 0, 1)draw_samplesfrom samplingsimulatorpy import draw_samples
draw_samples(pop, reps, n_s)Arguments:popthe virtual population as a data framerepsthe number of replication for each sample size as an integer
valuen_sthe sample size for each one of the samples as a listExample:samples = draw_samples(pop, 3, [5, 10, 15, 20])plot_sample_histfrom samplingsimulatorpy import plot_sample_hist
plot_sample_hist(pop, samples)Arguments:popthe virtual population as a data framesamplesthe samples as a data frameExample:plot_sample_hist(samples)plot_sampling_histfrom samplingsimulatorpy import plot_sampling_hist
plot_sampling_hist(pop, samples)Arguments:samplesthe samples as a data frameExample:plot_sampling_hist(samples)stat_summaryfrom samplingsimulatorpy import stat_summary
plot_sampling_hist(pop, samples, parameter)ArgumentspopulationThe virtual populationsamplesThe drawed samplesparameterThe parameter(s) of interestExamplestat_summary(pop, samples, ['np.mean', 'np.std'])Example Usage Scenariofromsamplingsimulatorpyimportgenerate_virtual_pop,draw_samples,plot_sample_dist,plot_sampling_dist,stat_summary# create virtual populationpop=generate_virtual_pop(100,np.random.normal,0,1)# take samplessamples=draw_samples(pop,3,[10,20])# plot sample histogramplot_sample_hist(pop,samples)# plot sampling distributionplot_sampling_hist(samples)# compare mean and standard deviationstat_summary(pop,samples,['np.mean','np.std'])DocumentationThe official documentation is hosted on Read the Docs:https://samplingsimulatorpy.readthedocs.io/en/latest/CreditsThis package was created with Cookiecutter and the UBC-MDS/cookiecutter-ubc-mds project template, modified from thepyOpenSci/cookiecutter-pyopensciproject template and theaudreyr/cookiecutter-pypackage.