Cantidad pivotal o estadístico

normal

\[ Z=\frac{\bar{x}_{size}-mean}{\frac{sd}{\sqrt{size}}}{\sim}N(0,1^2) \]

t - student

\[ T=\frac{\bar{x}_{size}-mean}{\frac{\widehat{sd}}{\sqrt{size}}}{\sim}t_{(size-1)} \]

Calculo de probabilidades

normal

\[ P\left(-z_{\frac{\alpha}{2}}{\leq}\frac{\bar{x}_{size}-mean}{\frac{sd}{\sqrt{size}}}{\leq}z_{\frac{\alpha}{2}}\right)=1-\alpha \]

\[ P\left(-z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}{\leq}\bar{x}_{size}-mean{\leq}z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}\right)=1-\alpha \]

\[ P\left(-\bar{x}_{size}-z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}{\leq}-mean{\leq}-\bar{x}_{size}+z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}\right)=1-\alpha \]

\[ P\left(\bar{x}_{size}+z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}{\geq}mean{\geq}\bar{x}_{size}-z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}\right)=1-\alpha \]

\[ P\left(\bar{x}_{size}-z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}{\leq}mean{\leq}\bar{x}_{size}+z_{\frac{\alpha}{2}}\frac{sd}{\sqrt{size}}\right)=1-\alpha \]

t - student

\[ P\left(-t_{\left(size-1,\frac{\alpha}{2}\right)}{\leq}\frac{\bar{x}_{size}-mean}{\frac{\widehat{sd}}{\sqrt{size}}}{\leq}t_{\left(size-1,\frac{\alpha}{2}\right)}\right)=1-\alpha \]

\[ P\left(-t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}{\leq}\bar{x}_{size}-mean{\leq}t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}\right)=1-\alpha \]

\[ P\left(-\bar{x}_{size}-t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}{\leq}-mean{\leq}-\bar{x}_{size}+t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}\right)=1-\alpha \]

\[ P\left(\bar{x}_{size}+t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}{\geq}mean{\geq}\bar{x}_{size}-t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}\right)=1-\alpha \]

\[ P\left(\bar{x}_{size}-t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}{\leq}mean{\leq}\bar{x}_{size}+t_{\left(size-1,\frac{\alpha}{2}\right)}\frac{\widehat{sd}}{\sqrt{size}}\right)=1-\alpha \]

library(mosaic)
## Warning: replacing previous import 'lifecycle::last_warnings' by
## 'rlang::last_warnings' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_unnamed' by
## 'rlang::check_dots_unnamed' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_used' by
## 'rlang::check_dots_used' when loading 'tibble'
## Warning: replacing previous import 'ellipsis::check_dots_empty' by
## 'rlang::check_dots_empty' when loading 'tibble'
cdist( "t", .95, df = 30)

## [1] -2.042272  2.042272
library(mosaic)
cdist( "norm", .95)

## [1] -1.959964  1.959964
x <- rnorm(23, mean = 10, sd = 2)
cdist("t", p = 0.95, df=22)

## [1] -2.073873  2.073873
mean(x) + cdist("t", p = 0.95, df=22) * sd(x) / sqrt(23)

## [1]  9.047287 10.937560
confint(t.test(x))
cdist("t", p = 0.95, df=22, verbose = TRUE)
## Verbose output not yet implemented.

## [1] -2.073873  2.073873

Una muestra

Hipótesis nula

\[H_0:\mu\geq\mu_0\leftrightarrow\mu-\mu_0\geq0\]

\[H_0:\mu=\mu_0\leftrightarrow\mu-\mu_0=0\]

\[H_0:\mu\leq\mu_0\leftrightarrow\mu-\mu_0\leq0\]

Hipótesis alternativa

\[H_1:\mu<\mu_0\leftrightarrow\mu-\mu_0<0\]

\[H_1:\mu\neq\mu_0\leftrightarrow\mu-\mu_0\neq0\]

\[H_1:\mu>\mu_0\leftrightarrow\mu-\mu_0>0\]

