generated from curso-r/template-pagina-do-curso
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,087 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--- | ||
title: "Lista 2" | ||
author: "Fernando" | ||
date: "2024-02-28" | ||
output: pdf_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = FALSE) | ||
``` | ||
|
||
# Exercício 1) | ||
|
||
Usando `x` definido abaixo calcule (no R ou não): | ||
|
||
```{r} | ||
x <- c( | ||
-1.38, -0.82, -0.1, | ||
-1.46, 0.4, -0.76, | ||
0.7, -1.26, 0.9, -1.15 | ||
) | ||
``` | ||
|
||
## a) A média | ||
|
||
## b) A amplitude | ||
|
||
## c) O desvio absoluto médio | ||
|
||
# Exercício 2) | ||
|
||
## a) | ||
|
||
A partir do `x` do exercício 1, calcule a média de `y1 <- x+1` | ||
|
||
## b) | ||
|
||
A partir do `x` do exercício 1, calcule a média de `y2 <- 2*x` | ||
|
||
## c) | ||
|
||
A partir do `x` do exercício 1, calcule a média de `y3 <- 2*x+1` | ||
|
||
|
||
## EXTRA | ||
|
||
Considere que existe uma $x_1, x_2, ..., x_n$, mas não vamos definir explicitamente o valor delas. Se $y_i = a\times x_i+b$, encontre uma fórmula para $\bar{y}$ que depende apenas de $a$, $b$ e $\bar{x}$ | ||
|
||
# Exercíco 3 | ||
|
||
Para avaliar se um remédio novo é capaz de reduzir os sintomas de gripe em 2 dias, um hospital quer que alguns de seus pacientes sejam tratados com o remédio. Como é um remédio novo e caro, o hospital gostaria de garantir que o remédio não está sendo oferecido de propósito a nenhum paciente. Sendo assim ele propõe o seguinte procedimento para observação de uma amostra: | ||
|
||
1. Pacientes que chegam no plantão com sintomas gripais são encaminhados para o cientista. | ||
|
||
2. O cientista joga um dado de 6 faces para decidir se o paciente receberá placebo ou o remédio. Se o dado der mais 4 ou mais, o paciente recebe o remédio, se não recebe placebo. | ||
|
||
3. Após 2 dias, o paciente retorna ao hospital para verificar se ainda apresenta sintomas gripais. | ||
|
||
**Com base nessa história, construa uma proposta de diagrama que represente o mecanismo de geração dessa amostra** | ||
|
||
# Exercício 4 | ||
|
||
A tabela `20_lancamentos_de_moeda.xlsx` registra em cada linha 1000 simulações de 20 lançamentos de u ma moeda honesta. Considerando que observamos a amostra abaixo, proponha duas comparações entre a amostra e as 1000 simulações e decida se elas são compatíveis. | ||
|
||
``` | ||
amostra <- c(1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, | ||
1, 1, 1, 0, 0) | ||
``` | ||
|
||
**Sugestão**: | ||
|
||
1. Escolha uma estatística, como por exemplo "contagem de `1`s". | ||
|
||
2. Calcule-a para todas 1000 amostra de 20 lançamentos simuladas na planilha. | ||
|
||
3. Caracterize a variabilidade dessa estatística. | ||
|
||
4. Calcule a estatística em `Amostra` | ||
|
||
5. Compare o valor calculado com a variabilidade avaliada em 3. | ||
|
||
|
||
|
||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
\relax | ||
\providecommand\hyper@newdestlabel[2]{} | ||
\providecommand\HyField@AuxAddToFields[1]{} | ||
\providecommand\HyField@AuxAddToCoFields[2]{} | ||
\providecommand\BKM@entry[2]{} | ||
\BKM@entry{id=1,dest={73656374696F6E2A2E31},srcline={77}}{5C3337365C3337375C303030455C303030785C303030655C303030725C303030635C3030305C3335355C303030635C303030695C3030306F5C3030305C3034305C303030315C3030305C303531} | ||
\BKM@entry{id=2,dest={73656374696F6E2A2E32},srcline={82}}{5C3337365C3337375C303030615C3030305C3035315C3030305C3034305C303030415C3030305C3034305C3030306D5C3030305C3335315C303030645C303030695C30303061} | ||
\BKM@entry{id=3,dest={73656374696F6E2A2E33},srcline={85}}{5C3337365C3337375C303030625C3030305C3035315C3030305C3034305C303030415C3030305C3034305C303030615C3030306D5C303030705C3030306C5C303030695C303030745C303030755C303030645C30303065} | ||
\BKM@entry{id=4,dest={73656374696F6E2A2E34},srcline={89}}{5C3337365C3337375C303030635C3030305C3035315C3030305C3034305C3030304F5C3030305C3034305C303030645C303030655C303030735C303030765C303030695C3030306F5C3030305C3034305C303030615C303030625C303030735C3030306F5C3030306C5C303030755C303030745C3030306F5C3030305C3034305C3030306D5C3030305C3335315C303030645C303030695C3030306F} | ||
\BKM@entry{id=5,dest={73656374696F6E2A2E35},srcline={92}}{5C3337365C3337375C303030455C303030785C303030655C303030725C303030635C3030305C3335355C303030635C303030695C3030306F5C3030305C3034305C303030325C3030305C303531} | ||
\BKM@entry{id=6,dest={73656374696F6E2A2E36},srcline={95}}{5C3337365C3337375C303030615C3030305C303531} | ||
\BKM@entry{id=7,dest={73656374696F6E2A2E37},srcline={101}}{5C3337365C3337375C303030625C3030305C303531} | ||
\BKM@entry{id=8,dest={73656374696F6E2A2E38},srcline={107}}{5C3337365C3337375C303030635C3030305C303531} | ||
\BKM@entry{id=9,dest={73656374696F6E2A2E39},srcline={113}}{5C3337365C3337375C303030455C303030585C303030545C303030525C30303041} | ||
\BKM@entry{id=10,dest={73656374696F6E2A2E3130},srcline={121}}{5C3337365C3337375C303030455C303030785C303030655C303030725C303030635C3030305C3335355C303030635C3030306F5C3030305C3034305C30303033} | ||
\@writefile{toc}{\contentsline {section}{Exercício 1)}{1}{section*.1}\protected@file@percent } | ||
\newlabel{exercuxedcio-1}{{}{1}{Exercício 1)}{section*.1}{}} | ||
\@writefile{toc}{\contentsline {subsection}{a) A média}{1}{section*.2}\protected@file@percent } | ||
\newlabel{a-a-muxe9dia}{{}{1}{a) A média}{section*.2}{}} | ||
\@writefile{toc}{\contentsline {subsection}{b) A amplitude}{1}{section*.3}\protected@file@percent } | ||
\newlabel{b-a-amplitude}{{}{1}{b) A amplitude}{section*.3}{}} | ||
\@writefile{toc}{\contentsline {subsection}{c) O desvio absoluto médio}{1}{section*.4}\protected@file@percent } | ||
\newlabel{c-o-desvio-absoluto-muxe9dio}{{}{1}{c) O desvio absoluto médio}{section*.4}{}} | ||
\@writefile{toc}{\contentsline {section}{Exercício 2)}{1}{section*.5}\protected@file@percent } | ||
\newlabel{exercuxedcio-2}{{}{1}{Exercício 2)}{section*.5}{}} | ||
\@writefile{toc}{\contentsline {subsection}{a)}{1}{section*.6}\protected@file@percent } | ||
\newlabel{a}{{}{1}{a)}{section*.6}{}} | ||
\@writefile{toc}{\contentsline {subsection}{b)}{1}{section*.7}\protected@file@percent } | ||
\newlabel{b}{{}{1}{b)}{section*.7}{}} | ||
\@writefile{toc}{\contentsline {subsection}{c)}{1}{section*.8}\protected@file@percent } | ||
\newlabel{c}{{}{1}{c)}{section*.8}{}} | ||
\@writefile{toc}{\contentsline {subsection}{EXTRA}{1}{section*.9}\protected@file@percent } | ||
\newlabel{extra}{{}{1}{EXTRA}{section*.9}{}} | ||
\@writefile{toc}{\contentsline {section}{Exercíco 3}{1}{section*.10}\protected@file@percent } | ||
\newlabel{exercuxedco-3}{{}{1}{Exercíco 3}{section*.10}{}} | ||
\BKM@entry{id=11,dest={73656374696F6E2A2E3131},srcline={148}}{5C3337365C3337375C303030455C303030785C303030655C303030725C303030635C3030305C3335355C303030635C303030695C3030306F5C3030305C3034305C30303034} | ||
\@writefile{toc}{\contentsline {section}{Exercício 4}{2}{section*.11}\protected@file@percent } | ||
\newlabel{exercuxedcio-4}{{}{2}{Exercício 4}{section*.11}{}} | ||
\gdef \@abspage@last{2} |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Pacotes ----------------------------------------------------------------- | ||
|
||
library(tidyverse) | ||
library(purrr) | ||
|
||
# Simulacao no R ---------------------------------------------------------- | ||
|
||
# Dados ------------------------------------------------------------------- | ||
|
||
numero_de_simulacoes <- 10000 | ||
espaco_amostral <- 1:6 | ||
tamanho_da_amostra <- 100 | ||
|
||
amostras <- map(1:numero_de_simulacoes, | ||
sample, | ||
x = espaco_amostral, | ||
size = tamanho_da_amostra) | ||
|
||
medias <- map_dbl(amostras, mean) | ||
|
||
tabela <- tibble(medias) | ||
|
||
tabela |> | ||
ggplot(aes(x = medias)) + | ||
geom_histogram( | ||
fill = 'royalblue', color = 'white', | ||
bins = floor(numero_de_simulacoes^(1/3)) | ||
) + | ||
theme_bw(15) + | ||
labs(x = "Médias", y = "Contagem") | ||
|
||
# Dados + Normal ---------------------------------------------------------- | ||
|
||
tabela |> | ||
ggplot(aes(x = medias, after_stat(density))) + | ||
geom_histogram( | ||
fill = 'royalblue', color = 'white', | ||
bins = floor(numero_de_simulacoes^(1/3)) | ||
) + | ||
theme_bw(15) + | ||
labs(x = "Médias", y = "Densidade") | ||
|
||
media <- mean(medias) | ||
sd <- sd(medias) | ||
|
||
tabela |> | ||
mutate( | ||
normal = dnorm(medias, media, sd) | ||
) |> | ||
ggplot(aes(x = medias, after_stat(density))) + | ||
geom_histogram( | ||
fill = 'royalblue', color = 'white', | ||
bins = floor(numero_de_simulacoes^(1/3)) | ||
) + | ||
theme_bw(15) + | ||
geom_line(aes(x = medias, y = normal), | ||
color = 'red', size = 3) + | ||
labs(x = "Médias", y = "Densidade") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
# Pacote ------------------------------------------------------------------ | ||
|
||
library(tidyverse) | ||
library(readxl) | ||
|
||
# populacoes -------------------------------------------------------------- | ||
|
||
pop1 <- read_excel("populacao1.xlsx") | ||
pop2 <- read_excel("populacao2.xlsx") | ||
pop3 <- read_excel("populacao3.xlsx") | ||
|
||
# Distribuição populacional da pop1 --------------------------------------- | ||
|
||
hist(pop1$altura) | ||
|
||
# Minha Amostra ----------------------------------------------------------- | ||
|
||
n <- 5000 | ||
|
||
minha_amostra <- sample(x = pop1$altura, size = n, replace = FALSE) | ||
|
||
hist(minha_amostra) | ||
|
||
|
||
# Outras amostras possíveis ----------------------------------------------- | ||
|
||
numero_de_simulacoes <- 10000 | ||
|
||
amostras <- map( | ||
1:numero_de_simulacoes, | ||
function(x){ | ||
sample( | ||
x = pop1$altura, | ||
size = n, | ||
replace = FALSE | ||
) | ||
} | ||
) | ||
|
||
medias_amostrais <- amostras |> | ||
map_dbl(mean) | ||
|
||
hist(medias_amostrais) | ||
|
||
|
||
# Minha amostra pop 2 ----------------------------------------------------- | ||
|
||
n <- 5000 | ||
|
||
minha_amostra2 <- sample(x = pop2$altura, size = n, replace = TRUE) | ||
|
||
hist(minha_amostra2) | ||
hist(pop2$altura) | ||
|
||
|
||
# amostral pop2 ----------------------------------------------------------- | ||
|
||
numero_de_simulacoes <- 10000 | ||
|
||
amostras_pop2 <- map( | ||
1:numero_de_simulacoes, | ||
function(x){ | ||
sample( | ||
x = pop2$altura, | ||
size = n, | ||
replace = TRUE | ||
) | ||
} | ||
) | ||
|
||
medias_amostrais_pop2 <- amostras_pop2 |> | ||
map_dbl(mean) | ||
|
||
hist(medias_amostrais_pop2) | ||
|
||
# Minha amostra pop 3 ----------------------------------------------------- | ||
|
||
n <- 5000 | ||
|
||
minha_amostra3 <- sample(x = pop3$altura, size = n, replace = TRUE) | ||
|
||
hist(minha_amostra3) | ||
|
||
|
||
# amostral pop3 ----------------------------------------------------------- | ||
|
||
numero_de_simulacoes <- 10000 | ||
|
||
amostras_pop3 <- map( | ||
1:numero_de_simulacoes, | ||
function(x){ | ||
sample( | ||
x = pop3$altura, | ||
size = n, | ||
replace = TRUE | ||
) | ||
} | ||
) | ||
|
||
medias_amostrais_pop3 <- amostras_pop3 |> | ||
map_dbl(mean) | ||
|
||
hist(medias_amostrais_pop3) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
hist(sort(medias_amostrais), probability = TRUE) | ||
|
||
media_populacional <- mean(pop1$altura) | ||
desv_pad <- sd(pop1$altura) | ||
|
||
lines( | ||
sort(medias_amostrais), | ||
dnorm( | ||
sort(medias_amostrais), | ||
mean = media_populacional, | ||
sd = desv_pad/sqrt(n) | ||
), col = 'red' | ||
) | ||
|
||
|
||
# Vida real --------------------------------------------------------------- | ||
|
||
plot(type = 'l', | ||
sort(medias_amostrais), | ||
dnorm( | ||
sort(medias_amostrais), | ||
mean = mean(minha_amostra), | ||
# POSSO COLOCAR O AMOSTRAL! | ||
sd = sd(minha_amostra)/sqrt(n) | ||
# O AMOSTRAL! | ||
), | ||
col = 'blue' | ||
) | ||
|
||
|
||
# população 2 ------------------------------------------------------------- | ||
|
||
n <- 5000 | ||
|
||
minha_amostra2 <- sample(x = pop2$altura, size = n, replace = TRUE) | ||
|
||
plot(type = 'l', | ||
seq(1.84, 1.86, 0.0001), | ||
dnorm( | ||
seq(1.84, 1.86, 0.0001), | ||
mean = mean(minha_amostra2), | ||
# POSSO COLOCAR O AMOSTRAL! | ||
sd = sd(minha_amostra2)/sqrt(n) | ||
# O AMOSTRAL! | ||
), | ||
col = 'purple' | ||
) | ||
|
||
lines(type = 'l', | ||
seq(1.84, 1.86, 0.0001), | ||
dnorm( | ||
seq(1.84, 1.86, 0.0001), | ||
mean = mean(pop2$altura), | ||
# POSSO COLOCAR O AMOSTRAL! | ||
sd = sd(pop2$altura)/sqrt(n) | ||
# O AMOSTRAL! | ||
), | ||
col = 'red' | ||
) | ||
|
||
|
||
# pop3 -------------------------------------------------------------------- | ||
|
||
plot(type = 'l', | ||
seq(1.55, 1.56, 0.0001), | ||
dnorm( | ||
seq(1.55, 1.56, 0.0001), | ||
mean = mean(minha_amostra3), | ||
# POSSO COLOCAR O AMOSTRAL! | ||
sd = sd(minha_amostra3)/sqrt(n) | ||
), | ||
col = 'purple' | ||
) | ||
|
||
lines(type = 'l', | ||
seq(1.53, 1.57, 0.0001), | ||
dnorm( | ||
seq(1.53, 1.57, 0.0001), | ||
mean = mean(pop3$altura), | ||
# POSSO COLOCAR O AMOSTRAL! | ||
sd = sd(pop3$altura)/sqrt(n) | ||
), | ||
col = 'red' | ||
) |
Oops, something went wrong.