Extreme Value Distribution y-axis not same with Histogram

1 view (last 30 days)
clc
clear
%Turning data into categorical for each column
opts = detectImportOptions('leftRight_data.csv');
varNames = opts.VariableNames ;
%since there are 8 columns filled with either, right or left there is 8
%categorical
varTypes = {'datetime','categorical','categorical',...
'categorical','categorical','categorical',...
'categorical','categorical','categorical'};
opts = setvartype(opts,varNames,varTypes);
%after setting as categorical we set everything undefined into 0
opts = setvaropts(opts,{'HandYouWriteWith','IfHoldingABatOneHandedWhichHandWouldItBeIn_',...
'HandToOpenLidOfJar','WhenUsingAKnifeAndForkTheHandWithTheForkIn',...
'WhenUsingABroomTheHandNearestTheBroomHead','HandHoldingAToothbrush',...
'WhichEarDoYouHoldAPhoneTo_','WhichFootWouldYouKickABallWith_'},'FillValue',0);
T = readtable('leftRight_data.csv',opts);
%we dont want the first column so we delete it%
Tnew = removevars(T,'Timestamp');
%convert the table to an array%
A = table2array(Tnew);
%changing the strings to numbers
C = double(A);
%Assigning values to C which is Array converted to numbers
%1 is 0, 2 is either so its 0, 3 is left so its -1, 4 is right so its 1
C(C==1)=0;
C(C==2)=0;
C(C==3)=-1;
C(C==4)=1;
%sums all the value for each row
total = sum(C,2);
%finding most common handedness value from all participants
commonv = mode(total)
%listing how many ppl are above 0
rh = total > 0;
%summing all the ones above 0
rhppl = sum(rh);
%divide the amount before with number of participants
rhpercent = rhppl./size(A(:,1));
rhpercent(2) = []
%plotting histogram
subplot(2,1,1);
histogram(total);
hold on;
title('Histogram of People and their Handedness Level');
xlabel('Handedness Value');
ylabel('Amount of People');
%fitting a normal distribution
pd = fitdist(total,'ExtremeValue')
x_values = linspace(-8,8,50);
y = pdf(pd, x_values);
plot(x_values,y,'r','LineWidth',2);
hold off
subplot(2,1,2);
plot(x_values,y,'r','LineWidth',2);
%paramEstsTotal = evfit(total);
%y = linspace(-8,8,221);
%p = evpdf(y,paramEstsTotal(1),paramEstsTotal(2));
%line(y,.25*length(total)*p,'color','r');
%hold off;
So this is the graph I got and the Extreme Value Distribution does not have the same y-axis as the histogram. How can I fix this?
Capture.PNG

Answers (1)

Jeff Miller
Jeff Miller on 6 Nov 2019
histogram(total,'normalization','pdf');

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!