Dos muestras

Hipótesis nula

\[H_0:\mu_m\geq\mu_h\leftrightarrow\mu_m-\mu_h\geq0\]

\[H_0:\mu_m=\mu_h\leftrightarrow\mu_m-\mu_h=0\]

\[H_0:\mu_m\leq\mu_h\leftrightarrow\mu_m-\mu_h\leq0\]

Hipótesis alternativa

\[H_1:\mu_m<\mu_h\leftrightarrow\mu_m-\mu_h<0\]

\[H_1:\mu_m\neq\mu_h\leftrightarrow\mu_m-\mu_h\neq0\]

\[H_1:\mu_m>\mu_h\leftrightarrow\mu_m-\mu_h>0\]

Estadísticos de prueba

normal

\[ Z=\frac{\bar{x}_{n}-\mu_0}{\frac{\sigma}{\sqrt{n_x}}}{\sim}N(\mu,\sigma^2) \]

t - student

\[ T=\frac{\bar{x}_{n}-\mu_0}{\frac{S_x}{\sqrt{n}}}{\sim}t_{(n-1)} \]

Ejemplo sobre algunos datos simulados de ingresos

Fijar semilla, las medias y las desviaciones estándar

media.hombres <- 1160000
desvest.hombres <-  5000
set.seed(12345678)
ingresos.hombres <- rnorm(n=50000, mean=media.hombres, sd=desvest.hombres)
head(ingresos.hombres)
## [1] 1165739 1168092 1148105 1158717 1164462 1156238
Ingresos.hombres <- cbind.data.frame(c(rep("hombres",50000)),c(ingresos.hombres), stringsAsFactors = TRUE)
colnames(Ingresos.hombres) <- c("Genero","Ingreso")
head(Ingresos.hombres)

Gráfico de los ingresos de los hombres

library(ggplot2);library(dplyr)
ggplot(data=Ingresos.hombres,aes(x=Genero,y=Ingreso, colour=Genero)) + geom_boxplot()

Seleccionar una muestra aleatoria

set.seed(12345678)
muestra <- Ingresos.hombres[sample(1:nrow(Ingresos.hombres),size=200),]
head(muestra)

Realización de la prueba de hipótesis

Sistema de hipótesis

\[H_0:\mu\geq\mu_0\leftrightarrow\mu-\mu_0\geq0\]

\[H_1:\mu<\mu_0\leftrightarrow\mu-\mu_0<0\]

\[H_0:\mu\geq1160000\leftrightarrow\mu-1160000\geq0\]

\[H_1:\mu<1160000\leftrightarrow\mu-1160000<0\]

Distribución de la muestra aleatoria

library(ggplot2)
ggplot(muestra, aes(x=Genero, y=Ingreso)) +
  geom_jitter(width=0.1) +
  stat_summary(fun.data="mean_se", col="red")

Estadístico de prueba

\[ t=\frac{\bar{x}_{hombres}-\mu_{0}}{\frac{S_{hombres}}{\sqrt{n_{hombres}}}}\sim t_{(n_{hombres}-1)} \]

Bajo la hipótesis nula \(H_0:\mu\geq\mu_0\leftrightarrow\mu-\mu_0\geq0\)

\[ t=\frac{\bar{x}_{hombres}-1160000}{\frac{S_{hombres}}{\sqrt{n_{hombres}}}}\sim t_{(n_{hombres}-1)} \]

Realización de la prueba de hipótesis

t.test(x=muestra[muestra$Genero=="hombres","Ingreso"],alternative="less",mu=1160000,var.equal=TRUE,conf.level = 0.95)
## 
##  One Sample t-test
## 
## data:  muestra[muestra$Genero == "hombres", "Ingreso"]
## t = 0.45237, df = 199, p-value = 0.6743
## alternative hypothesis: true mean is less than 1160000
## 95 percent confidence interval:
##     -Inf 1160806
## sample estimates:
## mean of x 
##   1160173

Visualización de la prueba de hipótesis

