{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercices" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "options(repr.matrix.max.cols=8, repr.matrix.max.rows=5)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "library(dplyr, warn.conflicts = F)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "path<-\"https://raw.githubusercontent.com/nmeraihi/data/master/\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Importer les données `qc_hommes_2.csv` à partir du répertoire [data github](https://github.com/nmeraihi/data) dans un _data frame_ df" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
agelx
0 an 100000
1 an 99501
2 ans 99483
4 ans99454
5 ans99442
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " age & lx\\\\\n", "\\hline\n", "\t 0 an & 100000\\\\\n", "\t 1 an & 99501\\\\\n", "\t 2 ans & 99483\\\\\n", "\t ⋮ & ⋮\\\\\n", "\t 4 ans & 99454\\\\\n", "\t 5 ans & 99442\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "age | lx | \n", "|---|---|---|---|---|---|\n", "| 0 an | 100000 | \n", "| 1 an | 99501 | \n", "| 2 ans | 99483 | \n", "| ⋮ | ⋮ | \n", "| 4 ans | 99454 | \n", "| 5 ans | 99442 | \n", "\n", "\n" ], "text/plain": [ " age lx \n", "1 0 an 100000\n", "2 1 an 99501\n", "3 2 ans 99483\n", "⋮ ⋮ ⋮ \n", "5 4 ans 99454 \n", "6 5 ans 99442 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(df)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
agelx
106105 ans96
107106 ans51
108107 ans26
110109 ans 6
111110 ans et plus3
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " & age & lx\\\\\n", "\\hline\n", "\t106 & 105 ans & 96 \\\\\n", "\t107 & 106 ans & 51 \\\\\n", "\t108 & 107 ans & 26 \\\\\n", "\t⋮ & ⋮ & ⋮\\\\\n", "\t110 & 109 ans & 6 \\\\\n", "\t111 & 110 ans et plus & 3 \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | age | lx | \n", "|---|---|---|---|---|---|\n", "| 106 | 105 ans | 96 | \n", "| 107 | 106 ans | 51 | \n", "| 108 | 107 ans | 26 | \n", "| ⋮ | ⋮ | ⋮ | \n", "| 110 | 109 ans | 6 | \n", "| 111 | 110 ans et plus | 3 | \n", "\n", "\n" ], "text/plain": [ " age lx\n", "106 105 ans 96\n", "107 106 ans 51\n", "108 107 ans 26\n", "⋮ ⋮ ⋮ \n", "110 109 ans 6 \n", "111 110 ans et plus 3 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tail(df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Dans la colonne `age`, garder seulement la partite numérique. Vous devriez alors obtenir age={0,1,2 ...}" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
agelx
0 100000
1 99501
2 99483
4 99454
5 99442
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " age & lx\\\\\n", "\\hline\n", "\t 0 & 100000\\\\\n", "\t 1 & 99501\\\\\n", "\t 2 & 99483\\\\\n", "\t ⋮ & ⋮\\\\\n", "\t 4 & 99454\\\\\n", "\t 5 & 99442\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "age | lx | \n", "|---|---|---|---|---|---|\n", "| 0 | 100000 | \n", "| 1 | 99501 | \n", "| 2 | 99483 | \n", "| ⋮ | ⋮ | \n", "| 4 | 99454 | \n", "| 5 | 99442 | \n", "\n", "\n" ], "text/plain": [ " age lx \n", "1 0 100000\n", "2 1 99501\n", "3 2 99483\n", "⋮ ⋮ ⋮ \n", "5 4 99454 \n", "6 5 99442 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## c)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "À ce df, ajouter une nouvelle colonne `dx` (nombre de décès entre l'âge x et x+n). Donc dx est le nombre de décès qui surviennent dans chaque intervalle d'âge au sein d'une cohorte initiale de 100 000 naissances vivantes à l'âge 0." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$d_x=l_x -l_{x+1}$$" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
agelxdx
0 100000499
1 99501 18
2 99483 16
4 9945412
5 9944211
\n" ], "text/latex": [ "\\begin{tabular}{r|lll}\n", " age & lx & dx\\\\\n", "\\hline\n", "\t 0 & 100000 & 499 \\\\\n", "\t 1 & 99501 & 18 \\\\\n", "\t 2 & 99483 & 16 \\\\\n", "\t ⋮ & ⋮ & ⋮\\\\\n", "\t 4 & 99454 & 12 \\\\\n", "\t 5 & 99442 & 11 \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "age | lx | dx | \n", "|---|---|---|---|---|---|\n", "| 0 | 100000 | 499 | \n", "| 1 | 99501 | 18 | \n", "| 2 | 99483 | 16 | \n", "| ⋮ | ⋮ | ⋮ | \n", "| 4 | 99454 | 12 | \n", "| 5 | 99442 | 11 | \n", "\n", "\n" ], "text/plain": [ " age lx dx \n", "1 0 100000 499\n", "2 1 99501 18\n", "3 2 99483 16\n", "⋮ ⋮ ⋮ ⋮ \n", "5 4 99454 12 \n", "6 5 99442 11 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## d)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculer qx (quotient de mortalité entre l'âge x et x+n). Donc qx est probabilité qu'un individu d'âge x décède avant d'atteindre l'âge x+n." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$q_x=\\frac{d_x}{l_x}$$" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
agelxdxqx
0 100000 499 0.00499
1 99501 18 0.00018
2 99483 16 0.00016
4 99454 12 0.00012
5 99442 11 0.00011
\n" ], "text/latex": [ "\\begin{tabular}{r|llll}\n", " age & lx & dx & qx\\\\\n", "\\hline\n", "\t 0 & 100000 & 499 & 0.00499\\\\\n", "\t 1 & 99501 & 18 & 0.00018\\\\\n", "\t 2 & 99483 & 16 & 0.00016\\\\\n", "\t ⋮ & ⋮ & ⋮ & ⋮\\\\\n", "\t 4 & 99454 & 12 & 0.00012\\\\\n", "\t 5 & 99442 & 11 & 0.00011\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "age | lx | dx | qx | \n", "|---|---|---|---|---|---|\n", "| 0 | 100000 | 499 | 0.00499 | \n", "| 1 | 99501 | 18 | 0.00018 | \n", "| 2 | 99483 | 16 | 0.00016 | \n", "| ⋮ | ⋮ | ⋮ | ⋮ | \n", "| 4 | 99454 | 12 | 0.00012 | \n", "| 5 | 99442 | 11 | 0.00011 | \n", "\n", "\n" ], "text/plain": [ " age lx dx qx \n", "1 0 100000 499 0.00499\n", "2 1 99501 18 0.00018\n", "3 2 99483 16 0.00016\n", "⋮ ⋮ ⋮ ⋮ ⋮ \n", "5 4 99454 12 0.00012\n", "6 5 99442 11 0.00011" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## e)\n", "Maintenant que vous avez toutes les données, on peut calculer la probabilité qu'un individu d'âge x survive jusqu'à l'âge x+n." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$tP_x=\\frac{l_{x+t}}{l_x}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculer la probabilité qu'un individu de 22 ans survive les trois prochaines années" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "0.998192831903079" ], "text/latex": [ "0.998192831903079" ], "text/markdown": [ "0.998192831903079" ], "text/plain": [ "[1] 0.9981928" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "library(formattable)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "99.82%" ], "text/latex": [ "99.82\\%" ], "text/markdown": [ "99.82%" ], "text/plain": [ "[1] 99.82%" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "percent(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 2" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Avec les données suivantes;" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
IdAge
1 14
2 12
3 15
4 10
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " Id & Age\\\\\n", "\\hline\n", "\t 1 & 14\\\\\n", "\t 2 & 12\\\\\n", "\t 3 & 15\\\\\n", "\t 4 & 10\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "Id | Age | \n", "|---|---|---|---|\n", "| 1 | 14 | \n", "| 2 | 12 | \n", "| 3 | 15 | \n", "| 4 | 10 | \n", "\n", "\n" ], "text/plain": [ " Id Age\n", "1 1 14 \n", "2 2 12 \n", "3 3 15 \n", "4 4 10 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df1" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
IdSexCode
1Fa
2Mb
3Mc
4Fd
\n" ], "text/latex": [ "\\begin{tabular}{r|lll}\n", " Id & Sex & Code\\\\\n", "\\hline\n", "\t 1 & F & a\\\\\n", "\t 2 & M & b\\\\\n", "\t 3 & M & c\\\\\n", "\t 4 & F & d\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "Id | Sex | Code | \n", "|---|---|---|---|\n", "| 1 | F | a | \n", "| 2 | M | b | \n", "| 3 | M | c | \n", "| 4 | F | d | \n", "\n", "\n" ], "text/plain": [ " Id Sex Code\n", "1 1 F a \n", "2 2 M b \n", "3 3 M c \n", "4 4 F d " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "df2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Créer un _data frame_ `M` qui fait une jointure de `df1` et `df2`" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
IdAgeSexCode
1 14F a
2 12M b
3 15M c
4 10F d
\n" ], "text/latex": [ "\\begin{tabular}{r|llll}\n", " Id & Age & Sex & Code\\\\\n", "\\hline\n", "\t 1 & 14 & F & a \\\\\n", "\t 2 & 12 & M & b \\\\\n", "\t 3 & 15 & M & c \\\\\n", "\t 4 & 10 & F & d \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "Id | Age | Sex | Code | \n", "|---|---|---|---|\n", "| 1 | 14 | F | a | \n", "| 2 | 12 | M | b | \n", "| 3 | 15 | M | c | \n", "| 4 | 10 | F | d | \n", "\n", "\n" ], "text/plain": [ " Id Age Sex Code\n", "1 1 14 F a \n", "2 2 12 M b \n", "3 3 15 M c \n", "4 4 10 F d " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ...\n", "M" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Selon un [journaliste de la CNBC](https://www.cnbc.com/video/3000418698), le prix de l'action de Apple [(AAPL)](https://ca.finance.yahoo.com/quote/AAPL/history?p=AAPL) est très corrélé avec le prix de l'action de [Boeing Co (BA)](https://ca.finance.yahoo.com/quote/BA/history?p=BA). \n", "\n", "Calculer la corrélation des prix Adj Close **mensuels** de ces deux compagnies sur la période allant du 2016-11-01 au 2017-10-01.\n", "\n", "**Indice:** créer deux vecteurs avec les valeurs des prix. Vous pouvez importer les données à partir de [finance yahoo](https://ca.finance.yahoo.com/) dans la section _Historical Data_ avec les dates et périodes indiquées ci-haut." ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "
AppleBoeing
Apple1.0000000.872264
Boeing0.8722641.000000
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " & Apple & Boeing\\\\\n", "\\hline\n", "\tApple & 1.000000 & 0.872264\\\\\n", "\tBoeing & 0.872264 & 1.000000\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "| | Apple | Boeing | \n", "|---|---|\n", "| Apple | 1.000000 | 0.872264 | \n", "| Boeing | 0.872264 | 1.000000 | \n", "\n", "\n" ], "text/plain": [ " Apple Boeing \n", "Apple 1.000000 0.872264\n", "Boeing 0.872264 1.000000" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cor(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Question 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Créer un _data frame_ avec les données [HackerRank-Developer-Survey](https://raw.githubusercontent.com/nmeraihi/data/master/HackerRank-Developer-Survey-2018-Values.csv). Dans ces données, vous trouvez une série de réponses que les développeurs de [HackerRank](https://www.hackerrank.com/) ont répondues suite à un sondage ayant pour but de comprendre les l'intérêts des femmes envers la programmation informatique." ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
RespondentIDStartDateEndDateCountryNumeric2q34PositiveExpq34IdealLengHackerRankTestq0035_otherq36Level4
6464453728 10/19/17 11:5110/20/17 12:05South Korea NA #NULL! Queue
6478031510 10/26/17 6:18 10/26/17 7:49 Ukraine NA #NULL! Queue
6464392829 10/19/17 10:4410/19/17 10:56Malaysia NA #NULL! Queue
6488385057 10/31/17 11:4610/31/17 11:59 NA #NULL! Hashmap
6463843138 10/19/17 3:02 10/19/17 3:18 United States NA #NULL! Queue
\n" ], "text/latex": [ "\\begin{tabular}{r|lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll}\n", " RespondentID & StartDate & EndDate & CountryNumeric2 & ⋯ & q34PositiveExp & q34IdealLengHackerRankTest & q0035\\_other & q36Level4\\\\\n", "\\hline\n", "\t 6464453728 & 10/19/17 11:51 & 10/20/17 12:05 & South Korea & ⋯ & NA & \\#NULL! & & Queue \\\\\n", "\t 6478031510 & 10/26/17 6:18 & 10/26/17 7:49 & Ukraine & ⋯ & NA & \\#NULL! & & Queue \\\\\n", "\t 6464392829 & 10/19/17 10:44 & 10/19/17 10:56 & Malaysia & ⋯ & NA & \\#NULL! & & Queue \\\\\n", "\t ⋮ & ⋮ & ⋮ & ⋮ & ⋱ & ⋮ & ⋮ & ⋮ & ⋮\\\\\n", "\t 6488385057 & 10/31/17 11:46 & 10/31/17 11:59 & & ⋯ & NA & \\#NULL! & & Hashmap \\\\\n", "\t 6463843138 & 10/19/17 3:02 & 10/19/17 3:18 & United States & ⋯ & NA & \\#NULL! & & Queue \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "RespondentID | StartDate | EndDate | CountryNumeric2 | ⋯ | q34PositiveExp | q34IdealLengHackerRankTest | q0035_other | q36Level4 | \n", "|---|---|---|---|---|---|\n", "| 6464453728 | 10/19/17 11:51 | 10/20/17 12:05 | South Korea | ⋯ | NA | #NULL! | | Queue | \n", "| 6478031510 | 10/26/17 6:18 | 10/26/17 7:49 | Ukraine | ⋯ | NA | #NULL! | | Queue | \n", "| 6464392829 | 10/19/17 10:44 | 10/19/17 10:56 | Malaysia | ⋯ | NA | #NULL! | | Queue | \n", "| ⋮ | ⋮ | ⋮ | ⋮ | ⋱ | ⋮ | ⋮ | ⋮ | ⋮ | \n", "| 6488385057 | 10/31/17 11:46 | 10/31/17 11:59 | | ⋯ | NA | #NULL! | | Hashmap | \n", "| 6463843138 | 10/19/17 3:02 | 10/19/17 3:18 | United States | ⋯ | NA | #NULL! | | Queue | \n", "\n", "\n" ], "text/plain": [ " RespondentID StartDate EndDate CountryNumeric2 ⋯ q34PositiveExp\n", "1 6464453728 10/19/17 11:51 10/20/17 12:05 South Korea ⋯ NA \n", "2 6478031510 10/26/17 6:18 10/26/17 7:49 Ukraine ⋯ NA \n", "3 6464392829 10/19/17 10:44 10/19/17 10:56 Malaysia ⋯ NA \n", "⋮ ⋮ ⋮ ⋮ ⋮ ⋱ ⋮ \n", "5 6488385057 10/31/17 11:46 10/31/17 11:59 ⋯ NA \n", "6 6463843138 10/19/17 3:02 10/19/17 3:18 United States ⋯ NA \n", " q34IdealLengHackerRankTest q0035_other q36Level4\n", "1 #NULL! Queue \n", "2 #NULL! Queue \n", "3 #NULL! Queue \n", "⋮ ⋮ ⋮ ⋮ \n", "5 #NULL! Hashmap \n", "6 #NULL! Queue " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "head(values)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "En utilisant le package `dplyr`, faites un petit tableau qui donne la proportion des hommes et des femmes dans ce _dataset_. \n", "\n", "Utilisez la variable `q3Gender`" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\n", "
q3Gendern
Female 16.55688
Male 83.44312
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " q3Gender & n\\\\\n", "\\hline\n", "\t Female & 16.55688\\\\\n", "\t Male & 83.44312\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "q3Gender | n | \n", "|---|---|\n", "| Female | 16.55688 | \n", "| Male | 83.44312 | \n", "\n", "\n" ], "text/plain": [ " q3Gender n \n", "1 Female 16.55688\n", "2 Male 83.44312" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "values_2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "En utilisant le package `dplyr`, faites un tableau qui donne la proportion des hommes et des femmes en les séparant par le fait qu'ils soient étudiants ou non. \n", "\n", "Utilisez les variables `q3Gender`, `is_student` et `q8Student`" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
q3Genderis_studentn
Female No 20.82685
Female Yes 13.55364
Male No 79.17315
Male Yes 86.44636
\n" ], "text/latex": [ "\\begin{tabular}{r|lll}\n", " q3Gender & is\\_student & n\\\\\n", "\\hline\n", "\t Female & No & 20.82685\\\\\n", "\t Female & Yes & 13.55364\\\\\n", "\t Male & No & 79.17315\\\\\n", "\t Male & Yes & 86.44636\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "q3Gender | is_student | n | \n", "|---|---|---|---|\n", "| Female | No | 20.82685 | \n", "| Female | Yes | 13.55364 | \n", "| Male | No | 79.17315 | \n", "| Male | Yes | 86.44636 | \n", "\n", "\n" ], "text/plain": [ " q3Gender is_student n \n", "1 Female No 20.82685\n", "2 Female Yes 13.55364\n", "3 Male No 79.17315\n", "4 Male Yes 86.44636" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## c)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Dresser un tableau qui donne le nombre de répondants par pays (utilisez la variable `CountryNumeric2`)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
CountryNumeric2n
3991
Afghanistan 3
Albania 8
American Samoa1
Andorra 1
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " CountryNumeric2 & n\\\\\n", "\\hline\n", "\t & 3991 \\\\\n", "\t Afghanistan & 3 \\\\\n", "\t Albania & 8 \\\\\n", "\t ⋮ & ⋮\\\\\n", "\t American Samoa & 1 \\\\\n", "\t Andorra & 1 \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "CountryNumeric2 | n | \n", "|---|---|---|---|---|---|\n", "| | 3991 | \n", "| Afghanistan | 3 | \n", "| Albania | 8 | \n", "| ⋮ | ⋮ | \n", "| American Samoa | 1 | \n", "| Andorra | 1 | \n", "\n", "\n" ], "text/plain": [ " CountryNumeric2 n \n", "1 3991\n", "2 Afghanistan 3\n", "3 Albania 8\n", "⋮ ⋮ ⋮ \n", "5 American Samoa 1 \n", "6 Andorra 1 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## d)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Faites un tableau qui donne le nombre de répondants en les classant par le diplôme obtenu. \n", "\n", "Utilisez la variable `q4Education`" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
q4EducationTotal
College graduate 12010
Post graduate degree (Masters, PhD) 6030
Some college 2499
#NULL! 305
Vocational training (like bootcamp)148
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " q4Education & Total\\\\\n", "\\hline\n", "\t College graduate & 12010 \\\\\n", "\t Post graduate degree (Masters, PhD) & 6030 \\\\\n", "\t Some college & 2499 \\\\\n", "\t ⋮ & ⋮\\\\\n", "\t \\#NULL! & 305 \\\\\n", "\t Vocational training (like bootcamp) & 148 \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "q4Education | Total | \n", "|---|---|---|---|---|---|\n", "| College graduate | 12010 | \n", "| Post graduate degree (Masters, PhD) | 6030 | \n", "| Some college | 2499 | \n", "| ⋮ | ⋮ | \n", "| #NULL! | 305 | \n", "| Vocational training (like bootcamp) | 148 | \n", "\n", "\n" ], "text/plain": [ " q4Education Total\n", "1 College graduate 12010\n", "2 Post graduate degree (Masters, PhD) 6030\n", "3 Some college 2499\n", "⋮ ⋮ ⋮ \n", "7 #NULL! 305 \n", "8 Vocational training (like bootcamp) 148 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Faites un tableau qui donne le nombre de développeurs par catégorie d'âge.\n", "\n", "Utilisez la variable `q1AgeBeginCoding`" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\t\n", "\n", "
q1AgeBeginCodingTotal
16 - 20 years old14293
11 - 15 years old 5264
21 - 25 years old 3626
#NULL! 30
50+ years or older 8
\n" ], "text/latex": [ "\\begin{tabular}{r|ll}\n", " q1AgeBeginCoding & Total\\\\\n", "\\hline\n", "\t 16 - 20 years old & 14293 \\\\\n", "\t 11 - 15 years old & 5264 \\\\\n", "\t 21 - 25 years old & 3626 \\\\\n", "\t ⋮ & ⋮\\\\\n", "\t \\#NULL! & 30 \\\\\n", "\t 50+ years or older & 8 \\\\\n", "\\end{tabular}\n" ], "text/markdown": [ "\n", "q1AgeBeginCoding | Total | \n", "|---|---|---|---|---|---|\n", "| 16 - 20 years old | 14293 | \n", "| 11 - 15 years old | 5264 | \n", "| 21 - 25 years old | 3626 | \n", "| ⋮ | ⋮ | \n", "| #NULL! | 30 | \n", "| 50+ years or older | 8 | \n", "\n", "\n" ], "text/plain": [ " q1AgeBeginCoding Total\n", "1 16 - 20 years old 14293\n", "2 11 - 15 years old 5264\n", "3 21 - 25 years old 3626\n", "⋮ ⋮ ⋮ \n", "9 #NULL! 30 \n", "10 50+ years or older 8 " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "4.1.2" }, "latex_envs": { "LaTeX_envs_menu_present": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "base_numbering": 1, "nav_menu": { "height": "174px", "width": "252px" }, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": "block", "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 4 }