This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
\[ \bar{X} \pm z_\gamma\sqrt{\frac{\sigma^2}{n}} \] When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#### SimulaĂ§Ă£o ################################
# Entrada
Semente <- 123
N <- 1000
Gama <- .95
Média <- 10
VariĂ¢ncia <- 2
Tamanho <- 20
############################
library(tidyverse)
## ── Attaching packages ───────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.0 ✔ purrr 0.3.2
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 0.8.3 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ──────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
Saida <- tibble(
Ordem = numeric(N),
LimInferior = numeric(N),
LimSuperior = numeric(N),
Acerto = character(N),
FreqRelativa = numeric(N)
)
# z_Gamma
z_gama <- -qnorm(p = (1 - Gama)/2)
# Loop
set.seed(321)
for (i in 1:N) {
# Sorteio:
Amostra <- rnorm(n = Tamanho, mean = MĂ©dia, sd = sqrt(VariĂ¢ncia))
# CĂ¡lculo do intervalo
IC <- c(mean(Amostra) - z_gama*sqrt(VariĂ¢ncia/Tamanho),
mean(Amostra) + z_gama*sqrt(VariĂ¢ncia/Tamanho))
Saida$Ordem[i] <- i
Saida$LimInferior[i] <- IC[1]
Saida$LimSuperior[i] <- IC[2]
Saida$Acerto[i] <- ifelse((MĂ©dia >= IC[1])&&(MĂ©dia <= IC[2]), "Sim", "NĂ£o")
Saida$FreqRelativa[i] <- sum(Saida$Acerto[1:i] == "Sim")/i
}
You can also embed plots, for example:
## # A tibble: 2 x 2
## Acerto n
## <chr> <int>
## 1 NĂ£o 55
## 2 Sim 945
## # A tibble: 2 x 4
## Acerto Total Freq Prop
## <chr> <int> <dbl> <dbl>
## 1 NĂ£o 55 0.055 5.5
## 2 Sim 945 0.945 94.5
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.