Matlab - hallar cuartiles matlab

 
Vista:

hallar cuartiles matlab

Publicado por MR-X (17 intervenciones) el 11/03/2010 03:42:32
HOlaaa a todos...

hay algun comando en matlab que me pueda hallar los cuartiles de una lista de datos
es decir , que me halle el cuartil 1 , que representa el 25% datos , cuartil 2 q es la mediana, y el cuartil 3 el 75 de los datos.

Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Dave
Val: 497
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

RE:hallar cuartiles matlab, La Solucion

Publicado por Dave (1094 intervenciones) el 11/03/2010 22:14:33
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']);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:hallar cuartiles matlab

Publicado por Katleen (1 intervención) el 22/08/2010 05:10:53
XQk=k*n/4
Esta es la formulaa
Q1=25
Q2=50
Q3=75
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar