function [ H z pval ] = ztest1_for_prop(p, p_sample, n, alpha, type)
% Hypothesis Test: One Sample ztest for Proportion
% Tim Placek (placetd@auburn.edu)

if strcmpi(type,'both')
sd = sqrt(p*(1-p)/n);
z = (p_sample-p)/sd;
pval = 2*(1-normcdf(abs(z),0,1)); % two tail test
H=pval<alpha;
end
if strcmpi(type,'left')
sd = sqrt(p*(1-p)/n);
z = (p_sample-p)/sd;
pval = normcdf(z,0,1); % left tail test
H=pval<alpha;
end
if strcmpi(type,'right')
sd = sqrt(p*(1-p)/n);
z = (p_sample-p)/sd;
pval = 1-normcdf(z,0,1); % right tail test
H=pval<alpha;
end
end