<jupyter_start><jupyter_text>Many samples from populations Here we will take a look at how we learn about a population from a sample. First let's create a population! We'll give each individual in the population an IQ. To do that we will use a normal distribution with a mean of 100 and a standard deviation of 25.<jupyter_code>#choose the parameters of our population
pop_IQ_mean = 100
pop_IQ_sd = 25

#Create a population of 100,000 people, each with a IQ
population_IQ_values = rnorm(n=100000, mean=pop_IQ_mean, sd=pop_IQ_sd )

#take a look at our population
hist(population_IQ_values)<jupyter_output><empty_output><jupyter_text>Now that we have a population let's take a random sample of 5 individuals<jupyter_code>#sample some individuals
sample_IQ_values = sample(population_IQ_values, size=5)

#take a look at our sample
sample_IQ_values<jupyter_output><empty_output><jupyter_text>If we only had this sample of the population we could use what we've learnt in descriptive statistics to calculate a mean!<jupyter_code>mean(sample_IQ_values)<jupyter_output><empty_output><jupyter_text>How close is the sample mean (what you got from runing the code just above) to the population mean?> Remember: we made the population so we know the real population mean is 100!    What if we took another sample from the population, would it give us the same mean? Re-run the code above a few times to see what kinds of means you are likely to get when you sample from the population What if we took many samples and calculate a mean for each sample? What would the distribution of these means look like?> Below we are going to use something called a **loop** to help us out. It will just do something many times. Here we will use it to take a sample, calculate a mean and store the mean. We'll tell it to do this 1000 times!<jupyter_code>#create a box to store all the values (in this case this box is called a vector!)
all_sample_means = c()

#Here we will start a "for loop" 
for (i in 1:1000){
  
  #1. take a sample
  sample_IQ_values = sample(population_IQ_values, size=10)

  #2. Get the sample mean
  sample_mean = mean(sample_IQ_values)

  #3. store the sample mean
  all_sample_means[length(all_sample_means)+1] = sample_mean
}


#take a look at all the sample means we got! 
all_sample_means<jupyter_output><empty_output><jupyter_text>Next let's take a look at these sample means in a histogram! Are there some sample means you are more likely to get than others?<jupyter_code>#take a look at all the sample means we calculated
hist(all_sample_means, breaks = seq(60,150,by=1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0571319018404908, 'fraction_numerical': 0.018404907975460124, 'mean_word_length': 5.286746987951807, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '563334', 'license': 'CC0-1.0', 'n_tokens_mistral': 829, 'n_tokens_neox': 751, 'n_words': 366, 'path': 'notebooks/intro_centralLimit.ipynb', 'repo_name': 'tbonne/IntroPychStats', 'size': '2608'}