library(visualize)
gl <- length(muestra[muestra$Genero=="hombres","Ingreso"])-1
valor.de.tabla <- qt(0.05,df=gl)
valor.de.tabla
## [1] -1.652547
t = (mean(muestra[muestra$Genero=="hombres","Ingreso"])-1160000)/sqrt(var(muestra[muestra$Genero=="hombres","Ingreso"])/length(muestra[muestra$Genero=="hombres","Ingreso"]))
t
## [1] 0.4523679
pt(t,gl,lower.tail=TRUE)
## [1] 0.6742516
visualize.t(stat=valor.de.tabla,df=gl,section="lower")
abline(v=t,col="red",lty=2,lwd=3)

Ejemplo sobre algunos datos simulados de ingresos

Fijar semilla, las medias y las desviaciones estándar

media.hombres <- 1160000
desvest.hombres <-  5000
set.seed(12345678)
ingresos.hombres <- rnorm(n=50000, mean=media.hombres, sd=desvest.hombres)
head(ingresos.hombres)
## [1] 1165739 1168092 1148105 1158717 1164462 1156238
Ingresos.hombres <- cbind.data.frame(c(rep("hombres",50000)),c(ingresos.hombres), stringsAsFactors = TRUE)
colnames(Ingresos.hombres) <- c("Genero","Ingreso")
head(Ingresos.hombres)

Gráfico de los ingresos de los hombres

library(ggplot2);library(dplyr)
ggplot(data=Ingresos.hombres,aes(x=Genero,y=Ingreso, colour=Genero)) + geom_boxplot()

Seleccionar una muestra aleatoria

set.seed(12345678)
muestra <- Ingresos.hombres[sample(1:nrow(Ingresos.hombres),size=200),]
head(muestra)

Realización de la prueba de hipótesis

Sistema de hipótesis

\[H_0:\mu=\mu_0\leftrightarrow\mu-\mu_0=0\]

\[H_1:\mu\neq\mu_0\leftrightarrow\mu-\mu_0\neq0\]

\[H_0:\mu=1160000\leftrightarrow\mu-1160000=0\]

\[H_1:\mu\neq1160000\leftrightarrow\mu-1160000\neq0\]

Distribución de la muestra aleatoria

library(ggplot2)
ggplot(muestra, aes(x=Genero, y=Ingreso)) +
  geom_jitter(width=0.1) +
  stat_summary(fun.data="mean_se", col="red")

Estadístico de prueba

\[ t=\frac{\bar{x}_{hombres}-\mu_{0}}{\frac{S_{hombres}}{\sqrt{n_{hombres}}}}\sim t_{(n_{hombres}-1)} \]

Bajo la hipótesis nula \(H_0:\mu\geq\mu_0\leftrightarrow\mu-\mu_0\geq0\)

\[ t=\frac{\bar{x}_{hombres}-1160000}{\frac{S_{hombres}}{\sqrt{n_{hombres}}}}\sim t_{(n_{hombres}-1)} \]

Realización de la prueba de hipótesis

t.test(x=muestra[muestra$Genero=="hombres","Ingreso"],alternative="two.sided",mu=1160000,var.equal=TRUE,conf.level = 0.95)
## 
##  One Sample t-test
## 
## data:  muestra[muestra$Genero == "hombres", "Ingreso"]
## t = 0.45237, df = 199, p-value = 0.6515
## alternative hypothesis: true mean is not equal to 1160000
## 95 percent confidence interval:
##  1159418 1160928
## sample estimates:
## mean of x 
##   1160173

Visualización de la prueba de hipótesis

library(visualize)
gl <- length(muestra[muestra$Genero=="hombres","Ingreso"])-1
valor.de.tabla <- qt(0.05,df=gl)
valor.de.tabla
## [1] -1.652547
t = (mean(muestra[muestra$Genero=="hombres","Ingreso"])-1160000)/sqrt(var(muestra[muestra$Genero=="hombres","Ingreso"])/length(muestra[muestra$Genero=="hombres","Ingreso"]))
t
## [1] 0.4523679
pt(t,gl,lower.tail=FALSE)
## [1] 0.3257484
visualize.t(stat=c(-valor.de.tabla,valor.de.tabla),df=gl,section="tails" )
abline(v=t,col="red",lty=2,lwd=3)

