load('../Data/StudData2014.txt')

hogde=StudData2014(:,1);
hogdeMor=StudData2014(:,2);
hogdeFar=StudData2014(:,3);
kjonn=StudData2014(:,4);
har=StudData2014(:,5);
auge=StudData2014(:,6);
Matlab=StudData2014(:,7);

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:4)
bar(xoutH,nH)
title('Harfarge, lys blond (1), brun (2), svart (3) og raud(4)')

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

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


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

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

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

antall=[nAlys;nAbrun;nAsvart;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,:))


