knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
When learning statistical inference, it is important to
The samplingsimulatorr package aims to make these steps easy by taking care of the coding part, and so you can focus more on the learning part. The samplingsimulatorr package provides the following functions that will:
This document introduces to you the basic tools of samplingsimulatorr package and shows you how to use those tools.
generate_virtual_popTo start learning sample distribution and sampling distribution, we need first to generate a virtual population. The generate_virtual_pop helps you generate a group of virtual population with the distribution of your choice. You just need to fill the size of the population you want to generate, the variable name of that population, and the distribution the population comes from. The function would then produce a nice tibble of the virtual population you sepcified.
library(samplingsimulatorr) # generate population pop <- generate_virtual_pop(1000, "height", rnorm, 0, 1) head(pop)
draw_samplesAfter we have the virtual population, the next thing we need to do is to draw samples from that population. draw_samples function helps you draw samples of different sizes from that population. You can also repeatedly draw the samples of the same sizes multiple times to create a sampling distribution.
# the number of replication for each sample size reps <- 100 # the sample sizes for each one of the samples sample_size <- c(10, 50, 100) # create samples samples <- draw_samples(pop, reps, sample_size) head(samples)
plot_sample_histAfter having the samples, we can then plot the sample histograms for different sample sizes using plot_sample_hist function.
# plot sample histogram plot_sample_hist(pop, samples, height, sample_size)
plot_sampling_histSince we have drawn the samples of the same size multiple times, we can then plot a nice sampling histogram. The plot_sampling_hist creates a grid of sampling distribution histogram of the mean of different sample sizes.
plot_sampling_hist(samples, height, sample_size)
stat_summaryFinally, we have both population and samples, the stat_summary creates a summary of the statistical for the arameters of interest.
stat_summary(pop, samples, c('mean', 'sd'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.