steve_bank
Diabetic retinopathy and poor eyesight. Typos ...
Discrete sampling is easy to emulate.
You receive a shipment of widgets wit an expectedd distribution of three colors. You take a small sample to check the ditrubtion of discrte colors.
You can vary the population size and sample size and see what happens.
You can download Scilab or port it. It would have been hard to generate distributions in a macro.
You receive a shipment of widgets wit an expectedd distribution of three colors. You take a small sample to check the ditrubtion of discrte colors.
You can vary the population size and sample size and see what happens.
You can download Scilab or port it. It would have been hard to generate distributions in a macro.
Code:
clear
clc
mprintf("RUNNING\n\n")
function [s] = rand_seq(nr,ns)
// random sequnce 1 - nr with no duplicates
//length ns
s = zeros(ns,1)
for i = 1:ns
cnt = nr
while(cnt > 0)
flag = 1
x = grand(1,1,"uin",1,nr)
for j = 1:ns
if(x == s(j))then flag = 0;end;
end //j
if(flag == 1)then break;end;
cnt = cnt - 1
end //while
s(i) = x
end //i
endfunction
function [y] = rand_samp(samples,population)
//pick random samples
n = length(samples)
for i = 1:n y(i) = population(samples(i));end;
endfunction
npop = 1000
nsamp = 50
n1 = 50
n2 = 200
n3 = 750
for i = 1:npop
if(i<=n1) then y(i) = 1;end;
if(i>n1&&i<=n2) then y(i) = 2;end;
if(i>n2) then y(i) = 3;end;
end
//randomize population
nshuf = length(y)
rx = rand_seq(nshuf,nshuf)
for i = 1:nshuf
r(i) = y(rx(i))
end
//take samples
rs = rand_seq(npop,nsamp)
s = rand_samp(rs,r)
cnt = zeros(3,1)
for i = 1:nsamp
if(s(i) == 1)then cnt(1) = cnt(1) + 1;end;
if(s(i) == 2)then cnt(2) = cnt(2) + 1;end;
if(s(i) == 3)then cnt(3) = cnt(3) + 1;end;
end
//sample prcentages
pc1 =100. * cnt(1)/nsamp
pc2 =100. * cnt(2)/nsamp
pc3 =100. * cnt(3)/nsamp
//population percentages
pcn1 =100. * n1/npop
pcn2 =100. * n2/npop
pcn3 =100. * n3/npop
mprintf(" %.d %d %d\n",pcn1,pcn2,pcn3)
mprintf(" %.d %d %d\n",pc1,pc2,pc3)