Ejercicios

  1. Realizar la prueba de hipótesis con un nivel de significancia del 0.02

  2. Realizar la prueba de hipótesis con un nivel de significancia del 0.03

  3. Realizar la prueba de hipótesis con un nivel de significancia del 0.04

  4. Realizar la prueba de hipótesis con un nivel de significancia del 0.07

  5. Realizar la prueba de hipótesis con un nivel de significancia del 0.09

Fijar semilla, las medias y las desviaciones estándar

media.hombres <- 1160000
media.mujeres <- 1160000
desvest.hombres <-  5000
desvest.mujeres <- 5000
set.seed(12345678)
ingresos.hombres <- rnorm(n=50000, mean=media.hombres, sd=desvest.hombres)
head(ingresos.hombres)
## [1] 1165739 1168092 1148105 1158717 1164462 1156238
Ingresos.hombres <- cbind.data.frame(c(rep("hombres",50000)),c(ingresos.hombres), stringsAsFactors = TRUE)
colnames(Ingresos.hombres) <- c("Genero","Ingreso")
head(Ingresos.hombres)
set.seed(12345678)
ingresos.mujeres <- rnorm(n=54000, mean=media.mujeres, sd=desvest.mujeres)
Ingresos.mujeres <- 
cbind.data.frame(c(rep("mujeres",54000)),c(ingresos.mujeres), stringsAsFactors = TRUE)
colnames(Ingresos.mujeres) <- c("Genero","Ingreso")
head(Ingresos.mujeres)

Poner todo dentro de un data frame o marco de datos

Ingresos <- rbind.data.frame(Ingresos.hombres, Ingresos.mujeres)
head(Ingresos)
tail(Ingresos)

Gráfico de los ingresos según el género

library(ggplot2);library(dplyr)
ggplot(data=Ingresos,aes(x=Genero,y=Ingreso, colour=Genero)) + geom_boxplot()

Seleccionar una muestra aleatoria

set.seed(12345678)
muestra <- Ingresos[sample(1:nrow(Ingresos),size=200),]
head(muestra)

Realización de la prueba de hipótesis

Sistema de hipótesis

\[H_0:\mu_m\geq\mu_h\leftrightarrow\mu_m-\mu_h\geq0\]

\[H_1:\mu_m<\mu_h\leftrightarrow\mu_m-\mu_h<0\]

Distribución de la muestra aleatoria

library(ggplot2)
ggplot(muestra, aes(x=Genero, y=Ingreso)) +
  geom_jitter(width=0.1) +
  stat_summary(fun.data="mean_se", col="red")

Estadístico de prueba

\[ t=\frac{\bar{x}_{hombres}-\bar{x}_{mujeres}-(\mu_{hombres}-\mu_{mujeres})}{\frac{S_{hombres}}{\sqrt{n_{mujeres}}}+\frac{S_{mujeres}}{\sqrt{n_{mujeres}}}}\sim t_{(n_{mujeres}+n_{hombres}-2)} \]

Bajo la hipótesis nula \(H_0:\mu_m\geq\mu_h\leftrightarrow\mu_m-\mu_h\geq0\)

\[ t=\frac{\bar{x}_{hombres}-\bar{x}_{mujeres}-0}{\frac{S_{hombres}}{\sqrt{n_{mujeres}}}+\frac{S_{mujeres}}{\sqrt{n_{mujeres}}}}\sim t_{(n_{mujeres}+n_{hombres}-2)} \]

Realización de la prueba de hipótesis

