Skip to content
Snippets Groups Projects
Commit f0809682 authored by Walmes Marques Zeviani's avatar Walmes Marques Zeviani
Browse files

Adiciona script de distribuição amostral.

parent 6b0d6992
No related branches found
No related tags found
No related merge requests found
Pipeline #
#=======================================================================
# Distribuição amostral da amplitude.
n <- 5 # Tamanho da amostra.
sigma <- 1 # Desvio-padrão populacional
w <- replicate(1000, {
x <- rnorm(n = n, m = 0, sd = sigma)
r <- diff(range(x))/sigma
r/sigma
}
)
plot(density(w))
rug(w)
plot(ecdf(w))
rug(w)
mean(w)
sd(w)
curve(pnorm(x, mean = mean(w), sd = sd(w)), add = TRUE, col = 2)
#-----------------------------------------------------------------------
# Fazer para diferentes valores de n.
nvals <- c(2, 3, 4, 5, 7, 10, 15)
ww <- lapply(nvals,
function(n) {
replicate(1000, {
x <- rnorm(n = n, m = 0, sd = sigma)
r <- diff(range(x))/sigma
r/sigma
})
})
str(ww)
t(sapply(ww, length))
da <- data.frame(n = ordered(rep(nvals, sapply(ww, length))),
w = do.call(c, ww))
aggregate(w ~ n, data = da, FUN = function(x) c(mean(x), sd(x)))
library(latticeExtra)
densityplot(~w | n, data = da, n = 202, as.table = TRUE,
auto.key = list(corner = c(0.9, 0.1)),
panel = function(x, ...) {
panel.densityplot(x = x, ...)
panel.mathdensity(dmath = dnorm, col = "black",
args = list(mean = mean(x),
sd = sd(x)))
})
ecdfplot(~w | n, data = da, as.table = TRUE,
auto.key = list(corner = c(0.9, 0.1)),
panel = function(x, subscripts, ...) {
panel.ecdfplot(x, subscripts = subscripts, ...)
m <- mean(x)
s <- sd(x)
col <- "gray50"
panel.curve(pnorm(x, mean = m, sd = s), col = col)
panel.abline(v = m, lty = 2, col = col)
})
ecdfplot(~w, groups = n, data = da,
auto.key = list(corner = c(0.9, 0.1)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment