first of all sorry if this is not the proper place to ask but i have been trying to create some dummy variables in order to run a students t-test as well as a welch t-test and then run a monte-carlo simulation.Problem is, I am only given the sample size and standard deviation of the 2 populations. How can I go about creating some sort of representation for this data in order for me to run these tests? I wish to run these tests in either python or R. Thanks in advance.

EDIT : both populations come from a normal distribution

  • $\begingroup$ So is your question, how to generate n points generated from a normal distribution given a mean (mu) and standard deviation (sigma)? $\endgroup$
    – A Kareem
    Commented May 5, 2020 at 10:35
  • $\begingroup$ Yes, exactly, sorry for not being more precise $\endgroup$ Commented May 5, 2020 at 11:01
  • $\begingroup$ Sure, no problem, I'll write up an answer now $\endgroup$
    – A Kareem
    Commented May 5, 2020 at 11:04

1 Answer 1


In Python, to generate random numbers from a certain distribution you would pick the corresponding distribution from np.random (documentation) and pass the corresponding parameters. Thus to draw from a normal distribution you would do

import numpy as np

# for reproducible results, seed the number generator

n = 100
mu_1, std_1 = 0, 1
mu_2, std_2 = 0.2, 1.5

dataset1 = np.random.normal(loc=mu_1, scale=std_1, size=n)
dataset2 = np.random.normal(loc=mu_2, scale=std_2, size=n)

And the output

print('dataset 1:')
print(f'mean: {dataset1.mean():.2f}')
print(f'std: {dataset1.std():.2f}')
print(f'shape: {dataset1.shape}')
print('dataset 2:')
print(f'mean: {dataset2.mean():.2f}')
print(f'std: {dataset2.std():.2f}')
print(f'shape: {dataset2.shape}')

dataset 1:
mean: -0.10
std: 0.90
shape: (100,)
dataset 2:
mean: 0.23
std: 1.42
shape: (100,)

PS: You don't have to use np.random.seed that's just to make the random generator consistent with the output every time the code is run.

EDIT: Also, if you want to use a t-test on python you can use scipy.stats, thus if you want to calculate the T-test for the means of two independent samples use scipy.stats.ttest_ind, or if you want to calculate the t-test on two related samples use scipy.stats.ttest_rel

  • $\begingroup$ thank you, aso, how would one go about using the code above when the std_2 and n1 vary? just run independent ttests ? $\endgroup$ Commented May 5, 2020 at 14:01
  • $\begingroup$ You can simply create n1 and n2 and pass each n. Also, std_2 already is different in this piece of code. $\endgroup$
    – A Kareem
    Commented May 5, 2020 at 14:26
  • $\begingroup$ Hi @LucaMarinescu if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. $\endgroup$
    – A Kareem
    Commented May 10, 2020 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.