Skip to content

Instantly share code, notes, and snippets.

@gaverdugo
Created April 10, 2018 17:38
Show Gist options
  • Save gaverdugo/0430165ff7c84169e904bc8d6c8dd23d to your computer and use it in GitHub Desktop.
Save gaverdugo/0430165ff7c84169e904bc8d6c8dd23d to your computer and use it in GitHub Desktop.
clear;
clc;
% Se generan numero aleatorios con el generador de matlab.
R = unifrnd(0,ones(300, 1));
hist(R)
% Se obtiene la media de la muestra de numeros aleatorios.
media = mean(R)
num = size(R);
num = num(1,1);
% Aprovechamos las matrices logicas de matlab para obtener unos en
% los numeros mayores a la media y ceros en los numeros menores a la media
C = R >= media;
% Se obtiene el numero de unos (signos positivos) y de ceros a los
% negativos
positivos = sum(C)
negativos = num - positivos
% bwlabel encuentra agrupaciones de numeros
[~, num_grupos_pos] = bwlabel(C == 1);
[~, num_grupos_neg] = bwlabel(C == 0);
corridas = num_grupos_pos + num_grupos_neg;
% mu de R
muR = (2 * positivos * negativos)/(positivos + negativos) + 1
% desviación estandar de R
desR = sqrt(((2 * positivos * negativos) * (2 * positivos * negativos - positivos - negativos))/(((positivos + negativos)^2) * (positivos + negativos - 1)))
% variable estadistica Z
Zc = (corridas - muR) / desR
% Z para nivel de confianza 0.05
Zt = norminv(0.05 / 2)
if Zc < -Zt & Zc > Zt
conclusion = "Los datos siguen una distribución uniforme aleatoria"
else
conclusion = "Los datos NO siguen una distribución uniforme aleatoria"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment