library("ggplot2")
grafico_densidad = ggplot(data = data.frame(x = c(28, 38)), aes(x)) +
stat_function(fun = dnorm, n = 36, args = list(mean =33, sd = 2)) + ylab("") +
scale_y_continuous(breaks = NULL) + xlab("Remuneraciones") + ylab("Densidad") + ggtitle("Función de densidad (distribución normal)") + theme_bw() +
geom_vline(xintercept = 32.5,cex=1.2,colour ="darkred",linetype="longdash") + geom_text(aes(x=35, label="xbar", y=0.0), colour ="darkred",size=5) + geom_vline(xintercept =33,cex=1.2,colour ="coral3",linetype="longdash") + geom_text(aes(x=34, label="mu", y=0.00001), colour ="coral3",size=5)
grafico_densidad
#Datos
mu=33
sigma = 2
x_bar= 32.5
n=36
#Normalización
z = (x_bar-mu)/(sigma/sqrt(n))
#Confianza
alfa = 0.01
confianza = 1-alfa
z_alfa = qnorm(alfa/2)
z_alfa
## [1] -2.575829
library("BSDA")
## Loading required package: lattice
##
## Attaching package: 'BSDA'
## The following object is masked from 'package:datasets':
##
## Orange
set.seed(10)
datos = rnorm(n,x_bar,sigma)
z = z.test(x=datos,mu=mu,sigma.x=sigma,conf.level = confianza)
print(z)
##
## One-sample z-Test
##
## data: datos
## z = -3.8223, p-value = 0.0001322
## alternative hypothesis: true mean is not equal to 33
## 99 percent confidence interval:
## 30.86728 32.58450
## sample estimates:
## mean of x
## 31.72589
dnorm_limit <- function(x) {
y <- dnorm(x)
y[x < z_alfa | x > -z_alfa] <- NA
return(y)
}
grafico_densidad = ggplot(data.frame(x = c(-3, 3)), aes(x = x)) +
stat_function(fun = dnorm_limit, geom = "area", fill = "blue", alpha = 0.2) + stat_function(fun = dnorm) +
xlab("Remuneraciones") + ylab("Densidad") + ggtitle("Función de densidad") +
theme_bw() + geom_vline(xintercept = (x_bar-mu)/(sigma/sqrt(n)),cex=1.2,colour ="darkred") +
geom_text(aes(x=(x_bar-mu)/(sigma/sqrt(n))+0.2, label="z", y=0.0), colour ="darkred",size=10)
plot(grafico_densidad)
library("ggplot2")
grafico_densidad = ggplot(data = data.frame(x = c(5, 15)), aes(x)) +
stat_function(fun = dchisq, n = 101, args = list(x =15, df = 19)) + ylab("") +
scale_y_continuous(breaks = NULL) + xlab("Puntaje") + ylab("Densidad") + ggtitle("Función de densidad") + theme_bw() +
geom_vline(xintercept = 32,cex=1.2,colour ="darkred") + geom_text(aes(x=31, label="S^2", y=0.0), colour ="darkred",size=5)
grafico_densidad
#### chi alfa es [-42.55697, 42.55697]
#Datos
sigma2=10
n = 30
s2=32
#Normalización
chi = (n-1)*s2/(sigma2)
chi
## [1] 92.8
#Confianza
alfa = 0.05
confianza = 1-(alfa/2)
chi_alfa = qchisq(alfa,df = n-1,lower.tail = F)
chi_alfa
## [1] 42.55697
library("EnvStats")
##
## Attaching package: 'EnvStats'
## The following objects are masked from 'package:stats':
##
## predict, predict.lm
## The following object is masked from 'package:base':
##
## print.default
set.seed(10)
datos=rnorm(20,sqrt(s2),n=n)
chi = varTest(datos,sigma.squared=sigma2,alternative="greater")
print(chi)
##
## Results of Hypothesis Test
## --------------------------
##
## Null Hypothesis: variance = 10
##
## Alternative Hypothesis: True variance is greater than 10
##
## Test Name: Chi-Squared Test on Variance
##
## Estimated Parameter(s): variance = 24.04624
##
## Data: datos
##
## Test Statistic: Chi-Squared = 69.73409
##
## Test Statistic Parameter: df = 29
##
## P-value: 3.296843e-05
##
## 95% Confidence Interval: LCL = 16.38606
## UCL = Inf
x = 30
n = 45
h = 0.40
prop.test(x, n, p = h, alt="greater", correct =FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: x out of n, null probability h
## X-squared = 13.333, df = 1, p-value = 0.0001304
## alternative hypothesis: true p is greater than 0.4
## 95 percent confidence interval:
## 0.5445542 1.0000000
## sample estimates:
## p
## 0.6666667
df= data.frame(
"alumnos" = c("juan", "pedro", "miguel", "alonso", "nicolas", "jose", "andrea", "javiera", "estefania", "nicol"),
"asistencia" = c(80.7, 97.2, 83.1, 86.9, 67.1, 90, 92.1, 78.4, 85.2, 94.8)
)
df
## alumnos asistencia
## 1 juan 80.7
## 2 pedro 97.2
## 3 miguel 83.1
## 4 alonso 86.9
## 5 nicolas 67.1
## 6 jose 90.0
## 7 andrea 92.1
## 8 javiera 78.4
## 9 estefania 85.2
## 10 nicol 94.8
wilcox.test(df$asistencia, mu = 85, conf.int = 1-0.05)
## Warning in wilcox.test.default(df$asistencia, mu = 85, conf.int = 1 - 0.05):
## cannot compute exact p-value with ties
## Warning in wilcox.test.default(df$asistencia, mu = 85, conf.int = 1 - 0.05):
## cannot compute exact confidence interval with ties
##
## Wilcoxon signed rank test with continuity correction
##
## data: df$asistencia
## V = 32.5, p-value = 0.6462
## alternative hypothesis: true location is not equal to 85
## 95 percent confidence interval:
## 78.55009 92.09996
## sample estimates:
## (pseudo)median
## 86.40008