%Load data and make variables

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);


%Plot hight
hist(hogde)
boxplot(hogde)
boxplot(hogde,kjonn)

%Make vectors with hight of men and women

indexMann=find(kjonn==1);
indexKvinne=find(kjonn==2);
hogdeMann=hogde(indexMann);
hogdeKvinne=hogde(indexKvinne);

%histograms
subplot(1,2,1)
hist(hogdeMann)
subplot(1,2,2)
hist(hogdeKvinne)

%mean
mean(hogdeMann)
mean(hogdeKvinne)

antmenn=length(indexMann)
antkvinner=length(indexKvinne)
















%Sample from distribution of hights for young Norwegian mans, and find
%means

figure
nsample=500;
samplemeans=zeros(nsample,1);
for(i=1:nsample)
    ASample=random('Normal',179.8,6.5,1,antmenn);
    subplot(1,2,1)
    hist(ASample)
    title('Eit utvalg')
    samplemeans(i)=mean(ASample);
    subplot(1,2,2) 
    hist(samplemeans(1:i));
    title('Utvalsfordeling for gjennomsnitt')
    pause(0.05)
end

%Rask
nsample=10000;
samplemeans=zeros(nsample,1);
Samples=random('Normal',179.8,6.5,nsample,antmenn);
samplemeans=mean(Samples');?


f=find(samplemeans>mean(hogdeMann));
length(f)/nsample





%Probability hypothesis test
1-normcdf(mean(hogdeMann),179.8,sqrt(6.5^2/antmenn))
1-normcdf(mean(hogdeKvinne),167.2,sqrt(6.5^2/antkvinner))



%Simulerer med Poisson
nsample=10000;
ineachsample=20;
samplemeans=zeros(nsample,1);
Samples=random('Poisson',1,nsample,ineachsample);
samplemeans=mean(Samples');
figure
subplot(1,2,1)
hist(Samples(:,1))
title('Eit utvalg, Poisson')
subplot(1,2,2)
hist(samplemeans)
title('Utvalsfordeling for gjennomsnitt, Poisson')



%Simulerer med eksponensial
nsample=10000;
ineachsample=20;
samplemeans=zeros(nsample,1);
Samples=random('exp',1,nsample,ineachsample);
samplemeans=mean(Samples');
figure
subplot(1,2,1)
hist(Samples(:,1))
title('Eit utvalg, eksponensial')
subplot(1,2,2)
hist(samplemeans)
title('Utvalsfordeling for gjennomsnitt, eksponensial')

