3
votes

How do I generate a new list from random numbers that have the same mean and standard deviation from the original list?

I tried newlist = mean(list) + std(list)*randn(100,1); which I found on the Matlab website but it was generating slightly different std and mean from the original since the new mean is always bigger.

2
100 points is probably not enough points to get exactly the same mean and standard deviation. Try with more points.mor22

2 Answers

2
votes

The trick is to generate random numbers with mean 0 and std dev 1. We do this by generating any old random numbers, then fixing the mean and standard deviation afterwards.

% generate your random numbers
r = randn(100, 1);

% scale the variance
r2 = r / std(r);

% shift the mean
r3 = r2 - mean(r2);

%check your answer
abs(mean(r3)) < sqrt(eps)
abs(std(r3) - 1) < sqrt(eps)

Now newlist = mean(list) + std(list) * r3 should give you what you need.

0
votes

Sorry to answer a question with a question, but I have to ask...

Why do you need to ensure that the mean of your vector of random numbers is precisely same as your original vector? In a similar vein, why does the standard deviation need to be precisely the same?

If I run a monte carlo simulation or some such, I'm trying to discover what might happen. If you adjust your random numbers so that the mean is precisely X and the standard deviation is exactly Y you're decreasing the chance that your simulation will contain an extreme event. In turn, this mean's that its less likely that something is going to go wrong.

These types of transforms are fine as an academic exercise, however, I'd have grave concerns about employing this type of method in the real world.

  1. You're defeating the whole purpose of your simulation
  2. If your methods are so sensitive that they won't work is the mean and standard deviation are off by some arbitrarily small amount this, in and of itself, should tell you something