t.test(x=muestra[muestra$Genero=="hombres","Ingreso"],y=muestra[muestra$Genero=="mujeres","Ingreso"],alternative="less",mu=0,var.equal=TRUE,conf.level = 0.95)
## 
##  Two Sample t-test
## 
## data:  muestra[muestra$Genero == "hombres", "Ingreso"] and muestra[muestra$Genero == "mujeres", "Ingreso"]
## t = 1.2784, df = 198, p-value = 0.8987
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
##     -Inf 2225.75
## sample estimates:
## mean of x mean of y 
##   1160490   1159520

Visualización de la prueba de hipótesis

library(visualize)
gl <- length(muestra[muestra$Genero=="mujeres","Ingreso"])+length(muestra[muestra$Genero=="hombres","Ingreso"])-2
valor.de.tabla <- qt(0.05,df=gl)
valor.de.tabla
## [1] -1.652586
t = (mean(muestra[muestra$Genero=="hombres","Ingreso"])-mean(muestra[muestra$Genero=="mujeres","Ingreso"]))/sqrt(var(muestra[muestra$Genero=="hombres","Ingreso"])/length(muestra[muestra$Genero=="hombres","Ingreso"])+var(muestra[muestra$Genero=="mujeres","Ingreso"])/length(muestra[muestra$Genero=="mujeres","Ingreso"]))
t
## [1] 1.281259
pt(t,gl,lower.tail=TRUE)
## [1] 0.8991994
visualize.t(stat=valor.de.tabla,df=gl,section="lower")
abline(v=t,col="red",lty=2,lwd=3)

Ejercicios

  1. Realizar la prueba de hipótesis con un nivel de significancia del 0

  2. Realizar la prueba de hipótesis con un nivel de significancia del 0.04

  3. Realizar la prueba de hipótesis con un nivel de significancia del 0.05

  4. Realizar la prueba de hipótesis con un nivel de significancia del 0.08

  5. Realizar la prueba de hipótesis con un nivel de significancia del 0.1

Ejemplo sobre algunos datos simulados de ingresos

Fijar semilla, las medias y las desviaciones estándar

media.hombres <- 1160000
media.mujeres <- 1160000
desvest.hombres <-  5000
desvest.mujeres <- 5000
set.seed(12345678)
ingresos.hombres <- rnorm(n=50000, mean=media.hombres, sd=desvest.hombres)
head(ingresos.hombres)
## [1] 1165739 1168092 1148105 1158717 1164462 1156238
Ingresos.hombres <- cbind.data.frame(c(rep("hombres",50000)),c(ingresos.hombres), stringsAsFactors = TRUE)
colnames(Ingresos.hombres) <- c("Genero","Ingreso")
head(Ingresos.hombres)
set.seed(12345678)
ingresos.mujeres <- rnorm(n=54000, mean=media.mujeres, sd=desvest.mujeres)
Ingresos.mujeres <- 
cbind.data.frame(c(rep("mujeres",54000)),c(ingresos.mujeres), stringsAsFactors = TRUE)
colnames(Ingresos.mujeres) <- c("Genero","Ingreso")
head(Ingresos.mujeres)

Poner todo dentro de un data frame o marco de datos

Ingresos <- rbind.data.frame(Ingresos.hombres, Ingresos.mujeres)
head(Ingresos)
tail(Ingresos)

Gráfico de los ingresos según el género

library(ggplot2);library(dplyr)
ggplot(data=Ingresos,aes(x=Genero,y=Ingreso, colour=Genero)) + geom_boxplot()

Seleccionar una muestra aleatoria

set.seed(12345678)
muestra <- Ingresos[sample(1:nrow(Ingresos),size=200),]
head(muestra)

Realización de la prueba de hipótesis

Sistema de hipótesis

\[H_0:\mu_m=\mu_h\leftrightarrow\mu_m-\mu_h=0\]

\[H_1:\mu_m\neq\mu_h\leftrightarrow\mu_m-\mu_h\neq0\]

Distribución de la muestra aleatoria

library(ggplot2)
ggplot(muestra, aes(x=Genero, y=Ingreso)) +
  geom_jitter(width=0.1) +
  stat_summary(fun.data="mean_se", col="red")

Estadístico de prueba

Estadístico de prueba

