Skip to content

Instantly share code, notes, and snippets.

@mschauer
Created September 30, 2020 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mschauer/839cc8385448a98ab2a8910f43916179 to your computer and use it in GitHub Desktop.
Save mschauer/839cc8385448a98ab2a8910f43916179 to your computer and use it in GitHub Desktop.
One sided test for hypothesis about proportion
#=
Newborn babies are more likely to be boys than girls.
A random sample found 13 173 boys were born among 25 468
newborn children. Population: All children born that time period. Alternatively,
the unknown p could be the unknown probability.
=#
b = 13173
n = 25486
p̂ = b/n
#H0 p = 0.5
p0 = 0.5 #null value
# Check if n is large enough
n*p0 > 5
n*(1 - p0)
# Every below computed under H0
SE = sqrt(p0*(1-p0)/n)
# Compute the test statistic
z = (p̂ - p0)/SE
# z is large, evidence in favour of H1: p > 0.5
α = 0.05
z0 = quantile(Normal(0,1), 1 - α)
if z > z0
println("Reject the null! With 0.05 significance ... p>0.5")
else
println("Null hypothesis cannot be rejected")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment