R Markdown

lambda <- 3
dias <- 150
poisson_sample <- rpois(dias, lambda)
mean(poisson_sample)
## [1] 2.726667
sd(poisson_sample)
## [1] 1.646215
mean2 <- 500
n2 <- 1000
exp_sample <- rexp(n2, rate = 1/mean2)
mean(exp_sample > 700)
## [1] 0.258
p_def <- 0.05
lotes <- 100
tam <- 50
binom_samples <- rbinom(lotes, size = tam, prob = p_def)
mean(binom_samples)
## [1] 2.68
mu4 <- 100
sd4 <- 15
n4 <- 365
norm_sample <- rnorm(n4, mean = mu4, sd = sd4)
mean(norm_sample > 130)
## [1] 0.02191781
hist(norm_sample, breaks=20, main="Demanda diaria (N(100,15^2))", xlab="Demanda (MW)")

beta <- 1000
n5 <- 1000
U <- runif(n5)
x5 <- -beta * log(U)  # transformada inversa
mean(x5); var(x5)     # muestral
## [1] 974.2477
## [1] 882198.1
# densidad teorica: dexp(x, rate = 1/beta)
hist(x5, breaks=40, probability=TRUE, main="Tiempos de vida (β=1000)", xlab="Horas")
xs <- seq(0, quantile(x5, 0.995), length.out=200)
lines(xs, dexp(xs, rate=1/beta))

mean(x5 < 940)
## [1] 0.611

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.

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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.