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


%Make vectors with hight of men and women

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



%% Hypotesetest H0 mu=172 mot H1 mu<172
N=length(hogdeKvinne)

mu0=172;
sigma=6;
alpha=0.05;


ourObs=mean(hogdeKvinne)

meanSigma=sigma/sqrt(N)

pvalue = normcdf(ourObs,mu0,meanSigma)



%% Som forkastningsomr?de

cutoff = norminv(alpha, mu0, sigma/sqrt(N))

%zobs=(ourObs-mu0)/(meanSigma)

%% Styrkefunksjon hogde kvinner

mu1 = 167:0.1:174;
y = normcdf(cutoff,mu1,sigma/sqrt(N));
h1 = plot(mu1,y);

hold
 plot([167,174],[0.05,0.05],'r-')
 
 
 xlabel('\mu_1','FontSize',16)
 ylabel('Hogde kvinner. Sannsyn for aa forkaste H_0','FontSize',16)
 
 
 

%% Hypotese Menn H0: mu=179.8 H1: mu>179.8

N=length(hogdeMann)

mu0=179.8;
sigma=6.5;
alpha=0.05;


ourObs=mean(hogdeMann)
meanSigma=sigma/sqrt(N);

pverdi = 1- normcdf(ourObs,mu0,meanSigma)


%% Forkastningsomr?de

cutoff = norminv(1-alpha, mu0, sigma/sqrt(N))

%% Som Z-observator

ourZ=(mean(hogdeMann)-mu0)/(meanSigma)

cutoffZ = norminv(1-alpha, 0, 1)