\[ t=\frac{\bar{x}_{hombres}-\bar{x}_{mujeres}-(\mu_{hombres}-\mu_{mujeres})}{\frac{S_{hombres}}{\sqrt{n_{mujeres}}}+\frac{S_{mujeres}}{\sqrt{n_{mujeres}}}}\sim t_{(n_{mujeres}+n_{hombres}-2)} \]

Bajo la hipótesis nula \(H_0:\mu_m\geq\mu_h\leftrightarrow\mu_m-\mu_h\geq0\)

\[ t=\frac{\bar{x}_{hombres}-\bar{x}_{mujeres}-0}{\frac{S_{hombres}}{\sqrt{n_{mujeres}}}+\frac{S_{mujeres}}{\sqrt{n_{mujeres}}}}\sim t_{(n_{mujeres}+n_{hombres}-2)} \]

Realización de la prueba de hipótesis

t.test(x=muestra[muestra$Genero=="hombres","Ingreso"],y=muestra[muestra$Genero=="mujeres","Ingreso"],alternative="two.sided",mu=0,var.equal=TRUE,conf.level = 0.95)
## 
##  Two Sample t-test
## 
## data:  muestra[muestra$Genero == "hombres", "Ingreso"] and muestra[muestra$Genero == "mujeres", "Ingreso"]
## t = 1.2784, df = 198, p-value = 0.2026
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -526.7321 2468.3222
## sample estimates:
## mean of x mean of y 
##   1160490   1159520

Visualización de la prueba de hipótesis

library(visualize)
gl <- length(muestra[muestra$Genero=="mujeres","Ingreso"])+length(muestra[muestra$Genero=="hombres","Ingreso"])-2
valor.de.tabla <- qt(0.95+(0.05/2),df=gl)
valor.de.tabla
## [1] 1.972017
t = (mean(muestra[muestra$Genero=="hombres","Ingreso"])-mean(muestra[muestra$Genero=="mujeres","Ingreso"]))/sqrt(var(muestra[muestra$Genero=="hombres","Ingreso"])/length(muestra[muestra$Genero=="hombres","Ingreso"])+var(muestra[muestra$Genero=="mujeres","Ingreso"])/length(muestra[muestra$Genero=="mujeres","Ingreso"]))
t
## [1] 1.281259
pt(t,gl,lower.tail=TRUE)
## [1] 0.8991994
visualize.t(stat=c(-valor.de.tabla,valor.de.tabla),df=gl,section="tails")
abline(v=t,col="red",lty=2,lwd=3)

Ejercicios

  1. Realizar la prueba de hipótesis con un nivel de significancia del 0

  2. Realizar la prueba de hipótesis con un nivel de significancia del 0.04

  3. Realizar la prueba de hipótesis con un nivel de significancia del 0.05

  4. Realizar la prueba de hipótesis con un nivel de significancia del 0.08

  5. Realizar la prueba de hipótesis con un nivel de significancia del 0.1

Ejemplo sobre algunos datos simulados de ingresos

Fijar semilla, las medias y las desviaciones estándar

media.hombres <- 1160000
media.mujeres <- 1160000
desvest.hombres <-  5000
desvest.mujeres <- 5000
set.seed(12345678)
ingresos.hombres <- rnorm(n=50000, mean=media.hombres, sd=desvest.hombres)
head(ingresos.hombres)
## [1] 1165739 1168092 1148105 1158717 1164462 1156238
Ingresos.hombres <- cbind.data.frame(c(rep("hombres",50000)),c(ingresos.hombres), stringsAsFactors = TRUE)
colnames(Ingresos.hombres) <- c("Genero","Ingreso")
head(Ingresos.hombres)
set.seed(12345678)
ingresos.mujeres <- rnorm(n=54000, mean=media.mujeres, sd=desvest.mujeres)
Ingresos.mujeres <- 
cbind.data.frame(c(rep("mujeres",54000)),c(ingresos.mujeres), stringsAsFactors = TRUE)
colnames(Ingresos.mujeres) <- c("Genero","Ingreso")
head(Ingresos.mujeres)

