A New Output Format
html_pretty in the prettydoc package is a new output format for creating HTML documents from R Markdown files. html_pretty is more lightweight compared to html_document, and is more stylish than html_vignette when creating package vignettes.
\[ f(x) = \int_a^b g(x) = G(b) - G(a) \] ## New Styles
library(tidyverse)## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.7
## v tidyr 1.1.4 v stringr 1.4.0
## v readr 2.1.1 v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.0.5
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'readr' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
# Uniforme com a = 0, b = 100
mean_function <- function(x) {
mean(runif(x, 0, 100))
}
mean_function(10)## [1] 50.06874
S1_function <- function(x){
amostra <- runif(x, 0, 100)
sum((amostra - mean(amostra))^2)/(x-1)
}
S2_function <- function(x){
amostra <- runif(x, 0, 100)
sum((amostra - mean(amostra))^2)/(x)
}
R = 10000
base <- tibble(
S1_N1 = replicate(R, {S1_function(20)}),
S1_N2 = replicate(R, {S1_function(400)}),
S2_N1 = replicate(R, {S2_function(20)}),
S2_N2 = replicate(R, {S2_function(400)}))
base## # A tibble: 10,000 x 4
## S1_N1 S1_N2 S2_N1 S2_N2
## <dbl> <dbl> <dbl> <dbl>
## 1 927. 810. 755. 899.
## 2 917. 746. 927. 862.
## 3 647. 787. 825. 788.
## 4 527. 880. 877. 867.
## 5 1244. 821. 890. 809.
## 6 752. 819. 732. 776.
## 7 1292. 850. 518. 788.
## 8 838. 863. 744. 759.
## 9 656. 876. 891. 886.
## 10 797. 818. 817. 758.
## # ... with 9,990 more rows
#pivot_longer(base, S1_N1:S2_N2, names_to = "Var", values_to = "Val")
estimativas <-
base %>%
pivot_longer(S1_N1:S2_N2, names_to = "Var", values_to = "Val") %>%
separate(Var, into = c("Estimador", "Amostra")) %>%
group_by(Estimador, Amostra) %>%
summarise(Média = mean(Val), Varância = sd(Val))## `summarise()` has grouped output by 'Estimador'. You can override using the `.groups` argument.
base %>%
pivot_longer(S1_N1:S2_N2, names_to = "Var", values_to = "Val") %>%
separate(Var, into = c("Estimador", "Amostra")) %>%
ggplot() +
geom_density(aes(x = Val, y = ..density..,
color = Estimador,
fill = Estimador), alpha = .5) +
facet_wrap(~ Amostra) +
geom_vline(aes(xintercept = Média, color = Estimador), size = 1, data = estimativas) +
geom_vline(xintercept = 833.3, color = "black", size = .5)