SNP_used=46;
vfrac_vector=[0.5,0.45,0.4,0.35,0.3,0.25,0.2,0.15,0.1,0.09,0.08,0.07,0.06,0.05,0.04,0.03,0.02,0.01];
top_freq=zeros(1,71);
top5_freq=zeros(1,71);
top_mcmc=zeros(1,71);
top5_mcmc=zeros(1,71);
total_freq=zeros(1,71);
triallength=25;
filename11='mouse_snp_';
filename22='_variance_fraction_';
filename33='_trial_';
no_SNPs=71;
iteration=2001

for i= 1:length(vfrac_vector)
    SNP_name1=num2str(SNP_used);
    vfrac=vfrac_vector(i);
        vfrac_name1=num2str(vfrac*100);
        filename4 = [filename11 SNP_name1  filename22 vfrac_name1 filename33];
        
    for j =1:triallength
        
            
            trial_name1= num2str(j);
            new_filename1 = [filename4 trial_name1 ];
            
            load (new_filename1)
            total_freq=total_freq+frequentist_log_likelihood;
            for ii=1:no_SNPs
                for jj=501:(iteration)
	
                    if(stored_beta(jj,ii)~=0)
                        times_in_model(ii)=times_in_model(ii)+1;
                    end
                end
            end
            sorted_TIM= sort(times_in_model,'descend');
            sorted_freq= sort(frequentist_log_likelihood, 'descend');
            for k=1:71
                
            if ( times_in_model(k)==sorted_TIM(1)) 
                top_mcmc(k)=top_mcmc(k)+1;
                top5_mcmc(k)=top5_mcmc(k)+1;
            elseif ( times_in_model(k)==sorted_TIM(2)) 
                top5_mcmc(k)=top5_mcmc(k)+1;
            elseif ( times_in_model(k)==sorted_TIM(3)) 
                top5_mcmc(k)=top5_mcmc(k)+1;
            elseif ( times_in_model(k)==sorted_TIM(4)) 
                top5_mcmc(k)=top5_mcmc(k)+1;
            elseif ( times_in_model(k)==sorted_TIM(5)) 
                top5_mcmc(k)=top5_mcmc(k)+1;
            end
            
            
            if ( frequentist_log_likelihood(k)== sorted_freq(1))
                top_freq(k)=top_freq(k)+1;
                top5_freq(k)=top5_freq(k)+1;
            elseif ( frequentist_log_likelihood(k)== sorted_freq(2))
                top5_freq(k)=top5_freq(k)+1;
            elseif ( frequentist_log_likelihood(k)== sorted_freq(3))
                top5_freq(k)=top5_freq(k)+1;
            elseif ( frequentist_log_likelihood(k)== sorted_freq(4))
                top5_freq(k)=top5_freq(k)+1;
            elseif ( frequentist_log_likelihood(k)== sorted_freq(5))
                top5_freq(k)=top5_freq(k)+1;
            end
            end
    end
end

plot( top_freq, 'red');
hold on
xlabel (' SNP ');
ylabel('number of times SNP is chosen by model ')
title('Frequentist')
plot(top5_freq, 'blue');
hold off
saveas(gcf,'freq','fig'); 

plot( top_mcmc, 'red');
hold on
xlabel (' SNP ');
ylabel('number of times SNP is chosen by model ')
title('mcmc')
plot(top5_mcmc, 'blue');
hold off
saveas(gcf,'mcmc','fig'); 

plot(total_freq);
xlabel (' SNP ');
ylabel('total log likelihood')
title('total log likelihood for  SNP 46 simulations')
saveas(gcf,'total_llh','fig'); 

newfile='analysisplot';
save(newfile)






