Inferencia Estad stica: Excel, wxMaxima y R · MS Excel: Complemento An alisis de Datos 1 Inicio !...
Transcript of Inferencia Estad stica: Excel, wxMaxima y R · MS Excel: Complemento An alisis de Datos 1 Inicio !...
Inferencia Estadıstica:Excel, wxMaxima y R
Melilla, Mayo 2014
Vıctor Blanco
Dpt. Metodos Cuantitativos para la Economıa y la Empresa
UGR
Contenidos
1 Introduccion
2 MS EXCEL
3 MS Excel: Complemento Analisis de Datos
4 wxMaxima
Programacion Entera OPT GEST EMPR 2 / 31
I.C. para la media:
1 Varianza Conocida:X ± z1−α
2
σ√n
[PROMEDIO(DATOS) ± INTERVALO.CONFIANZA(alpha, sigma, n)]
2 Varianza Desconocida:
X ± tn−1:1−α2
Sn−1√n
[PROMEDIO(DATOS) ± DISTR.T.INV(ALPHA, n-1)]
Programacion Entera OPT GEST EMPR 3 / 31
I.C. para la varianza:
1 Media Conocida: [∑ni=1(Xi − µ)
2
χn,1−α2
,
∑ni=1(Xi − µ)
2
χn,α2
]Usando:
PRUEBA.CHI.INV(1 - ALPHA/2, n), PRUEBA.CHI.INV(ALPHA/2, n)
2 Media Desconocida: [(n − 1)S2
n−1
χn−1,1−α2
,(n − 1)S2
n−1
χn−1,α2
]Usando:
VAR(DATOS), PRUEBA.CHI.INV(1 - ALPHA/2, n-1) y PRUEBA.CHI.INV(ALPHA/2,
n-1)
Programacion Entera OPT GEST EMPR 4 / 31
I.C. para la Proporcion:
p ± z1−α2
√p(1 − p)
n
[PROMEDIO(DATOS) ± INTERVALO.CONFIANZA(alpha, sigma, n)]
Programacion Entera OPT GEST EMPR 5 / 31
I.C. para la Diferencia de Medias:
1 Muestras independientes y varianzas conocidas:
(X − Y )± z1−α2
√σ2
1
n+σ2
2
m
[PROMEDIO(MUESTRA1)-PROMEDIO(MUESTRA2) ± DISTR.NORM.INV(1-ALPHA/2)*RAIZ(VAR1/n + VAR2/m)]
2 Muestras independientes y varianzas desconocidas e iguales:
(X − Y )± tn+m−2,1−α2
√(n − 1) · S2
n−1 + (m − 1) · S2m−1
n + m − 2
√1
n+
1
m
Programacion Entera OPT GEST EMPR 6 / 31
I.C. para el Cociente de Varianzas
[Fn−1,m−1,α
2
S2m−1
S2n−1
,Fn−1,m−1,1−α2
S2m−1
S2n−1
][DISTR.F.INV(ALPHA/2;n-1, m-1)*VAR(MUESTRA2)/VAR(MUESTRA1),DISTR.F.INV(1-ALPHA/2;n-1, m-1)*VAR(MUESTRA2)/VAR(MUESTRA1)]
Programacion Entera OPT GEST EMPR 7 / 31
I.C. para la Diferencia de Proporciones
(p1 − p2)± z1−α2
√p1(1 − p1)
n+
p2(1 − p2)
m
[PROMEDIO(MUESTRA1)-PROMEDIO(MUESTRA2) ± DISTR.NORM.INV(1-ALPHA/2)*RAIZ(VAR1/n + VAR2/m)]
Programacion Entera OPT GEST EMPR 8 / 31
Contrastes para la Media
Casosσ
2C
on
oci
da
Region de rechazo
σ2
Des
con
oci
da
Region de rechazoH0 : µ = µ0
H1 : µ 6= µ0
|x − µ0|σ√n
> z1−α/2|x − µ0|
Sn−1√n
> tn−1,1−α/2
H0 : µ ≤ µ0
H1 : µ > µ0
x − µ0σ√n
> z1−αx − µ0
Sn−1√n
> tn−1,1−α
H0 : µ ≥ µ0
H1 : µ < µ0
x − µ0σ√n
< zαx − µ0
Sn−1√n
< tn−1,α
• Normal: INTERVALO.CONFIANZA(ALPHA, sigma, n).
• t-Student: DISTR.T.INV(ALPHA, n-1).
Programacion Entera OPT GEST EMPR 9 / 31
Contrastes para la varianza:µ
Des
con
oci
da
Casos Region de rechazoH0 : σ2 = σ2
0
H1 : σ2 6= σ20
(n − 1)S2n−1
σ20
< χ2n−1,α/2 o
(n − 1)S2n−1
σ20
> χ2n−1,1−α/2
H0 : σ2 ≤ σ20
H1 : σ2 > σ20
(n − 1)S2n−1
σ20
> χ2n−1,1−α
H0 : σ2 ≥ σ20
H1 : σ2 < σ20
(n − 1)S2n−1
σ20
< χ2n−1,α
Chi-Cuadrado: PRUEBA.CHI.INV(1-ALPHA, n).
Programacion Entera OPT GEST EMPR 10 / 31
Contrastes para Proporciones:
Casos Region de rechazo
H0 : p = p0
H1 : p 6= p0
|p − p0|√p(1−p)
n
> z1−α/2
H0 : p ≤ p0
H1 : p > p0
p − p0√p(1−p)
n
> z1−α
H0 : p ≥ p0
H1 : p < p0
p − p0√p(1−p)
n
< zα
Normal: INTERVALO.CONFIANZA(ALPHA, sigma, n).
Programacion Entera OPT GEST EMPR 11 / 31
Contrastes para la Diferencia de Medias:
Casos
σ2 1,σ
2 2C
on
oci
da
s
Region de rechazo
σ2 1=σ
2 2D
esco
no
cid
as
Region de Rechazo
H0 : µ1 = µ2
H1 : µ1 6= µ2
|X − Y |√σ2
1n+σ2
1m
> z1−α/2|X − Y |√
(n−1)·S2n−1+(m−1)·S2
m−1n+m−2
·√
1n+ 1
m
> tn+m−2,1−α/2
H0 : µ1 ≤ µ2
H1 : µ1 > µ2
X − Y√σ2
1n+σ2
1m
> z1−αX − Y√
(n−1)·S2n−1+(m−1)·S2
m−1n+m−2
·√
1n+ 1
m
> tn+m−2,1−α
H0 : µ1 ≥ µ2
H1 : µ1 < µ2
X − Y√σ2
1n+σ2
1m
< zαX − Y√
(n−1)·S2n−1+(m−1)·S2
m−1n+m−2
·√
1n+ 1
m
< tn+m−2,α
• Normal: INTERVALO.CONFIANZA(ALPHA, sigma, n).
• t-Student: DISTR.T.INV(ALPHA, n+m-2).
Programacion Entera OPT GEST EMPR 12 / 31
Contrastes para el Cociente de Varianzas
Casos Region de rechazo
H0 :σ2
1
σ22= r0
H1 :σ2
1
σ226= r0
r0 ·S2n−1
S2m−1
< Fn−1,m−1,α/2 o r0 ·S2n−1
S2m−1
> Fn−1,m−1,1−α/2
H0 :σ2
1
σ22≤ r0
H1 :σ2
1
σ22> r0
r0 ·S2n−1
S2m−1
> Fn−1,m−1,1−α
H0 :σ2
1
σ22≥ r0
H1 :σ2
1
σ22< r0
r0 ·S2n−1
S2m−1
< Fn−1,m−1,α
F-Snedecor: DISTR.F.INV(ALPHA/2;n-1, m-1).
Programacion Entera OPT GEST EMPR 13 / 31
Contrastes para la Dif de Proporciones
Casos Region de rechazo
H0 : p1 = p2
H1 : p1 6= p2
|p1 − p2|√p1(1−p1)
n+ p2(1−p2)
m
> z1−α/2
H0 : p1 ≤ p2
H1 : p1 > p2
p1 − p2√p1(1−p1)
n+ p2(1−p2)
m
> z1−α
H0 : p1 ≥ p2
H1 : p1 < p2
p1 − p2√p1(1−p1)
n+ p2(1−p2)
m
< zα
Normal: INTERVALO.CONFIANZA(ALPHA, sigma, n).
Programacion Entera OPT GEST EMPR 14 / 31
MS Excel: Complemento Analisis de Datos
1 Inicio → Opciones de Excel → Complementos
2 Administrar Complementos de Excel → Herramientas para analisis.
Programacion Entera OPT GEST EMPR 15 / 31
Opciones
• Estadıstica Descriptiva (I.C. Media).
• Prueba F para varianzas de dos muestras. (Cociente Varianzas).
• Prueba t para media de dos muestras emparejadas.
• Prueba t para dos muestras suponiendo varianzas iguales.
• Prueba t para dos muestras suponiendo varianzas desiguales.
• Prueba z para media de dos muestras.
Programacion Entera OPT GEST EMPR 16 / 31
Media: test mean(data, OPCIONES)
OPCIONES:
• ’mean= Media a constrastar (por defecto 0).
• alternative: ’twosided, ’greater, ’less. (Hipotesis alternativa).
• ’dev: por defecto ’unknown (desviacion tıpica).
• ’conflevel: Nivel de confianza (por defecto 0.95).
Devuelve:
• ’mean estimate: Media muestral.
• ’conf level: Nivel de confianza.
• ’conf interval: I.C. para la media.
• ’method: Procedimiento usado.
• ’hypotheses: Constraste.
• ’statistic: Valor del estadıstico.
• ’distribution: Distribucion del estadıstico usado.
• ’p value: p-valor.
Programacion Entera OPT GEST EMPR 17 / 31
Media: test mean(data, OPCIONES)
load("stats")$
data:[78,64,35,45,45,75,43,74,42,42]$
test mean(data, ’conflevel=0.95, ’mean=50);
MEAN TESTmean estimate = 54.3
conf level = 0.95conf interval = [42.50179070143281, 66.09820929856718]
method = Exactt − test.Unknownvariance.hypotheses = H0 : mean = 50,H1 : mean#50
statistic = 0.82447052350717distribution = [student t, 9]
p value = 0.43097991764262
Programacion Entera OPT GEST EMPR 18 / 31
Varianza: test variance(data, OPCIONES)
OPCIONES:
• ’mean= Por defecto ’unknown (Media poblacional, si conocida).
• alternative: ’twosided, ’greater, ’less. (Hipotesis alternativa).
• ’variance: por defecto 1 (a contrastar).
• ’conflevel: Nivel de confianza (por defecto 0.95).
Devuelve:
• ’var estimate: Cuasi-varianza.
• ’conf level: Nivel de confianza.
• ’conf interval: I.C. para la varianza.
• ’method: Procedimiento usado.
• ’hypotheses: Constraste.
• ’statistic: Valor del estadıstico.
• ’distribution: Distribucion del estadıstico usado.
• ’p value: p-valor.
Programacion Entera OPT GEST EMPR 19 / 31
Varianza: test variance(data, OPCIONES)
datos: [203,229,215,220,223,233,208,228,209]$
test variance(datos);
VARIANCE TESTvar estimate = 110.75
conf level = 0.95conf interval = [50.52882423941885, 406.4722219093904]
method = VarianceChi − squaretest.Unknownmean.hypotheses = H0 : var = 1,H1 : var#1
statistic = 886.0000000000001distribution = [chi2, 8]
p value = 0.0
Programacion Entera OPT GEST EMPR 20 / 31
Proporcion: test proportion(x, n, OPCIONES)
x : elementos en la muestra con la carasterıstica a analizar-n: elementos en la muestra.OPCIONES:
• alternative: ’twosided, ’greater, ’less. (Hipotesis alternativa).
• ’conflevel: Nivel de confianza (por defecto 0.95).
Devuelve:
• ’proportiona: Lista de proporciones.
• ’conf level: Nivel de confianza.
• ’conf interval: I.C. para cociente de varianzas.
• ’method: Procedimiento usado.
• ’hypotheses: Constraste.
• ’statistic: Valor del estadıstico.
• ’distribution: Distribucion del estadıstico usado.
• ’p value: p-valor.
Programacion Entera OPT GEST EMPR 21 / 31
Proporcion: test proportion(x, n, OPCIONES)
test proportion(45, 103, alternative = less);
PROPORTION TESTsample proportion = 0.4368932038835
conf level = 0.95conf interval = [0, 0.52271414915023]
method = Exactbinomialtest.hypotheses = H0 : p = 0.5,H1 : p < 0.5
statistic = 45distribution = [binomial , 103, 0.5]
p value = 0.11845093889015
Programacion Entera OPT GEST EMPR 22 / 31
Dif. Prop.: test proportion difference(x1,n1,x2,n2,OPCIONES)
x1, x2 : elementos en cada muestra con la carasterıstica a analizar.n1, n2: elementos en cada muestra.OPCIONES:
• ’proportion= Proporcion a ser contrastada. (por defecto 0.5).
• alternative: ’twosided, ’greater, ’less. (Hipotesis alternativa).
• ’conflevel: Nivel de confianza (por defecto 0.95).
Devuelve:
• ’sample proportion: Proporcion en muestra.
• ’conf level: Nivel de confianza.
• ’conf interval: I.C. para cociente de varianzas.
• ’method: Procedimiento usado.
• ’hypotheses: Constraste.
• ’statistic: Valor del estadıstico.
• ’distribution: Distribucion del estadıstico usado.
• ’p value: p-valor.
Programacion Entera OPT GEST EMPR 23 / 31
Dif. de Medias: test mean(data1, data2, OPCIONES)
OPCIONES:
• alternative: ’twosided, ’greater, ’less. (Hipotesis alternativa).
• ’dev1: por defecto ’unknown (desviacion tıpica de la primera poblacion).
• ’dev2: por defecto ’unknown (desviacion tıpica de la segunda poblacion).
• ’varequal: por defecto false (solo si dev1 y dev2 son desconocidad).
• ’conflevel: Nivel de confianza (por defecto 0.95).
Devuelve:
• ’diff estimate: Diferencia de medias muestrales.
• ’conf level: Nivel de confianza.
• ’conf interval: I.C. para la diferencia de medias.
• ’method: Procedimiento usado.
• ’hypotheses: Constraste.
• ’statistic: Valor del estadıstico.
• ’distribution: Distribucion del estadıstico usado.
• ’p value: p-valor.
Programacion Entera OPT GEST EMPR 24 / 31
Dif. de Medias: test mean(data1, data2, OPCIONES)
data1: [20.4,62.5,61.3,44.2,11.1,23.7]$
data2: [1.2,6.9,38.7,20.4,17.2]$
test means difference(data1,data2);
DIFFERENCE OF MEANS TESTdiff estimate = 20.31999999999999
conf level = 0.95conf interval = [−4.854739139651127, 45.49473913965112]
method = Exactt − test.Welchapprox .hypotheses = H0 : mean1 = mean2,H1 : mean1#mean2
statistic = 1.838004300728477distribution = [student t, 8.627587401846039]
p value = 0.10065493055984
Programacion Entera OPT GEST EMPR 25 / 31
Coc. de var: test variance ratio(data1, data2, OPCIONES)
OPCIONES:
• ’mean1= Por defecto ’unknown (Media poblacional 1, si conocida).
• ’mean2= Por defecto ’unknown (Media poblacional 2, si conocida).
• alternative: ’twosided, ’greater, ’less. (Hipotesis alternativa).
• ’conflevel: Nivel de confianza (por defecto 0.95).
Devuelve:
• ’ratio estimate: Cociente de cuasivarianzas.
• ’conf level: Nivel de confianza.
• ’conf interval: I.C. para cociente de varianzas.
• ’method: Procedimiento usado.
• ’hypotheses: Constraste.
• ’statistic: Valor del estadıstico.
• ’distribution: Distribucion del estadıstico usado.
• ’p value: p-valor.
Programacion Entera OPT GEST EMPR 26 / 31
Coc. de var: test variance ratio(data1, data2, OPCIONES)
x: [20.4,62.5,61.3,44.2,11.1,23.7]$
y: [1.2,6.9,38.7,20.4,17.2]$
test variance ratio(x,y);
VARIANCE RATIO TESTratio estimate = 2.316933391522034
conf level = 0.95conf interval = [0.24741743950027, 17.11723918986183]
method = VarianceratioF − test.Unknownmeans.hypotheses = H0 : var1 = var2,H1 : var1#var2
statistic = 2.316933391522034distribution = [f , 5, 4]
p value = 0.43585393845089
Programacion Entera OPT GEST EMPR 27 / 31
Dif. Prop.: test proportion difference(x1,n1,x2,n2,OPCIONES)
test proportions difference(10, 250, 4, 150,alternative = greater);
DIFFERENCE OF PROPORTIONS TESTproportions = [0.04, 0.026666666666667]
conf level = 0.95conf interval = [−0.021727608336707, 1]
method = Asymptotictest.Yatescorrection.hypotheses = H0 : p1 = p2,H1 : p1 > p2
statistic = 0.013333333333333distribution = [normal , 0, 0.018980691943832]
p value = 0.241193599641
Programacion Entera OPT GEST EMPR 28 / 31
Test de Normalidad: test normality(x)
Tests de Shapiro-Wilks de Normalidad (para menos de 5000 datos).Devuelve:
• ’statistic: Valor del estadıstico: W.
• ’p value: p-valor para asuncion de normalidad.
Programacion Entera OPT GEST EMPR 29 / 31
Test de Normalidad: test normality(x)
x:[12,15,17,38,42,10,23,35,28]$
test normality(x);
SHAPIRO − WILKTESTstatistic = 0.92510556951624p value = 0.43617639188604
Programacion Entera OPT GEST EMPR 30 / 31