I want to generate a random sample size of 90 (10+30+50), create a list that holds these 90 randomly generated samples and find the sample median. this is what I'm given:
sub_pop = [300, 500, 1000]
samplesize = [10, 30, 50]
std_list = [40, 50, 60]
mean_list = [50, 60, 70]
in other words, I want to randomly generate a sub sample size of 10 from sub_pop 300, a sub sample size of 30 from sub_pop 500 and a sub sample size of 50 from sub_pop 1000 and then append the results into a single list. each sub_pop are normally distributed as follows: sub_pop 300 is normally distributed wif std dev 40 and mean 50, sub_pop 500 is normally distributed wif std dev 50 and mean 60 and so on.
this is what I've done so far:
import numpy as np
n_pop = 1800
obs_size = 90
sub_pop = [300, 500, 1000]
samplesize = [10, 30, 50]
std_list = [40, 50, 60]
mean_list = [50, 60, 70]
list = []
for i in range(300):
list += np.random.normal(loc = 50, scale = 40, size = 10).tolist()
for i in range(500):
list += np.random.normal(loc = 60, scale = 50, size = 30).tolist()
for i in range(1000):
list += np.random.normal(loc = 70, scale = 60, size = 50).tolist()
list1 = [abs(x) for x in list]
print(list1)
print(np.median(list1))
is my approach right?
sample_sizeelt with the random parameter of the population is enough. Compare to my answer, it means that thesizeargument must be changed tosize=samplesize[i]. - Mathieu