How to Generate Randomized Data Set with Given Mean/Median/Standard Deviation

24 visualizaciones (últimos 30 días)
Need to generate a data set thats randomIZED but not completely random with the following criteria:
Mean: 55.4
Median: 54.8
Standard Deviation: 10
I appreciate any help I can get!
  5 comentarios
Bruno Luong
Bruno Luong el 4 de Dic. de 2020
Editada: Bruno Luong el 4 de Dic. de 2020
It's not "much harder".
Sorry but such request just does look any pratical sense statistically, and usually asked by person who does not really know about random process and distribution.
Still this is a code, try to make use it if you can, good luck.
meantarget = 55.4;
mediantarget = 54.8;
starget = 10;
n = 100;
midp = 500/n;
xmid = midp*randn(1,n-2);
xmid = xmid-median(xmid);
m = meantarget-mediantarget;
s = sum(xmid);
s2 = sum(xmid.^2);
b = (m*n-s);
c = (b^2+s2-n*(m^2+starget^2))/2;
delta = b^2-4*c;
if delta < 0
error('reduce midp')
end
xhi = (b+sqrt(delta))/2;
xlo = b-xhi;
x = mediantarget+[xlo xmid xhi];
medianx = median(x)
meanx = mean(x)
stdx = std(x,1)
Jeff Miller
Jeff Miller el 4 de Dic. de 2020
Very clever, Bruno. I didn't think of generating n-2 scores and computing the last 2. I guess I should have said, "much harder for me".

Iniciar sesión para comentar.

Respuestas (1)

Bruno Luong
Bruno Luong el 3 de Dic. de 2020
Editada: Bruno Luong el 3 de Dic. de 2020
There is infinity of random variables with the same mean/median/standard deviation
Here is one that meet what you ask (three discrete values).
meantarget = 55.4;
mediantarget = 54.8;
starget = 10;
pm = 0.1;
pout = (1-pm)/2;
p = [pout pm pout];
dmx = meantarget-mediantarget;
v = starget^2;
a = dmx;
b = v+dmx^2;
delta = 2*b/pout-a^2/pout^2;
xhi = (a/pout+sqrt(delta))/2;
xlo = a/pout-xhi;
x3 = mediantarget + [xlo 0 xhi];
c = cumsum(p);
c = c/c(end);
n = 1e6;
x = rand(1,n);
[~,i] = histc(x, [0 c]);
x = x3(i);
meanx = mean(x)
medianx = median(x)
stdx = std(x)

Categorías

Más información sobre Smoothing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by