Can I generate random numbers with specific conditions, like this . . .
"8 set of random numbers (a, b, c, d, e, f, g, and h)"
- each set has the same 'mean' (arithmetic Mean)
- the range of random numbers is 1-9
- every set is normal distribution
- but sample size for each set is difference for example :
set a, sample size 30 (30 of random numbers)
set b, sample size 50
set c, sample size 80
set d, sample size 100
set e, sample size 200
set f, sample size 300
set g, sample size 500
set h sample size 1,000
thank you for your kindness and sorry about my broken english ^_^
When you say that each set has the same mean, do you mean the exact same mean?
or should all be normal distributed with mean=5, sd=2 for example.
You can look into the rand() function and then either truncate, discard or floor values that go outside of your range, but that may change your distribution. It really depends on what your SD and mean are though...ie a mean of 5 and sd of 1 would rarely have any values outside of 1 or 9.
From all the criteria the sample size being different is actually the easiest to control! Same mean and between 1 and 9 will be the most difficult, in my opinion.
samplesize = 300; /* update to desired sample size*/
seed = date(); /*setting a seed for the random number generator*/
do i = 1 to samplesize;
obs = ceil((ranuni(seed) * 9)); /*change upper bound here */
I think your biggest problem is to define mu and sigma of Normal Distribution.
Your mean " the range of random numbers is 1-9 " ,That is to mean mu=5, sigma is not quit sure,
because basing my statistical knowledge , the valuefrom normal will 99.7% probability fall in between mu-3*sigma and mu+3*sigma (e.g ~N(0,1) ,the value will 99.7% probability fall in -3 and 3).
So if as the rule of 3*sigma then sigma will be about 1.4, to make sure value fall in 1-9,
I set sigma = 1.2, or you can change it more little.
Remember sigma is relation with mu for your situation ( from 1-9).
Another problem is arithmetic mean,Are you to mean (1+2+3+4)/4 ?
In numeric calculated ,there can not be exactly matched,So I use round() function to
%let mu=5; *Normal Distribution 's position parameter;
%let sigma=1.2; *Normal Distribution 's scale parameter;
%let mean=5.0; * Your arithmetic Mean;
%macro normal(mu= , sigma= , sample_size= , mean=);
data normal_&sample_size ;
value=rand('normal',μ,σ); count+1; sum+value;
do until(count = &sample_size);
if round(sum/count,.1) = &mean then output;