Poner todo dentro de un data frame o marco de datos

Ingresos <- rbind.data.frame(Ingresos.hombres, Ingresos.mujeres)
head(Ingresos)
tail(Ingresos)

Gráfico de los ingresos según el género

library(ggplot2);library(dplyr)
ggplot(data=Ingresos,aes(x=Genero,y=Ingreso, colour=Genero)) + geom_boxplot()

Seleccionar una muestra aleatoria

set.seed(12345678)
muestra <- Ingresos[sample(1:nrow(Ingresos),size=200),]
head(muestra)

Realización de la prueba de hipótesis

Sistema de hipótesis

\[H_0:\mu_m\leq\mu_h\leftrightarrow\mu_m-\mu_h\leq0\]

\[H_1:\mu_m>\mu_h\leftrightarrow\mu_m-\mu_h>0\]

Distribución de la muestra aleatoria

library(ggplot2)
ggplot(muestra, aes(x=Genero, y=Ingreso)) +
  geom_jitter(width=0.1) +
  stat_summary(fun.data="mean_se", col="red")

Estadístico de prueba

\[ t=\frac{\bar{x}_{hombres}-\bar{x}_{mujeres}-(\mu_{hombres}-\mu_{mujeres})}{\frac{S_{hombres}}{\sqrt{n_{mujeres}}}+\frac{S_{mujeres}}{\sqrt{n_{mujeres}}}}\sim t_{(n_{mujeres}+n_{hombres}-2)} \]

Bajo la hipótesis nula \(H_0:\mu_m\leq\mu_h\leftrightarrow\mu_m-\mu_h\leq0\)

\[ t=\frac{\bar{x}_{hombres}-\bar{x}_{mujeres}-0}{\frac{S_{hombres}}{\sqrt{n_{mujeres}}}+\frac{S_{mujeres}}{\sqrt{n_{mujeres}}}}\sim t_{(n_{mujeres}+n_{hombres}-2)} \]

Realización de la prueba de hipótesis

t.test(x=muestra[muestra$Genero=="hombres","Ingreso"],y=muestra[muestra$Genero=="mujeres","Ingreso"],alternative="greater",mu=0,var.equal=TRUE,conf.level = 0.95)
## 
##  Two Sample t-test
## 
## data:  muestra[muestra$Genero == "hombres", "Ingreso"] and muestra[muestra$Genero == "mujeres", "Ingreso"]
## t = 1.2784, df = 198, p-value = 0.1013
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -284.1594       Inf
## sample estimates:
## mean of x mean of y 
##   1160490   1159520

Visualización de la prueba de hipótesis

library(visualize)
gl <- length(muestra[muestra$Genero=="mujeres","Ingreso"])+length(muestra[muestra$Genero=="hombres","Ingreso"])-2
valor.de.tabla <- qt(0.95,df=gl)
valor.de.tabla
## [1] 1.652586
t = (mean(muestra[muestra$Genero=="hombres","Ingreso"])-mean(muestra[muestra$Genero=="mujeres","Ingreso"]))/sqrt(var(muestra[muestra$Genero=="hombres","Ingreso"])/length(muestra[muestra$Genero=="hombres","Ingreso"])+var(muestra[muestra$Genero=="mujeres","Ingreso"])/length(muestra[muestra$Genero=="mujeres","Ingreso"]))
t
## [1] 1.281259
pt(t,gl,lower.tail=FALSE)
## [1] 0.1008006
visualize.t(stat=valor.de.tabla,df=gl,section="upper")
abline(v=t,col="red",lty=2,lwd=3)

Ejercicios

  1. Realizar la prueba de hipótesis con un nivel de significancia del 0

  2. Realizar la prueba de hipótesis con un nivel de significancia del 0.04

  3. Realizar la prueba de hipótesis con un nivel de significancia del 0.05

  4. Realizar la prueba de hipótesis con un nivel de significancia del 0.08

  5. Realizar la prueba de hipótesis con un nivel de significancia del 0.1