function p=chisquared(c)
%gives the p-value where c=observed chisquared for a chisquared test of multinomial(16,(1/4,1/4,1/4,1/4))
chs=[];
for i=1:50000
    U=rand(1,16);
    N=[sum(U<=.25) sum((U>.25)&(U<=.5)) sum((U>.5)&(U<=.75)) sum(U>.75)];
    chs=[chs sum((N-4).^2./4)];
end
p=mean(chs>=c);
hist(chs,40)

    
    