function type1Error=BehrensFisher();

sigmaX=8;
NX=310;

sigmaY=10;
NY=40;



rejected=0;
iterations=1000;

%One sided test) H0: MeanX<=MeanY; HA: MeanX>MeanY 

for(t=1:iterations)
    delta=0;
    X=randn(1,NX)*sigmaX+delta;  %if add positive number, alt is true 
    Y=randn(1,NY)*sigmaY;
    
    
    SX=sqrt(var(X));
    SY=sqrt(var(Y));
    
    
    %case 1:if variances are known
    %testStat=(mean(X)-mean(Y))/sqrt(sigmaX^2/NX+sigmaY^2/NY);
    %critical = norminv(.95);  % constant
    
    %case 2A: if variances are not known, STAT 101 says pool    
    %SPooled=sqrt(((NX-1)*SX^2+(NY-1)*SY^2)/(NX+NY-2));
    %testStat=(mean(X)-mean(Y))/(SPooled*sqrt(1/NX+1/NY));
    %critical=tinv(.95,NX+NY-2); 
    %critical
    
    %case 2b: if variances are not known, STAT 101 says Welch
    testStat=(mean(X)-mean(Y))/sqrt(SX^2/NX+SY^2/NY);
    Welch_SatterwaitheDF=(SX^2/NX+SY^2/NY)^2/(SX^4/(NX^2*(NX-1))+SY^4/(NY^2*(NY-1)));
    %Welch_SatterwaitheDF
    critical=tinv(.95,Welch_SatterwaitheDF);%Satterwaithe Corrected
    %critical
    
    if(testStat>critical)    
        rejected=rejected+1;
    end
end

type1Error=rejected/iterations;

%HW Suggestion: How does the Bayesian (Gibbs implemented) one side test compare?





