\[ X{\sim}\chi^2_{(n)} \]
Nota: La suma de variables aleatorias normales o distribuidas de forma normal o Gaussiana, elevadas al cuadrado sigue o tiene una distribución ji o chi cuadrado; con grados de libertad igual al número de variables aleatorias sumadas
\[ \text{Si }X_1,X_2,\ldots,X_n\stackrel{iid}{\sim}N(\mu_x,\sigma^2_x)\text{ entonces }X=\sum_{i=1}^{n}X_i^2{\sim}\chi_{(n)}^2 \]
\[ E(X)=n \] \[ Var(X)=2n \]
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggfortify)
chi.cuadrado <- function(df,fill="gray",colour="black",p=NULL){
ggdistribution(
func=dchisq,
x=seq(
from=0,
to=9*sqrt(2*df),
by=0.01
),
df=df,
fill=fill,
colour=colour,
p=p
)
}
chi.cuadrado(
df=3
)
chi.cuadrado(
df=3,
p=chi.cuadrado(
df=17,
fill="red",
colour="orange"
)
)
chi.cuadrado(
df=3,
p=chi.cuadrado(
df=17,
fill="red",
colour="orange",
p=chi.cuadrado(
df=31,
fill="yellow",
colour="green"
)
)
)
ji.cuadrado <- function(n,df,fill="orange",color="red"){
chicuadradosimulada <- replicate(
n=n,
expr=sum(
rnorm(df)**2
)
)
valoresenx <- seq(
from=0,
to=max(chicuadradosimulada),
by=0.01
)
densidadchicuadrado <- dchisq(
x=valoresenx,
df=df
)
chicuadradoteorica <- data.frame(x=valoresenx,y=densidadchicuadrado)
ggplot() +
geom_histogram(
mapping=aes(
x=chicuadradosimulada,
y=after_stat(density),
),
bins=round(x=sqrt(x=n),digits=0),
fill=fill,
color=color
) +
geom_line(
data=chicuadradoteorica,
mapping=aes(x=x,y=y),
color="black",
alpha=0.7,
linewidth=2
)
}
ji.cuadrado(n=10000,df=3)
ji.cuadrado(n=10000,df=17,fill="yellow",color="green")
ji.cuadrado(n=10000,df=31,fill="blue",color="magenta")
densidad.chicuadrado <- function(x, df) {
ggdistribution(
func=dchisq,
x=seq(
from=0,
to=6*sqrt(2*df),
by=0.01
),
df=df,
colour="blue",
p=ggdistribution(
func=dchisq,
x=seq(
from=x-0.05,
to=x+0.05,
by=0.01
),
df=df,
fill="blue"
)
) +
labs(
subtitle=bquote(
P(chi[.(df)]^2==.(x))==.(round(
x=dchisq(
x=x,
df=df
),
digits=4
))
)
)
}
densidad.chicuadrado(x=1,df=3)
distribucion.chicuadrado <- function(q, df, lower.tail=TRUE) {
ggdistribution(
func=dchisq,
x=seq(
from=0,
to=6*sqrt(2*df),
by=0.01
),
df=df,
colour="blue",
p=ggdistribution(
func=dchisq,
x=if(lower.tail==TRUE){
seq(
from=0,
to=q,
by=0.01
)
} else {
seq(
from=q,
to=6*sqrt(2*df),
by=0.01
)
},
df = df,
fill = "blue"
)
) +
labs(
subtitle=bquote(
P(chi[.(df)]^2 <= .(q)) == .(round(
x=pchisq(
q=q,
df=df,
lower.tail=lower.tail
),
digits=4
))
)
)
}
distribucion.chicuadrado(q=1,df=3,lower.tail=TRUE)
probabilidad.chicuadrado <- function(q1, q2, df) {
ggdistribution(
func=dchisq,
x=seq(
from=0,
to=6*sqrt(2*df),
by=0.01
),
df=df,
colour="blue",
p=ggdistribution(
func=dchisq,
x=seq(
from=q1,
to=q2,
by=0.01
),
df = df,
fill = "blue"
)
) +
labs(
subtitle=bquote(
P(chi[.(df)]^2 <= .(q2)) - P(chi[.(df)]^2 <= .(q1)) == .(round(
x=pchisq(
q=q2,
df=df
)-pchisq(
q=q1,
df=df
),
digits=4
))
)
)
}
probabilidad.chicuadrado(q1=1,q2=5,df=3)
\(P_{\chi_5^2}(X{\geq}3)\)
\(P_{\chi_7^2}(X{\geq}5)\)
\(P_{\chi_9^2}(X{\geq}7)\)
\(P_{\chi_11^2}(X{\geq}9)\)