Last active
December 8, 2021 01:44
-
-
Save devCcori/ec1d739e12858992ba4790bd44d0a45e to your computer and use it in GitHub Desktop.
Ploting hipotesis testing in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Plots | |
using Distributions | |
using StatsPlots | |
using StatsFuns | |
################################################################ | |
#[round.(x,digits=7) for x in [q0*[-2:2;];7.155417528]] | |
#normcdf(distribution, α) | |
################################################################ | |
#Add estimator | |
function Estimator(Q::String,e) | |
vline!([e],label=string(Q,"=",e),line=:solid,linewidth=4) | |
end | |
################################################################ | |
#Modificar a conveniencia para lo que se necesite | |
function DownloadImagenes(e) | |
ProportionNUnilateralRight(0.01) | |
png(string("P",e,"_1")) | |
ProportionNUnilateralRight(0.01) | |
Estimator("Z",0.6182070924) | |
png(string("P",e,"_2")) | |
ProportionNUnilateralRight1(0.7317805822688619) | |
Estimator("Z",0.6182070924) | |
png(string("P",e,"_3")) | |
end | |
################################################################ | |
##For μ and n ≥ 30 | |
#For ploting unilateral right hypothesis testing | |
function MeanNUnilateralRight(α) | |
n = Normal() | |
q0 = quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:orange, label="Zona de Aceptación",xticks=[round.(x,digits=) for x in [0.]],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,8, fillrange=0, c=:yellow, label="Zona de Rechazo") | |
vline!([q0],label=string("Z(α)=Z(",α,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
#For ploting unilateral left hypothesis testing | |
function MeanNUnilateralLeft(α) | |
n = Normal() | |
q0 = -quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:yellow, label="Zona de Rechazo",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,4, fillrange=0, c=:orange, label="Zona de Aceptación") | |
vline!([q0],label=string("-Z(α)=-Z(",α,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
#For ploting bilateral hypothesis testing | |
function MeanNBilateralHypothesis(α) | |
n = Normal() | |
q0 = quantile(n,α/2) | |
q1 = -quantile(n,α/2) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:yellow, label="Zona de Rechazo",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,q1, fillrange=0, c=:orange, label="Zona de Aceptación") | |
plot!(x->pdf(n,x),q1,4, fillrange=0, c=:yellow, label=false) | |
vline!([q0],label=string("Z(α/2)=Z(",α/2,")"), line=:dash, linewidth=2) | |
vline!([q1],label=string("-Z(α/2)=-Z(",α/2,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
############################################################ | |
##For μ and n < 30 and ¿σ? | |
#For ploting unilateral right hypothesis testing | |
function MeanTdUnilateralRight(m,α) | |
n = TDist(m-1) | |
q0 = quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:orange, label="Zona de Aceptación",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,4, fillrange=0, c=:yellow, label="Zona de Rechazo") | |
vline!([q0],label=string("-t(α)=-t(",α,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
#For ploting unilateral left hypothesis testing | |
function MeanTdUnilateralLeft(m,α) | |
n = TDist(m-1) | |
q0 = -quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:orange, label="Zona de Rechazo",ylim=[0,0.4]) | |
plot!(x->pdf(n,x),q0,4, fillrange=0, c=:yellow, label="Zona de Aceptación") | |
vline!([q0],label=string("-t(α)=-t(",α,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
#For ploting bilateral hypothesis testing | |
function MeanTdBilateralHypothesis(m,α) | |
n = TDist(m-1) | |
q0 = quantile(n,α) | |
q1 = -quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:yellow, label="Zona de Rechazo",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,q1, fillrange=0, c=:orange, label="Zona de Aceptación") | |
plot!(x->pdf(n,x),q1,4, fillrange=0, c=:yellow, label=false) | |
vline!([q0],label=string("t(α/2)=t(",α/2,")"), line=:dash, linewidth=2) | |
vline!([q1],label=string("-t(α/2)=-t(",α/2,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
############################################################ | |
##For P and n ≥ 30 | |
#For ploting unilateral right hypothesis testing | |
function ProportionNUnilateralRight(α) | |
n = Normal() | |
q0 = quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:orange, label="Zona de Aceptación",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,4, fillrange=0, c=:yellow, label="Zona de Rechazo") | |
vline!([q0],label=string("Z(α)=Z(",α,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
#For ploting unilateral left hypothesis testing | |
function ProportionNUnilateralLeft(α) | |
n = Normal() | |
q0 = -quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:yellow, label="Zona de Rechazo",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,4, fillrange=0, c=:orange, label="Zona de Aceptación") | |
vline!([q0],label=string("-Z(α)=-Z(",α,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
#For ploting bilateral hypothesis testing | |
function ProportionNBilateralHypothesis(α) | |
n = Normal() | |
q0 = quantile(n,α) | |
q1 = -quantile(n,α) | |
plot(x->pdf(n,x),-4,q0, fillrange=0, c=:yellow, label="Zona de Rechazo",xticks=q0*[-2:2;],ylim=(0,0.4)) | |
plot!(x->pdf(n,x),q0,q1, fillrange=0, c=:orange, label="Zona de Aceptación") | |
plot!(x->pdf(n,x),q1,4, fillrange=0, c=:yellow, label=false) | |
vline!([q0],label=string("Z(α/2)=Z(",α/2,")"), line=:dash, linewidth=2) | |
vline!([q1],label=string("-Z(α/2)=-Z(",α/2,")"), line=:dash, linewidth=2) | |
plot!(size=(600,300)) | |
end | |
############################################################ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment