Más aplicaciones estadísticas en:

https://rpubs.com/orlandoan

1. Una muestra.

1.1. Datos.

Tomados de Essentials of probability & statistics for engineers & scientists Walpole Myers Myers Ye. Pag 257.

1.2. Estadístico de prueba.

\(t_{p}=\dfrac{\bar{x}-\mu_{0}}{\frac{S}{\sqrt{n}}}\)

Tiene distribución \(t\) con \(\nu=n-1\) grados de libertad.

x<-c(7.07,7.00,7.10,6.97,7.00,7.03,7.01,7.01,6.98,7.08)
n<-length(x);n
## [1] 10
m=mean(x);m
## [1] 7.025
media<-7
de<-sd(x);de
## [1] 0.04403282
tp<-(m-media)/(de/sqrt(n));tp
## [1] 1.79541

1.3. Dos colas.

\(H_{0}: \mu = \mu_{0}\)

\(H_{1}: \mu \neq \mu_{0}\)

prueba<-t.test(x,mu=media,alternative="two.sided")
prueba
## 
##  One Sample t-test
## 
## data:  x
## t = 1.7954, df = 9, p-value = 0.1062
## alternative hypothesis: true mean is not equal to 7
## 95 percent confidence interval:
##  6.993501 7.056499
## sample estimates:
## mean of x 
##     7.025

1.4. Una cola derecha.

\(H_{0}: \mu = \mu_{0}\)

\(H_{1}: \mu > \mu_{0}\)

prueba1<-t.test(x,mu=media,alternative="greater")
prueba1
## 
##  One Sample t-test
## 
## data:  x
## t = 1.7954, df = 9, p-value = 0.05308
## alternative hypothesis: true mean is greater than 7
## 95 percent confidence interval:
##  6.999475      Inf
## sample estimates:
## mean of x 
##     7.025

1.5. Una cola izquierda.

\(H_{0}: \mu = \mu_{0}\)

\(H_{1}: \mu < \mu_{0}\)

prueba2<-t.test(x,mu=media,alternative="less")
prueba2
## 
##  One Sample t-test
## 
## data:  x
## t = 1.7954, df = 9, p-value = 0.9469
## alternative hypothesis: true mean is less than 7
## 95 percent confidence interval:
##      -Inf 7.050525
## sample estimates:
## mean of x 
##     7.025

2. Dos muestras (Diferencia de medias suponiendo varianzas iguales.)

2.1. Datos.

Tomados de Essentials of probability & statistics for engineers & scientists Walpole Myers Myers Ye. Pag 270.

2.2. Estadístico de prueba.

\(t_{p}=\dfrac{(\bar{x}_{1}-\bar{x}_{2})-d_{0}}{S_{p}\sqrt{\dfrac{1}{n_{1}}+\dfrac{1}{n_{2}}}}\)

Con

\(S_{p}^{2}=\dfrac{(n_{1}-1)S_{1}^{2}+(n_{2}-1)S_{2}^{2}}{n_{1}+n_{2}-2}\)

Tiene distribución \(t\) con \(\nu=n_{1}+n_{2}-2\) grados de libertad.

x1<-c(5030,13700,10730,11400,860,2200,4250,15040,4980,11910,8130,26850,17660,
22800,1130,1690)
x2<-c(2800,4670,6890,7720,7030,7330,2810,1330,3320,1230,2130,2190)
n1<-length(x1);n1
## [1] 16
n2<-length(x2);n2
## [1] 12
m1=mean(x1);m1
## [1] 9897.5
m2=mean(x2);m2
## [1] 4120.833
v1=var(x1);v1
## [1] 62005060
v2=var(x2);v2
## [1] 6147936
sp2=((n1-1)*v1+(n2-1)*v2)/(n1+n2-2);sp2
## [1] 38373200
tp2=(m1-m2)/(sqrt(sp2)*sqrt(1/n1+1/n2));tp2
## [1] 2.441939

2.2. Dos colas.

\(H_{0}: \mu_{1} - \mu_{2}=d_{0}\)

\(H_{1}: \mu_{1} - \mu_{2} \neq d_{0}\)

prueba3<-t.test(x1,x2,mu=0,alternative="two.sided",paired=FALSE,var.equal = TRUE)
prueba3
## 
##  Two Sample t-test
## 
## data:  x1 and x2
## t = 2.4419, df = 26, p-value = 0.02172
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##    914.0939 10639.2394
## sample estimates:
## mean of x mean of y 
##  9897.500  4120.833

2.4. Una cola izquierda.

\(H_{0}: \mu_{1} - \mu_{2}=d_{0}\)

\(H_{1}: \mu_{1} - \mu_{2}< d_{0}\)

prueba4<-t.test(x1,x2,mu=0,alternative="less",paired=FALSE,var.equal = TRUE)
prueba4
## 
##  Two Sample t-test
## 
## data:  x1 and x2
## t = 2.4419, df = 26, p-value = 0.9891
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
##      -Inf 9811.487
## sample estimates:
## mean of x mean of y 
##  9897.500  4120.833

2.5. Una cola derecha.

\(H_{0}: \mu_{1} - \mu_{2}=d_{0}\)

\(H_{1}: \mu_{1} - \mu_{2} > d_{0}\)

prueba5<-t.test(x1,x2,mu=0,alternative="greater",paired=FALSE,var.equal = TRUE)
prueba5
## 
##  Two Sample t-test
## 
## data:  x1 and x2
## t = 2.4419, df = 26, p-value = 0.01086
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  1741.847      Inf
## sample estimates:
## mean of x mean of y 
##  9897.500  4120.833

