Hola Mr -X
Aqui un ejemplo para hallar diferentes cuartiles.
Saludos
Dave
Email:
[email protected]
..................................................
% define set de datos
x = [16, 22, 24, 24, 27, 28, 29, 30]';
Nx = size(x,1);
% calcula el promedio
mx = mean(x);
% calcula la desviacion estandar
sigma = std(x);
% calcula la mediana
medianx = median(x);
% Paso 1 - rango de datos
y = sort(x);
% calcula el percentil 25avo (primer cuartil)
Q(1) = median(y(find(y<median(y))));
% calcula el percentil 50avo (segundo cuartil)
Q(2) = median(y);
% calcula el percentil 75avo (tercer cuartil)
Q(3) = median(y(find(y>median(y))));
% calcula el rango intercuartil
IQR = Q(3)-Q(1);
% compute Semi Interquartile Deviation (SID)
% The importance and implication of the SID is that if you
% start with the median and go 1 SID unit above it
% and 1 SID unit below it, you should (normally)
% account for 50% of the data in the original data set
SID = IQR/2;
% determine extreme Q1 outliers (e.g., x < Q1 - 3*IQR)
iy = find(y<Q(1)-3*IQR);
if length(iy)>0,
outliersQ1 = y(iy);
else
outliersQ1 = [];
end
% determine extreme Q3 outliers (e.g., x > Q1 + 3*IQR)
iy = find(y>Q(1)+3*IQR);
if length(iy)>0,
outliersQ3 = y(iy)
else
outliersQ3 = [];
end
% calculo del numero total de outliers
Noutliers = length(outliersQ1)+length(outliersQ3);
% display results
disp(['promedio: ',num2str(mx)]);
disp(['Desviacion Estandar: ',num2str(sigma)]);
disp(['Mediana: ',num2str(medianx)]);
disp(['Percentil 25 avo: ',num2str(Q(1))]);
disp(['Percentil 50 avo: ',num2str(Q(2))]);
disp(['Percentil 75 avo: ',num2str(Q(3))]);
disp(['Desviacion semi intercuartil: ',num2str(SID)]);
disp(['Numero de outliers: ',num2str(Noutliers)]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Percentile Calculation Example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% define percentil
kpercent = 75;
% STEP 1 - rank the data
y = sort(x);
% STEP 2 - find k% (k /100) of the sample size, n.
k = kpercent/100;
result = k*Nx;
% STEP 3 - if this is an integer, add 0.5. If it isn't an integer round up.
[N,D] = rat(k*Nx);
if isequal(D,1), % k*Nx is an integer, add 0.5
result = result+0.5;
else % round up
result = round(result);
end
% STEP 4 - Find the number in this position. If your depth ends
% in 0.5, then take the midpoint between the two numbers.
[T,R] = strtok(num2str(result),'0.5');
if strcmp(R,'.5'),
Qk = mean(y(result-0.5:result+0.5));
else
Qk = y(result);
end
% display result
fprintf(1,['\nThe ',num2str(kpercent),'th percentile is ',num2str(Qk),'.\n\n']);