## Clase del 3 de octubre 2012 Dr Hernandez
## ---------------------------------- CORRREGIDO EL 17 DE OCTUBRE 2012
## Problema 1 Considere la muestra
muestra = c(6, 8, 5.5, 4.5, 8.5, 4, 3.5) ## n = 7
(n = length(muestra))
## [1] 7
(Xbar = sum(muestra)/n)
## [1] 5.714
## Con media hipotética
mu = 8 ## [media de la población] y con distribucion Normal
## Considere valor crítico 0.1
alpha = 0.1
## La pregunta que surge es: la muestra pertenece a una población con
## media 'mu' Con un grado de confianza '1 - alpha' ? [es decir con una
## probabilidad]:
(p = 1 - alpha)
## [1] 0.9
## Solution
## -------------------------------------------------------------------
## Step 1 State the hypotheses and identify the claim. Ho: Xbar = mu and
## H1: Xbar different from mu
## Step 2 Find the critical values. Since alpha = 0.1 and the test is a
## two-tailed test, the critical values are [-1.64 and +1.64]; alpha
## splits in alpha/2 to either side
(critical_values = qt(alpha/2, df = n - 1)) ## Funcion q calcula valores criticos normalizados
## [1] -1.943
## Considerar valores negativo y positivo
## Step 3 Compute the test value. t = (Xbar - mu)/(S/sqrt(n))
S = sqrt(var(muestra)) ## {Ya que var(X) calcula con 'n-1'}
## O bien:
(S = sd(muestra))
## [1] 1.933
(tm = (Xbar - mu)/(S/sqrt(n)))
## [1] -3.128
## Step 4 Make the decision: Reject the Hypotheses since the test value tm
## = -3.12 fall in the critical region, as shown in the figure at the
## bottom:
## --------------------------------------------------------------------------
## Grafica t distribution with shaded areas
inicio = -5
Mean = 0 ## Mu or average value
final = +5
Sd = S ## Sigma or standard deviation
## ---------------------------------------------------
par(mfrow = c(1, 1))
library(calibrate)
## Loading required package: MASS
## Grafica de la Normal (base)
x = seq(inicio, final, 0.01)
y = dt(x, df = n - 1)
plot(x, y, type = "l", col = "blue", xlab = "t-Distribution", ylab = "Density")
abline(v = 0, col = "red")
abline(v = -3.12, col = "red")
text(-3.12, 0.03, labels = "tm = -3.12", cex = 0.7, pos = 3)
## Grafica del area sombreada [izquierda] de limInferior a l
limInferior = inicio
limSuperior = -1.943
x = seq(limInferior, limSuperior, 0.01)
y = dt(x, df = n - 1)
polygon(c(limInferior, x, limSuperior), c(0, y, 0), col = "gray")
text(limSuperior, 0.02, labels = "-1.943", cex = 0.7, pos = 1)
## Grafica del area sombreada [derecha] de (otro) limInferior a l
limInferior = 1.943
limSuperior = 5
x = seq(limInferior, limSuperior, 0.01)
y = dt(x, df = n - 1)
## curve(x-limSuperior,dnorm(x-limSuperior))
polygon(c(limInferior, x, limSuperior), c(0, y, 0), col = "gray")
text(limInferior, 0.02, labels = "1.943", cex = 0.7, pos = 1)