3. Dos muestras (Diferencia de medias suponiendo que las varianzas no son iguales.)

3.1. Datos.

Se utilizan los datos anteriores.

3.2. Estadístico de prueba.

\(t_{p}=\dfrac{(\bar{x}_{1}-\bar{x}_{2})-d_{0}}{\sqrt{\frac{S_{1}^{2}}{n_{1}}+\frac{S_{2}^{2}}{n_{2}}}}\)

Que tiene aproximadamente una distribución \(t\) con

\(\nu= \dfrac{(\frac{S_{1}^{2}}{n_{1}}+\frac{S_{2}^{2}}{n_{2}})^{2}}{\frac{(S_{1}^{2}/n_{1})^{2}}{n_{1}-1}+\frac{(S_{2}^{2}/n_{2})^{2}}{n_{2}-1}}\)

grados de libertad.

x1<-c(5030,13700,10730,11400,860,2200,4250,15040,4980,11910,8130,26850,17660,
22800,1130,1690)
x2<-c(2800,4670,6890,7720,7030,7330,2810,1330,3320,1230,2130,2190)
n1<-length(x1);n1
## [1] 16
n2<-length(x2);n2
## [1] 12
m1=mean(x1);m1
## [1] 9897.5
m2=mean(x2);m2
## [1] 4120.833
v1=var(x1);v1
## [1] 62005060
v2=var(x2);v2
## [1] 6147936
tp3=(m1-m2)/(sqrt(v1/n1+v2/n2));tp3
## [1] 2.757793
v=(v1/n1+v2/n2)^{2}/((v1/n1)^{2}/(n1-1)+((v2/n2)^{2}/(n2-1)));v
## [1] 18.78065

3.3. Dos colas.

prueba10<-t.test(x1,x2,mu=0,alternative="two.sided",paired=FALSE,var.equal = FALSE)
prueba10
## 
##  Welch Two Sample t-test
## 
## data:  x1 and x2
## t = 2.7578, df = 18.781, p-value = 0.01261
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   1389.003 10164.331
## sample estimates:
## mean of x mean of y 
##  9897.500  4120.833

3.4. Una cola izquierda.

prueba11<-t.test(x1,x2,mu=0,alternative="less",paired=FALSE,var.equal =FALSE)
prueba11
## 
##  Welch Two Sample t-test
## 
## data:  x1 and x2
## t = 2.7578, df = 18.781, p-value = 0.9937
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
##      -Inf 9400.797
## sample estimates:
## mean of x mean of y 
##  9897.500  4120.833

3.5. Una cola derecha.

prueba12<-t.test(x1,x2,mu=0,alternative="greater",paired=FALSE,var.equal = FALSE)
prueba12
## 
##  Welch Two Sample t-test
## 
## data:  x1 and x2
## t = 2.7578, df = 18.781, p-value = 0.006306
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  2152.537      Inf
## sample estimates:
## mean of x mean of y 
##  9897.500  4120.833

4. Muestras pareadas.

4.1. Datos.

Tomados de Essentials of probability & statistics for engineers & scientists Walpole Myers Myers Ye. Pag 270.

4.2. Estadístico de prueba.

\(t_{p}= \dfrac{\bar{d}-d_{do}}{\frac{S_{d}}{\sqrt{n}}}\)

Tiene \(n-1\) grados de libertad.

x5<-c(158,92,65,98,33,89,148,58,142,117,74,66,109,57,85)
x6<-c(91,59,215,226,223,91,92,177,134,116,153,219,143,164,100)
d=x5-x6;d
##  [1]   67   33 -150 -128 -190   -2   56 -119    8    1  -79 -153  -34 -107  -15
n=length(d);n
## [1] 15
dm=mean(d);dm
## [1] -54.13333
ddm=sd(d);ddm
## [1] 83.00247
tp=(dm-0)/(ddm/sqrt(n));tp
## [1] -2.525919

4.3. Dos colas.

\(H_{0}: \mu_{D}=d0\)

\(H_{1}: \mu_{D} \neq d_{0}\)

prueba7<-t.test(x5,x6,mu=0,alternative="two.sided",paired=TRUE)
prueba7
## 
##  Paired t-test
## 
## data:  x5 and x6
## t = -2.5259, df = 14, p-value = 0.02422
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -100.098567   -8.168099
## sample estimates:
## mean difference 
##       -54.13333

4.4. Una cola izquierda.

\(H_{0}: \mu_{D}=d0\)

\(H_{1}: \mu_{D}< d_{0}\)

prueba8<-t.test(x5,x6,mu=0,alternative="less",paired=TRUE)
prueba8
## 
##  Paired t-test
## 
## data:  x5 and x6
## t = -2.5259, df = 14, p-value = 0.01211
## alternative hypothesis: true mean difference is less than 0
## 95 percent confidence interval:
##       -Inf -16.38644
## sample estimates:
## mean difference 
##       -54.13333

4.5. Una cola derecha.

\(H_{0}: \mu_{D}=d0\)

\(H_{1}: \mu_{D} > d_{0}\)

prueba9<-t.test(x5,x6,mu=0,alternative="greater",paired=TRUE)
prueba9
## 
##  Paired t-test
## 
## data:  x5 and x6
## t = -2.5259, df = 14, p-value = 0.9879
## alternative hypothesis: true mean difference is greater than 0
## 95 percent confidence interval:
##  -91.88023       Inf
## sample estimates:
## mean difference 
##       -54.13333