## Considere la muestra
muestra = c(6, 8, 5.5, 4.5, 8.5, 4, 3.5)
n = length(muestra)
n
## [1] 7
Xbar = sum(muestra)/n
Xbar
## [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 del 90%]:
p = 1 - alpha
p
## [1] 0.9
## Solución {Referencia.- Elementary-Statistics-by-Bluman-8th-Edition-pp.
## 413 and 414]
# 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 = qnorm(alpha/2) ## Funcion q calcula valores criticos normalizdos
critical_values ## In both tails
## [1] -1.645
## Step 3 Compute the test value. z = (Xbar - mu)/(S/sqrt(n))
S = sqrt(var(muestra)) ## {Ya que var(X) calcula con 'n-1'}
S
## [1] 1.933
z = (Xbar - mu)/(S/sqrt(n))
z
## [1] -3.128
## Step 4 Make the decision: Reject the Hypotheses since the test value
## z=-3.12 falls into the critical region, as shown in next figure:
## Graphic - Normal distribution with shaded areas
par(mfrow = c(1, 1))
inicio = -5
Mean = 0 ## Mu or average value
final = +5
Sd = S ## Sigma or standard deviation
## Grafica de la Normal (base) [línea azul]
x = seq(inicio, final, 0.01)
y = dnorm(x)
plot(x, y, type = "l", col = "blue", xlab = "", ylab = "")
abline(v = 0, col = "red")
abline(v = -3.12, col = "red")
library(calibrate)
## Loading required package: MASS
textxy(-3.128, 0.03, labs = "Xbar = -3.12", cx = 0.7)
## Grafica del area sombreada [izquierda] de limInferior a l
limInferior = inicio
limSuperior = -1.64
x = seq(limInferior, limSuperior, 0.01)
y = dnorm(x)
polygon(c(limInferior, x, limSuperior), c(0, y, 0), col = "gray")
textxy(limSuperior, 0.02, labs = "-1.64", cx = 0.8)
## Grafica del area sombreada [derecha] de (otro) limInferior a l
limInferior = 1.64
limSuperior = 5
x = seq(limInferior, limSuperior, 0.01)
y = dnorm(x)
## curve(x-limSuperior,dnorm(x-limSuperior))
polygon(c(limInferior, x, limSuperior), c(0, y, 0), col = "gray")
textxy(limInferior, 0.02, labs = "1.64", cx = 0.8)