Visualização
Peso cerebral
Usando o conjunto de dados msleep
, construa um histograma da variável brainwt
. Escolha o número de classes que você achar melhor. O que acontece com os valores NA
?
Horas de sono \(\times\) peso cerebral
Usando o conjunto de dados msleep
, construa um scatter plot de horas de sono versus peso cerebral. Você percebe alguma correlação entre estas variáveis? Se precisar, concentre-se em um subconjunto dos dados.
Medidas
Valor médio e desvio padrão de lançamentos de um dado
Simule 10 mil lançamentos de um dado não-viciado.
Calcule a média dos valores obtidos.
Faça um gráfico (como o do primeiro vídeo sobre probabilidades) do valor médio em função do número do lançamento (i.e., considerando todos os lançamentos anteriores).
Valores discrepantes
Escreva uma função que receba um vetor numérico e retorne um vetor contendo os outliers segundo a definição usada para construir boxplots.
Escreva uma função que receba um vetor numérico e retorne um vetor contendo os valores que estão a 2 ou mais desvios padrão de distância da média.
Ache um exemplo de vetor numérico que faça as duas funções retornar o mesmo resultado.
Denominador \(n - 1\) na variância amostral
populacao <- c(1, 4, 10, 15)
Calcule a variância populacional, usando a sua função varpop
.
Carregue o pacote RcppAlgos
. Instale-o se necessário.
Gere todos os arranjos possíveis de 3 elementos desta população, com reposição. Use a função permuteGeneral
. O resultado vai ser uma matriz com 64 linhas. Cada linha corresponde a uma amostra.
(Variâncias amostrais com denominador \(n\)) Para cada amostra, calcule a variância usando a sua função varpop
, guardando os resultados em um vetor. Use a função apply
, do R base.
Quantas destas variâncias são menores ou iguais à variância da população inteira? Quantas são maiores?
Calcule a média das variâncias obtidas. O resultado é maior ou menor do que a variância populacional? Usar \(n\) no denominador da variância amostral superestima ou subestima a variância da população?
(Variâncias amostrais com denominador \(n - 1\)) Agora, para cada amostra, calcule a variância amostral (com \(n-1\) no denominador), guardando os resultados em outro vetor. Use a função apply
, do R base.
Quantas destas variâncias são menores ou iguais à variância da população inteira? Quantas são maiores?
Calcule a média das variâncias obtidas. O resultado é maior ou menor do que a variância populacional?
Probabilidades
Titanic
Qual a probabilidade de um tripulante sobreviver?
Qual a probabilidade de um sobrevivente ser tripulante?
Qual a probabilidade de um não-tripulante sobreviver?
Qual a probabilidade de um sobrevivente não ser tripulante?
Pôquer
Uma mão de pôquer consiste de 5 cartas retiradas ao acaso de um baralho de 32 cartas (4 naipes, cada um com cartas 7, 8, 9, 10, J, Q, K, A).
Calcule as seguintes probabilidades teoricamente e através de simulações.
Qual a probabilidade de obter uma mão sem ases?
Qual a probabilidade de obter 4 ases?
Qual a probabilidade de obter uma sequência (7 a J, 8 a Q, 9 a K, ou 10 a A) de naipes quaisquer?
Qual a probabilidade de obter uma sequência (7 a J, 8 a Q, 9 a K, ou 10 a A) do mesmo naipe?
Dados
Calcule as seguintes probabilidades teoricamente e através de simulações.
Você lança um dado não-viciado 6 vezes. Qual a probabilidade de que saiam os 6 números?
Idem, se você lançar o dado 10 vezes.
Repita os 2 itens acima, para um dado viciado, no qual \[
P(1) = \frac{1}{12}, \quad P(2) = P(3) = P(4) = P(5) = \frac{1}{6}, \quad P(6) = \frac{3}{12}
\]
LS0tCnRpdGxlOiAnTGlzdGEgMScKc3VidGl0bGU6ICdQcm9iYWJpbGlkYWRlIGUgRXN0YXTDrXN0aWNhIC0tIDIwMjAuMScKYXV0aG9yOiAnZm5hdWZlbCcKZW1haWw6ICdodHRwczovL2ZuYXVmZWwuZ2l0aHViLmlvLycKZGF0ZTogJzE4LzEwLzIwMjA8YnIgLz4obW9kaWZpY2FkbyBlbSBgciBmb3JtYXQoU3lzLkRhdGUoKSwgIiVkLyVtLyVZIilgKScKbGFuZzogJ3B0JwpvdXRwdXQ6IHJtZGZvcm1hdDo6Zm5hdWZlbF9ybWRfZm9ybWF0CiMgVG8gaW5zdGFsbCB0aGlzIGZvcm1hdCwgZW50ZXIKIyAgIGluc3RhbGwucGFja2FnZXMoImRldnRvb2xzIikKIyAgIGRldnRvb2xzOjppbnN0YWxsX2dpdGh1YigiZm5hdWZlbC9ybWRmb3JtYXQiKQotLS0KCmBgYHtyIHNldHVwLCBpbmNsdWRlPUZBTFNFfQpsaWJyYXJ5KGtuaXRy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