%% load data 

clc; %% clear the dashboard
clearvars; %% clear the exisiting data

T = readtable('raw_data.xlsx');
dataMatrix = table2array(T); %% make sure the data become numerical

index = dataMatrix(:,1); %% choose first collumn as the index / position
defect = dataMatrix(:,2);  %% the second collumn is the number of defective unit

%% Frequency table
freqTable = tabulate(defect);
disp('Frequency Table [Value, Count, Percentage]:');
disp(freqTable);


%% Five number summary

% Compute the five-number summary
fiveNum = [min(defect), quantile(defect, [0.25, 0.5, 0.75]), max(defect)];
disp('Five-Number Summary [Min, Q1, Median, Q3, Max]:');
disp(fiveNum);

%% Histrogram

% Create the histogram
figure;
h = histogram(defect);

% Add labels and title
title('Histogram of Defective Units per Box', 'FontSize', 12, 'FontWeight', 'bold');
xlabel('Number of Defective Units', 'FontSize', 10);
ylabel('Frequency', 'FontSize', 10);

% Clean up the axes
grid on;
box off;
set(gca, 'FontSize', 10, 'TickDir', 'out');


%% boxplot 

figure;
boxplot(defect, 'Whisker', 1.5); %% also the default setting, Tukey's style
% boxplot(defect, 'Whisker', 0);  %%  min /max style
title('Boxplot of Defective Units');
ylabel('Number of Defects');
grid on;


%% Summary statistic
x = defect;

% Compute selected statistics
Statistic = {
    'Excess Kurtosis'; ...
    'Skewness'; ...
    'Range'; ...
    'Minimum'; ...
    'Maximum'; ...
    'Sum'
};

Value = [
    kurtosis(x) - 3; ...
    skewness(x); ...
    range(x); ...
    min(x); ...
    max(x); ...
    sum(x)
];

% Create and display the table
customSummary = table(Statistic, Value);
disp(customSummary);