%%
load('../Data/StudDataV16.txt')
%%
hogde=StudDataV16(:,1);
hogdeFar=StudDataV16(:,2);
hogdeMor=StudDataV16(:,3);
kjonn=StudDataV16(:,4);
har=StudDataV16(:,5);
auge=StudDataV16(:,6);

%%
figure
menn=find(kjonn==1);
kvinner=find(kjonn==2);
subplot(2,1,1)
hist(hogde(menn))
title('Hogde menn')
subplot(2,1,2)
hist(hogde(kvinner))
title('Hogde kvinner')

length(menn)
length(kvinner)

mean(hogde(menn))
mean(hogde(kvinner))
%%

figure
subplot(2,1,1)
[nA,xoutA] = hist(auge,1:1:3)
bar(xoutA, nA)
title('Augefarge, blaa (1), brun(2) og gron(3)')
subplot(2,1,2)
[nH,xoutH]=hist(har,1:1:3)
bar(xoutH,nH)
title('Harfarge, lys/blond (1), brun/svart (2) og raud(3)')

flys=find(har==1);
fbrun = find(har==2);
fraud=find(har==3);

%%

figure
subplot(1,3,1)
[nAlys,xoutA] = hist(auge(flys),1:1:3);
bar(xoutA,nAlys)
xlabel('Augefarge')
title('Harfarge lys')
subplot(1,3,2)
[nAbrun,xoutAbrun] = hist(auge(fbrun),1:1:3)
bar(xoutA, nAbrun)
xlabel('Augefarge')
title('Harfarge brun')
subplot(1,3,3)
[nAraud,xoutA] = hist(auge(fraud),1:1:3);
bar(xoutA, nAraud)
xlabel('Augefarge')
title('Harfarge raud')

%%

figure()
bar3(xoutA,[nAlys;nAbrun;nAraud]')
colormap([0.9 0.9 0;0.2 0.1 0;1,0,0])
ylabel('Augefarge')
xlabel('Harfarge')

%%

figure()
bar3(xoutA,[nAlys;nAbrun;nAraud]'/length(har))
colormap([0.9 0.9 0;0.2 0.1 0;1,0,0])
ylabel('Augefarge')
xlabel('Harfarge')
title('Simultan sannsynsfordeling for harfarge (som 5-aring) og augefarge')

%%

sannsford=[nAlys;nAbrun;nAraud]'/length(har)
%f(auge,haar)

antall=[nAlys;nAbrun;nAraud]'

%%

%Finn marinalfordelingar
figure
MarginalAuge=sum(sannsford')
nA/length(auge)
subplot(2,1,1)
bar(xoutA,MarginalAuge)
title('(Marginal)fordeling til augefarge')


MarginalHar=sum(sannsford)
nH/length(har)
subplot(2,1,2)
bar(xoutH,MarginalHar)
title('(Marginal)fordeling til harfarge')

%%

%Finn betingafordeling, haarfarge|auge=blaa
sannsford(1,:) %tar ut den rada

betford=sannsford(1,:)/sum(sannsford(1,:))


