8.5 Capítulo 5
Solução. 5.15
# b.
# função triangular inversa
Finv <- function(u,a,m,b){
m0 <- (m-a)/(b-a)
f <- vector(length = length(u))
fltr <- u <= m0
f[fltr] <- a + sqrt(u[fltr]*(m-a)*(b-a))
f[!fltr] <- b - sqrt((1-u[!fltr])*(b-m)*(b-a))
return(f)
}
# simulando via Finv
set.seed(42)
u <- runif(5000)
sim1 <- Finv(u,0,.6,1)
hist(sim1, 40, freq = FALSE, main = 'Tri(0,0.6,1)')
curve(extraDistr::dtriang(x, a=0, b=1, c=0.6), col = 'red', add = TRUE)
# simulando via extraDistr::rtriang()
set.seed(420)
sim2 <- extraDistr::rtriang(5000, a=0, b=1, c=0.6)
# c.
# comparando sim1 e sim2
plot(ecdf(sim1))
plot(ecdf(sim2), add = TRUE, col = 'red')
##
## Asymptotic two-sample Kolmogorov-Smirnov test
##
## data: sim1 and sim2
## D = 0.0122, p-value = 0.8508
## alternative hypothesis: two-sided
## [1] 0.7684
# P(X>0.37) via probabilidade teórica
Fx <- function(x,a,m,b){
if(x <= m){
f <- (x-a)^2/((b-a)*(m-a))
} else{
f <- 1 - (b-x)^2/((b-a)*(b-m))
}
return(f)
}
1-Fx(0.37,0,0.6,1)
## [1] 0.7718333
## [1] 0.7718333
## [1] 0.7718333
Solução. 5.16
- \(F^{-1}(u) = \sqrt{-2 \sigma^2 \log(1-u)}\)
# b.
# simulando via Finv
Finv <- function(x,sigma){
return(sqrt(-2*sigma^2*log(1-x)))
}
set.seed(42)
u <- runif(5000)
sim1 <- Finv(u,1)
hist(sim1, 40, freq = FALSE, main = 'Rayleigh(1)')
curve(extraDistr::drayleigh(x, sigma=1), col = 'red', add = TRUE)
# simulando via extraDistr::rrayleigh()
set.seed(420)
sim2 <- extraDistr::rrayleigh(5000, sigma=1)
# c.
# comparando sim1 e sim2
plot(ecdf(sim1))
plot(ecdf(sim2), add = TRUE, col = 'red')
##
## Asymptotic two-sample Kolmogorov-Smirnov test
##
## data: sim1 and sim2
## D = 0.016, p-value = 0.5441
## alternative hypothesis: two-sided
## [1] 0.1172
# P(X<0.5) via probabilidade teórica
Fx <- function(x,sigma){
return(1-exp(-x^2/(2*sigma^2)))
}
Fx(0.5,1)
## [1] 0.1175031
## [1] 0.1175031
Solução. 5.28
- https://en.wiktionary.org/wiki/hypothesis
- https://en.wiktionary.org/wiki/%E1%BD%91%CF%80%CF%8C%CE%B8%CE%B5%CF%83%CE%B9%CF%82
- Hypothesis, subs. Assumption: P. ὑπόθεσις , ἦ, θέσις, ἦ. (Woodhouse 1910, 412)
References
Woodhouse, Sidney Chawner. 1910. English-Greek dictionary: a vocabulary of the attic language. G. Routledge & Sons, limited. https://archive.org/details/in.ernet.dli.2015.31421/page/n425/mode/2up.