diff --git a/02_RProgramming/DataTypes/Introduction to the R Language.pdf b/02_RProgramming/DataTypes/Introduction to the R Language.pdf index cec046b60..b8f1bc492 100644 Binary files a/02_RProgramming/DataTypes/Introduction to the R Language.pdf and b/02_RProgramming/DataTypes/Introduction to the R Language.pdf differ diff --git a/02_RProgramming/DataTypes/index.Rmd b/02_RProgramming/DataTypes/index.Rmd index 65eb1ce54..19f8f1af4 100644 --- a/02_RProgramming/DataTypes/index.Rmd +++ b/02_RProgramming/DataTypes/index.Rmd @@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...} highlighter : highlight.js # {highlight.js, prettify, highlight} hitheme : tomorrow # url: - lib: ../../libraries + lib: ../../librariesNew assets: ../../assets widgets : [mathjax] # {mathjax, quiz, bootstrap} mode : selfcontained # {standalone, draft} @@ -200,7 +200,9 @@ NAs introduced by coercion > as.logical(x) [1] NA NA NA > as.complex(x) -[1] 0+0i 1+0i 2+0i 3+0i 4+0i 5+0i 6+0i +[1] NA NA NA +Warning message: +NAs introduced by coercion ``` --- @@ -472,4 +474,4 @@ Data Types - data frames -- names \ No newline at end of file +- names diff --git a/02_RProgramming/DataTypes/index.html b/02_RProgramming/DataTypes/index.html index 9b50617cb..00c65c081 100644 --- a/02_RProgramming/DataTypes/index.html +++ b/02_RProgramming/DataTypes/index.html @@ -8,46 +8,46 @@ <meta name="generator" content="slidify" /> <meta name="apple-mobile-web-app-capable" content="yes"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> - <link rel="stylesheet" href="../../libraries/frameworks/io2012/css/default.css" media="all" > - <link rel="stylesheet" href="../../libraries/frameworks/io2012/phone.css" + <link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/default.css" media="all" > + <link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/phone.css" media="only screen and (max-device-width: 480px)" > - <link rel="stylesheet" href="../../libraries/frameworks/io2012/css/slidify.css" > - <link rel="stylesheet" href="../../libraries/highlighters/highlight.js/css/tomorrow.css" /> - <base target="_blank"> <!-- This amazingness opens all links in a new tab. --> - <script data-main="../../libraries/frameworks/io2012/js/slides" - src="../../libraries/frameworks/io2012/js/require-1.0.8.min.js"> + <link rel="stylesheet" href="../../librariesNew/frameworks/io2012/css/slidify.css" > + <link rel="stylesheet" href="../../librariesNew/highlighters/highlight.js/css/tomorrow.css" /> + <base target="_blank"> <!-- This amazingness opens all links in a new tab. --> + + <!-- Grab CDN jQuery, fall back to local if offline --> + <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script> + <script>window.jQuery || document.write('<script src="../../librariesNew/widgets/quiz/js/jquery.js"><\/script>')</script> + <script data-main="../../librariesNew/frameworks/io2012/js/slides" + src="../../librariesNew/frameworks/io2012/js/require-1.0.8.min.js"> </script> - <link rel="stylesheet" href = "../../assets/css/custom.css"> -<link rel="stylesheet" href = "../../assets/css/ribbons.css"> + </head> <body style="opacity: 0"> <slides class="layout-widescreen"> <!-- LOGO SLIDE --> - <!-- END LOGO SLIDE --> + <slide class="title-slide segue nobackground"> + <aside class="gdbar"> + <img src="../../assets/img/bloomberg_shield.png"> + </aside> + <hgroup class="auto-fadein"> + <h1>Introduction to the R Language</h1> + <h2>Data Types and Basic Operations</h2> + <p>Roger Peng, Associate Professor<br/>Johns Hopkins Bloomberg School of Public Health</p> + </hgroup> + <article></article> +</slide> - <!-- TITLE SLIDE --> - <!-- Should I move this to a Local Layout File? --> - <slide class="title-slide segue nobackground"> - <aside class="gdbar"> - <img src="../../assets/img/bloomberg_shield.png"> - </aside> - <hgroup class="auto-fadein"> - <h1>Introduction to the R Language</h1> - <h2>Data Types and Basic Operations</h2> - <p>Roger Peng, Associate Professor<br/>Johns Hopkins Bloomberg School of Public Health</p> - </hgroup> - </slide> - <!-- SLIDES --> - <slide class="" id="slide-1" style="background:;"> + <slide class="" id="slide-1" style="background:;"> <hgroup> <h2>Objects</h2> </hgroup> - <article> + <article data-timings=""> <p>R has five basic or “atomic” classes of objects:</p> <ul> @@ -73,11 +73,11 @@ <h2>Objects</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-2" style="background:;"> +<slide class="" id="slide-2" style="background:;"> <hgroup> <h2>Numbers</h2> </hgroup> - <article> + <article data-timings=""> <ul> <li><p>Numbers in R a generally treated as numeric objects (i.e. double precision real numbers)</p></li> @@ -97,11 +97,11 @@ <h2>Numbers</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-3" style="background:;"> +<slide class="" id="slide-3" style="background:;"> <hgroup> <h2>Attributes</h2> </hgroup> - <article> + <article data-timings=""> <p>R objects can have attributes</p> <ul> @@ -119,11 +119,11 @@ <h2>Attributes</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-4" style="background:;"> +<slide class="" id="slide-4" style="background:;"> <hgroup> <h2>Entering Input</h2> </hgroup> - <article> + <article data-timings=""> <p>At the R prompt we type expressions. The <code><-</code> symbol is the assignment operator.</p> <pre><code class="r">> x <- 1 @@ -145,11 +145,11 @@ <h2>Entering Input</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-5" style="background:;"> +<slide class="" id="slide-5" style="background:;"> <hgroup> <h2>Evaluation</h2> </hgroup> - <article> + <article data-timings=""> <p>When a complete expression is entered at the prompt, it is evaluated and the result of the evaluated expression is returned. The result may be auto-printed.</p> <pre><code class="r">> x <- 5 ## nothing printed @@ -165,11 +165,11 @@ <h2>Evaluation</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-6" style="background:;"> +<slide class="" id="slide-6" style="background:;"> <hgroup> <h2>Printing</h2> </hgroup> - <article> + <article data-timings=""> <pre><code class="r">> x <- 1:20 > x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @@ -182,11 +182,11 @@ <h2>Printing</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-7" style="background:;"> +<slide class="" id="slide-7" style="background:;"> <hgroup> <h2>Creating Vectors</h2> </hgroup> - <article> + <article data-timings=""> <p>The <code>c()</code> function can be used to create vectors of objects.</p> <pre><code class="r">> x <- c(0.5, 0.6) ## numeric @@ -208,11 +208,11 @@ <h2>Creating Vectors</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-8" style="background:;"> +<slide class="" id="slide-8" style="background:;"> <hgroup> <h2>Mixing Objects</h2> </hgroup> - <article> + <article data-timings=""> <p>What about the following?</p> <pre><code class="r">> y <- c(1.7, "a") ## character @@ -226,11 +226,11 @@ <h2>Mixing Objects</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-9" style="background:;"> +<slide class="" id="slide-9" style="background:;"> <hgroup> <h2>Explicit Coercion</h2> </hgroup> - <article> + <article data-timings=""> <p>Objects can be explicitly coerced from one class to another using the <code>as.*</code> functions, if available.</p> <pre><code class="r">> x <- 0:6 @@ -248,11 +248,11 @@ <h2>Explicit Coercion</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-10" style="background:;"> +<slide class="" id="slide-10" style="background:;"> <hgroup> <h2>Explicit Coercion</h2> </hgroup> - <article> + <article data-timings=""> <p>Nonsensical coercion results in <code>NA</code>s.</p> <pre><code class="r">> x <- c("a", "b", "c") @@ -263,18 +263,20 @@ <h2>Explicit Coercion</h2> > as.logical(x) [1] NA NA NA > as.complex(x) -[1] 0+0i 1+0i 2+0i 3+0i 4+0i 5+0i 6+0i +[1] NA NA NA +Warning message: +NAs introduced by coercion </code></pre> </article> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-11" style="background:;"> +<slide class="" id="slide-11" style="background:;"> <hgroup> <h2>Matrices</h2> </hgroup> - <article> + <article data-timings=""> <p>Matrices are vectors with a <em>dimension</em> attribute. The dimension attribute is itself an integer vector of length 2 (nrow, ncol)</p> <pre><code class="r">> m <- matrix(nrow = 2, ncol = 3) @@ -293,11 +295,11 @@ <h2>Matrices</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-12" style="background:;"> +<slide class="" id="slide-12" style="background:;"> <hgroup> <h2>Matrices (cont’d)</h2> </hgroup> - <article> + <article data-timings=""> <p>Matrices are constructed <em>column-wise</em>, so entries can be thought of starting in the “upper left” corner and running down the columns.</p> <pre><code class="r">> m <- matrix(1:6, nrow = 2, ncol = 3) @@ -311,11 +313,11 @@ <h2>Matrices (cont’d)</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-13" style="background:;"> +<slide class="" id="slide-13" style="background:;"> <hgroup> <h2>Matrices (cont’d)</h2> </hgroup> - <article> + <article data-timings=""> <p>Matrices can also be created directly from vectors by adding a dimension attribute.</p> <pre><code class="r">> m <- 1:10 @@ -332,11 +334,11 @@ <h2>Matrices (cont’d)</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-14" style="background:;"> +<slide class="" id="slide-14" style="background:;"> <hgroup> <h2>cbind-ing and rbind-ing</h2> </hgroup> - <article> + <article data-timings=""> <p>Matrices can be created by <em>column-binding</em> or <em>row-binding</em> with <code>cbind()</code> and <code>rbind()</code>.</p> <pre><code class="r">> x <- 1:3 @@ -356,11 +358,11 @@ <h2>cbind-ing and rbind-ing</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-15" style="background:;"> +<slide class="" id="slide-15" style="background:;"> <hgroup> <h2>Lists</h2> </hgroup> - <article> + <article data-timings=""> <p>Lists are a special type of vector that can contain elements of different classes. Lists are a very important data type in R and you should get to know them well.</p> <pre><code class="r">> x <- list(1, "a", TRUE, 1 + 4i) @@ -382,11 +384,11 @@ <h2>Lists</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-16" style="background:;"> +<slide class="" id="slide-16" style="background:;"> <hgroup> <h2>Factors</h2> </hgroup> - <article> + <article data-timings=""> <p>Factors are used to represent categorical data. Factors can be unordered or ordered. One can think of a factor as an integer vector where each integer has a <em>label</em>.</p> <ul> @@ -398,11 +400,11 @@ <h2>Factors</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-17" style="background:;"> +<slide class="" id="slide-17" style="background:;"> <hgroup> <h2>Factors</h2> </hgroup> - <article> + <article data-timings=""> <pre><code class="r">> x <- factor(c("yes", "yes", "no", "yes", "no")) > x [1] yes yes no yes no @@ -421,11 +423,11 @@ <h2>Factors</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-18" style="background:;"> +<slide class="" id="slide-18" style="background:;"> <hgroup> <h2>Factors</h2> </hgroup> - <article> + <article data-timings=""> <p>The order of the levels can be set using the <code>levels</code> argument to <code>factor()</code>. This can be important in linear modelling because the first level is used as the baseline level.</p> <pre><code class="r">> x <- factor(c("yes", "yes", "no", "yes", "no"), @@ -439,11 +441,11 @@ <h2>Factors</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-19" style="background:;"> +<slide class="" id="slide-19" style="background:;"> <hgroup> <h2>Missing Values</h2> </hgroup> - <article> + <article data-timings=""> <p>Missing values are denoted by <code>NA</code> or <code>NaN</code> for undefined mathematical operations. </p> <ul> @@ -457,11 +459,11 @@ <h2>Missing Values</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-20" style="background:;"> +<slide class="" id="slide-20" style="background:;"> <hgroup> <h2>Missing Values</h2> </hgroup> - <article> + <article data-timings=""> <pre><code class="r">> x <- c(1, 2, NA, 10, 3) > is.na(x) [1] FALSE FALSE TRUE FALSE FALSE @@ -478,11 +480,11 @@ <h2>Missing Values</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-21" style="background:;"> +<slide class="" id="slide-21" style="background:;"> <hgroup> <h2>Data Frames</h2> </hgroup> - <article> + <article data-timings=""> <p>Data frames are used to store tabular data</p> <ul> @@ -498,11 +500,11 @@ <h2>Data Frames</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-22" style="background:;"> +<slide class="" id="slide-22" style="background:;"> <hgroup> <h2>Data Frames</h2> </hgroup> - <article> + <article data-timings=""> <pre><code class="r">> x <- data.frame(foo = 1:4, bar = c(T, T, F, F)) > x foo bar @@ -520,11 +522,11 @@ <h2>Data Frames</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-23" style="background:;"> +<slide class="" id="slide-23" style="background:;"> <hgroup> <h2>Names</h2> </hgroup> - <article> + <article data-timings=""> <p>R objects can also have names, which is very useful for writing readable code and self-describing objects.</p> <pre><code class="r">> x <- 1:3 @@ -542,11 +544,11 @@ <h2>Names</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-24" style="background:;"> +<slide class="" id="slide-24" style="background:;"> <hgroup> <h2>Names</h2> </hgroup> - <article> + <article data-timings=""> <p>Lists can also have names.</p> <pre><code class="r">> x <- list(a = 1, b = 2, c = 3) @@ -565,11 +567,11 @@ <h2>Names</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-25" style="background:;"> +<slide class="" id="slide-25" style="background:;"> <hgroup> <h2>Names</h2> </hgroup> - <article> + <article data-timings=""> <p>And matrices.</p> <pre><code class="r">> m <- matrix(1:4, nrow = 2, ncol = 2) @@ -584,11 +586,11 @@ <h2>Names</h2> <!-- Presenter Notes --> </slide> - <slide class="" id="slide-26" style="background:;"> +<slide class="" id="slide-26" style="background:;"> <hgroup> <h2>Summary</h2> </hgroup> - <article> + <article data-timings=""> <p>Data Types</p> <ul> @@ -606,34 +608,191 @@ <h2>Summary</h2> <slide class="backdrop"></slide> </slides> - - <!--[if IE]> + <div class="pagination pagination-small" id='io2012-ptoc' style="display:none;"> + <ul> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=1 title='Objects'> + 1 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=2 title='Numbers'> + 2 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=3 title='Attributes'> + 3 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=4 title='Entering Input'> + 4 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=5 title='Evaluation'> + 5 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=6 title='Printing'> + 6 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=7 title='Creating Vectors'> + 7 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=8 title='Mixing Objects'> + 8 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=9 title='Explicit Coercion'> + 9 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=10 title='Explicit Coercion'> + 10 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=11 title='Matrices'> + 11 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=12 title='Matrices (cont’d)'> + 12 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=13 title='Matrices (cont’d)'> + 13 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=14 title='cbind-ing and rbind-ing'> + 14 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=15 title='Lists'> + 15 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=16 title='Factors'> + 16 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=17 title='Factors'> + 17 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=18 title='Factors'> + 18 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=19 title='Missing Values'> + 19 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=20 title='Missing Values'> + 20 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=21 title='Data Frames'> + 21 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=22 title='Data Frames'> + 22 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=23 title='Names'> + 23 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=24 title='Names'> + 24 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=25 title='Names'> + 25 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=26 title='Summary'> + 26 + </a> + </li> + </ul> + </div> <!--[if IE]> <script src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"> </script> <script>CFInstall.check({mode: 'overlay'});</script> <![endif]--> </body> -<!-- Grab CDN jQuery, fall back to local if offline --> -<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script> -<script>window.jQuery || document.write('<script src="../../libraries/widgets/quiz/js/jquery-1.7.min.js"><\/script>')</script> -<!-- Load Javascripts for Widgets --> -<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) --> -<script type="text/x-mathjax-config"> - MathJax.Hub.Config({ - tex2jax: { - inlineMath: [['$','$'], ['\\(','\\)']], - processEscapes: true - } - }); -</script> -<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> -</script> --> -<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>') + <!-- Load Javascripts for Widgets --> + + <!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) --> + <script type="text/x-mathjax-config"> + MathJax.Hub.Config({ + tex2jax: { + inlineMath: [['$','$'], ['\\(','\\)']], + processEscapes: true + } + }); + </script> + <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> + </script> --> + <script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../librariesNew/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>') </script> <!-- LOAD HIGHLIGHTER JS FILES --> -<script src="../../libraries/highlighters/highlight.js/highlight.pack.js"></script> -<script>hljs.initHighlightingOnLoad();</script> -<!-- DONE LOADING HIGHLIGHTER JS FILES --> -</html> \ No newline at end of file + <script src="../../librariesNew/highlighters/highlight.js/highlight.pack.js"></script> + <script>hljs.initHighlightingOnLoad();</script> + <!-- DONE LOADING HIGHLIGHTER JS FILES --> + + </html> \ No newline at end of file diff --git a/02_RProgramming/DataTypes/index.md b/02_RProgramming/DataTypes/index.md index ccd9ff364..19f8f1af4 100644 --- a/02_RProgramming/DataTypes/index.md +++ b/02_RProgramming/DataTypes/index.md @@ -8,7 +8,7 @@ framework : io2012 # {io2012, html5slides, shower, dzslides, ...} highlighter : highlight.js # {highlight.js, prettify, highlight} hitheme : tomorrow # url: - lib: ../../libraries + lib: ../../librariesNew assets: ../../assets widgets : [mathjax] # {mathjax, quiz, bootstrap} mode : selfcontained # {standalone, draft} @@ -200,7 +200,9 @@ NAs introduced by coercion > as.logical(x) [1] NA NA NA > as.complex(x) -[1] 0+0i 1+0i 2+0i 3+0i 4+0i 5+0i 6+0i +[1] NA NA NA +Warning message: +NAs introduced by coercion ``` --- diff --git a/03_GettingData/dplyr/chicago.zip b/03_GettingData/dplyr/chicago.zip new file mode 100644 index 000000000..d0eb3a7fd Binary files /dev/null and b/03_GettingData/dplyr/chicago.zip differ diff --git a/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pdf b/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pdf index 092a7e4c4..a04ed124a 100644 Binary files a/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pdf and b/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pdf differ diff --git a/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pptx b/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pptx index 44e98c5d4..7c3ec5979 100644 Binary files a/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pptx and b/04_ExploratoryAnalysis/ggplot2/ppt/ggplot2.pptx differ diff --git a/05_ReproducibleResearch/organizingADataAnalysis/index.Rmd b/05_ReproducibleResearch/organizingADataAnalysis/index.Rmd index eae99fc98..e2db82a63 100644 --- a/05_ReproducibleResearch/organizingADataAnalysis/index.Rmd +++ b/05_ReproducibleResearch/organizingADataAnalysis/index.Rmd @@ -110,7 +110,7 @@ mode : selfcontained # {standalone, draft} * Not necessary if you use R markdown * Should contain step-by-step instructions for analysis -* Here is an example [https://github.com/jtleek/swfdr/blob/master/README](https://github.com/jtleek/swfdr/blob/master/README) +* Here is an example [https://github.com/jtleek/swfdr/blob/master/README.md](https://github.com/jtleek/swfdr/blob/master/README.md) --- diff --git a/05_ReproducibleResearch/organizingADataAnalysis/index.html b/05_ReproducibleResearch/organizingADataAnalysis/index.html index 027e1d484..ab751d4e7 100644 --- a/05_ReproducibleResearch/organizingADataAnalysis/index.html +++ b/05_ReproducibleResearch/organizingADataAnalysis/index.html @@ -1,59 +1,171 @@ <!DOCTYPE html> <html> <head> - <title>Organizing a Data Analysis</title> - <meta charset="utf-8"> - <meta name="description" content="Organizing a Data Analysis"> - <meta name="author" content="Roger D. Peng, Associate Professor of Biostatistics"> - <meta name="generator" content="slidify" /> - <meta name="apple-mobile-web-app-capable" content="yes"> - <meta http-equiv="X-UA-Compatible" content="chrome=1"> - <link rel="stylesheet" href="../../libraries/frameworks/io2012/css/default.css" media="all" > - <link rel="stylesheet" href="../../libraries/frameworks/io2012/phone.css" - media="only screen and (max-device-width: 480px)" > - <link rel="stylesheet" href="../../libraries/frameworks/io2012/css/slidify.css" > - <link rel="stylesheet" href="../../libraries/highlighters/highlight.js/css/zenburn.css" /> - <base target="_blank"> <!-- This amazingness opens all links in a new tab. --> - <script data-main="../../libraries/frameworks/io2012/js/slides" - src="../../libraries/frameworks/io2012/js/require-1.0.8.min.js"> - </script> - - <link rel="stylesheet" href = "../../assets/css/custom.css"> -<link rel="stylesheet" href = "../../assets/css/custom.css.BACKUP.546.css"> -<link rel="stylesheet" href = "../../assets/css/custom.css.BASE.546.css"> -<link rel="stylesheet" href = "../../assets/css/custom.css.LOCAL.546.css"> -<link rel="stylesheet" href = "../../assets/css/custom.css.orig"> -<link rel="stylesheet" href = "../../assets/css/custom.css.REMOTE.546.css"> -<link rel="stylesheet" href = "../../assets/css/ribbons.css"> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + +<title>Data analysis files</title> + +<script type="text/javascript"> +window.onload = function() { + var imgs = document.getElementsByTagName('img'), i, img; + for (i = 0; i < imgs.length; i++) { + img = imgs[i]; + // center an image if it is the only element of its parent + if (img.parentElement.childElementCount === 1) + img.parentElement.style.textAlign = 'center'; + } +}; +</script> + + + + + +<style type="text/css"> +body, td { + font-family: sans-serif; + background-color: white; + font-size: 13px; +} + +body { + max-width: 800px; + margin: auto; + padding: 1em; + line-height: 20px; +} + +tt, code, pre { + font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace; +} + +h1 { + font-size:2.2em; +} + +h2 { + font-size:1.8em; +} + +h3 { + font-size:1.4em; +} + +h4 { + font-size:1.0em; +} + +h5 { + font-size:0.9em; +} + +h6 { + font-size:0.8em; +} + +a:visited { + color: rgb(50%, 0%, 50%); +} + +pre, img { + max-width: 100%; +} +pre { + overflow-x: auto; +} +pre code { + display: block; padding: 0.5em; +} + +code { + font-size: 92%; + border: 1px solid #ccc; +} + +code[class] { + background-color: #F8F8F8; +} + +table, td, th { + border: none; +} + +blockquote { + color:#666666; + margin:0; + padding-left: 1em; + border-left: 0.5em #EEE solid; +} + +hr { + height: 0px; + border-bottom: none; + border-top-width: thin; + border-top-style: dotted; + border-top-color: #999999; +} + +@media print { + * { + background: transparent !important; + color: black !important; + filter:none !important; + -ms-filter: none !important; + } + + body { + font-size:12pt; + max-width:100%; + } + + a, a:visited { + text-decoration: underline; + } + + hr { + visibility: hidden; + page-break-before: always; + } + + pre, blockquote { + padding-right: 1em; + page-break-inside: avoid; + } + + tr, img { + page-break-inside: avoid; + } + + img { + max-width: 100% !important; + } + + @page :left { + margin: 15mm 20mm 15mm 10mm; + } + + @page :right { + margin: 15mm 10mm 15mm 20mm; + } + + p, h2, h3 { + orphans: 3; widows: 3; + } + + h2, h3 { + page-break-after: avoid; + } +} +</style> + + </head> -<body style="opacity: 0"> - <slides class="layout-widescreen"> - - <!-- LOGO SLIDE --> - <!-- END LOGO SLIDE --> - - - <!-- TITLE SLIDE --> - <!-- Should I move this to a Local Layout File? --> - <slide class="title-slide segue nobackground"> - <aside class="gdbar"> - <img src="../../assets/img/bloomberg_shield.png"> - </aside> - <hgroup class="auto-fadein"> - <h1>Organizing a Data Analysis</h1> - <h2></h2> - <p>Roger D. Peng, Associate Professor of Biostatistics<br/>Johns Hopkins Bloomberg School of Public Health</p> - </hgroup> - </slide> - - <!-- SLIDES --> - <slide class="" id="slide-1" style="background:;"> - <hgroup> - <h2>Data analysis files</h2> - </hgroup> - <article> - <ul> + +<body> +<h2>Data analysis files</h2> + +<ul> <li>Data <ul> @@ -81,32 +193,22 @@ <h2>Data analysis files</h2> </ul></li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> - <slide class="" id="slide-2" style="background:;"> - <hgroup> - <h2>Raw Data</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/medicalrecord.png height='400'/></p> +<h2>Raw Data</h2> + +<p><img class=center src=../../assets/img/medicalrecord.png height='400'/></p> <ul> <li>Should be stored in your analysis folder</li> <li>If accessed from the web, include url, description, and date accessed in README</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> + +<h2>Processed data</h2> - <slide class="" id="slide-3" style="background:;"> - <hgroup> - <h2>Processed data</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/excel.png height='400'/></p> +<p><img class=center src=../../assets/img/excel.png height='400'/></p> <ul> <li>Processed data should be named so it is easy to see which script generated the data. </li> @@ -114,32 +216,22 @@ <h2>Processed data</h2> <li>Processed data should be <a href="http://vita.had.co.nz/papers/tidy-data.pdf">tidy</a></li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> + +<h2>Exploratory figures</h2> - <slide class="" id="slide-4" style="background:;"> - <hgroup> - <h2>Exploratory figures</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/example10.png height='400'/></p> +<p><img class=center src=../../assets/img/example10.png height='400'/></p> <ul> <li>Figures made during the course of your analysis, not necessarily part of your final report.</li> -<li>They do not need to be "pretty"</li> +<li>They do not need to be “pretty”</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> - <slide class="" id="slide-5" style="background:;"> - <hgroup> - <h2>Final Figures</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/figure1final.png height='400'/></p> +<h2>Final Figures</h2> + +<p><img class=center src=../../assets/img/figure1final.png height='400'/></p> <ul> <li>Usually a small subset of the original figures</li> @@ -147,16 +239,11 @@ <h2>Final Figures</h2> <li>Possibly multiple panels</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> + +<h2>Raw scripts</h2> - <slide class="" id="slide-6" style="background:;"> - <hgroup> - <h2>Raw scripts</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/rawcode.png height='350'/></p> +<p><img class=center src=../../assets/img/rawcode.png height='350'/></p> <ul> <li>May be less commented (but comments help you!)</li> @@ -164,16 +251,11 @@ <h2>Raw scripts</h2> <li>May include analyses that are later discarded</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> - <slide class="" id="slide-7" style="background:;"> - <hgroup> - <h2>Final scripts</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/finalscript2.png height='300'/></p> +<h2>Final scripts</h2> + +<p><img class=center src=../../assets/img/finalscript2.png height='300'/></p> <ul> <li>Clearly commented @@ -186,16 +268,11 @@ <h2>Final scripts</h2> <li>Only analyses that appear in the final write-up</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> + +<h2>R markdown files</h2> - <slide class="" id="slide-8" style="background:;"> - <hgroup> - <h2>R markdown files</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/rmd.png height='400'/></p> +<p><img class=center src=../../assets/img/rmd.png height='400'/></p> <ul> <li><a href="http://www.rstudio.com/ide/docs/authoring/using_markdown">R markdown</a> files can be used to generate reproducible reports</li> @@ -203,33 +280,23 @@ <h2>R markdown files</h2> <li>Very easy to create in <a href="http://www.rstudio.com/">Rstudio</a></li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> - <slide class="" id="slide-9" style="background:;"> - <hgroup> - <h2>Readme files</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/readme.png height='400'/></p> +<h2>Readme files</h2> + +<p><img class=center src=../../assets/img/readme.png height='400'/></p> <ul> <li>Not necessary if you use R markdown</li> <li>Should contain step-by-step instructions for analysis</li> -<li>Here is an example <a href="https://github.com/jtleek/swfdr/blob/master/README">https://github.com/jtleek/swfdr/blob/master/README</a></li> +<li>Here is an example <a href="https://github.com/jtleek/swfdr/blob/master/README.md">https://github.com/jtleek/swfdr/blob/master/README.md</a></li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> + +<h2>Text of the document</h2> - <slide class="" id="slide-10" style="background:;"> - <hgroup> - <h2>Text of the document</h2> - </hgroup> - <article> - <p><img class=center src=../../assets/img/swfdr.png height='350'/></p> +<p><img class=center src=../../assets/img/swfdr.png height='350'/></p> <ul> <li>It should include a title, introduction (motivation), methods (statistics you used), results (including measures of uncertainty), and conclusions (including potential problems)</li> @@ -238,56 +305,17 @@ <h2>Text of the document</h2> <li>References should be included for statistical methods</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> +<hr/> + +<h2>Further resources</h2> - <slide class="" id="slide-11" style="background:;"> - <hgroup> - <h2>Further resources</h2> - </hgroup> - <article> - <ul> +<ul> <li>Information about a non-reproducible study that led to cancer patients being mistreated: <a href="http://simplystatistics.org/2012/02/27/the-duke-saga-starter-set/">The Duke Saga Starter Set</a></li> <li><a href="http://biostatistics.oxfordjournals.org/content/10/3/405.full">Reproducible research and Biostatistics</a></li> <li><a href="http://www.r-statistics.com/2010/09/managing-a-statistical-analysis-project-guidelines-and-best-practices/">Managing a statistical analysis project guidelines and best practices</a></li> <li><a href="http://projecttemplate.net/">Project template</a> - a pre-organized set of files for data analysis</li> </ul> - </article> - <!-- Presenter Notes --> -</slide> - - <slide class="backdrop"></slide> - </slides> - - <!--[if IE]> - <script - src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"> - </script> - <script>CFInstall.check({mode: 'overlay'});</script> - <![endif]--> </body> -<!-- Grab CDN jQuery, fall back to local if offline --> -<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script> -<script>window.jQuery || document.write('<script src="../../libraries/widgets/quiz/js/jquery-1.7.min.js"><\/script>')</script> -<!-- Load Javascripts for Widgets --> -<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) --> -<script type="text/x-mathjax-config"> - MathJax.Hub.Config({ - tex2jax: { - inlineMath: [['$','$'], ['\\(','\\)']], - processEscapes: true - } - }); -</script> -<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> -</script> --> -<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>') -</script> -<!-- LOAD HIGHLIGHTER JS FILES --> -<script src="../../libraries/highlighters/highlight.js/highlight.pack.js"></script> -<script>hljs.initHighlightingOnLoad();</script> -<!-- DONE LOADING HIGHLIGHTER JS FILES --> -</html> \ No newline at end of file + +</html> diff --git a/05_ReproducibleResearch/organizingADataAnalysis/index.md b/05_ReproducibleResearch/organizingADataAnalysis/index.md index eae99fc98..e2db82a63 100644 --- a/05_ReproducibleResearch/organizingADataAnalysis/index.md +++ b/05_ReproducibleResearch/organizingADataAnalysis/index.md @@ -110,7 +110,7 @@ mode : selfcontained # {standalone, draft} * Not necessary if you use R markdown * Should contain step-by-step instructions for analysis -* Here is an example [https://github.com/jtleek/swfdr/blob/master/README](https://github.com/jtleek/swfdr/blob/master/README) +* Here is an example [https://github.com/jtleek/swfdr/blob/master/README.md](https://github.com/jtleek/swfdr/blob/master/README.md) --- diff --git a/06_StatisticalInference/homework/hw1.Rmd b/06_StatisticalInference/homework/hw1.Rmd index 7f31c63a0..f5476f5c7 100644 --- a/06_StatisticalInference/homework/hw1.Rmd +++ b/06_StatisticalInference/homework/hw1.Rmd @@ -40,22 +40,22 @@ Creating Data Products --- &radio -Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 15% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 6% while that the mother contracted the disease is 5%. What is the probability that both contracted influenza expressed as a whole number percentage? +Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 15% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 10% while that the mother contracted the disease is 9%. What is the probability that both contracted influenza expressed as a whole number percentage? 1. 15% -2. 6% -3. 5% -4. _2%_ +2. 10% +3. 9% +4. _4%_ *** .hint -$A = Father$, $P(A) = .06$, $B = Mother$, $P(B) = .05$ +$A = Father$, $P(A) = .10$, $B = Mother$, $P(B) = .09$ $P(A\cup B) = .15$, *** .explanation -$P(A\cup B) = P(A) + P(B) - 2 P(AB)$ thus -$$.15 = .06 + .05 - 2 P(AB)$$ +$P(A\cup B) = P(A) + P(B) - P(AB)$ thus +$$.15 = .10 + .09 - P(AB)$$ ```{r} -(0.15 - .06 - .05) / 2 +.10 + .09 - .15 ``` --- &radio diff --git a/06_StatisticalInference/homework/hw1.html b/06_StatisticalInference/homework/hw1.html index e2e14b4a6..3db02f1ae 100644 --- a/06_StatisticalInference/homework/hw1.html +++ b/06_StatisticalInference/homework/hw1.html @@ -63,13 +63,13 @@ <h2>About these slides</h2> <article data-timings=""> <div class="quiz quiz-single well "> - <p>Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 15% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 6% while that the mother contracted the disease is 5%. What is the probability that both contracted influenza expressed as a whole number percentage?</p> + <p>Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 15% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 10% while that the mother contracted the disease is 9%. What is the probability that both contracted influenza expressed as a whole number percentage?</p> <ol> <li>15%</li> -<li>6%</li> -<li>5%</li> -<li><em>2%</em></li> +<li>10%</li> +<li>9%</li> +<li><em>4%</em></li> </ol> <button class="quiz-submit btn btn-primary">Submit</button> @@ -78,18 +78,18 @@ <h2>About these slides</h2> <button class="quiz-clear btn btn-danger">Clear</button> <div class="quiz-hint"> - <p>\(A = Father\), \(P(A) = .06\), \(B = Mother\), \(P(B) = .05\) + <p>\(A = Father\), \(P(A) = .10\), \(B = Mother\), \(P(B) = .09\) \(P(A\cup B) = .15\), </p> </div> <div class="quiz-explanation"> - <p>\(P(A\cup B) = P(A) + P(B) - 2 P(AB)\) thus -\[.15 = .06 + .05 - 2 P(AB)\]</p> + <p>\(P(A\cup B) = P(A) + P(B) - P(AB)\) thus +\[.15 = .10 + .09 - P(AB)\]</p> -<pre><code class="r">(0.15 - .06 - .05) / 2 +<pre><code class="r">.10 + .09 - .15 </code></pre> -<pre><code>[1] 0.02 +<pre><code>[1] 0.04 </code></pre> </div> @@ -107,7 +107,7 @@ <h2>About these slides</h2> <ol> <li>1.00</li> <li>0.75</li> -<li>0.50</li> +<li><em>0.50</em></li> <li>0.25</li> </ol> diff --git a/06_StatisticalInference/homework/hw1.md b/06_StatisticalInference/homework/hw1.md index 4a7add5f0..0025d9fc3 100644 --- a/06_StatisticalInference/homework/hw1.md +++ b/06_StatisticalInference/homework/hw1.md @@ -25,27 +25,27 @@ Creating Data Products --- &radio -Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 15% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 6% while that the mother contracted the disease is 5%. What is the probability that both contracted influenza expressed as a whole number percentage? +Consider influenza epidemics for two parent heterosexual families. Suppose that the probability is 15% that at least one of the parents has contracted the disease. The probability that the father has contracted influenza is 10% while that the mother contracted the disease is 9%. What is the probability that both contracted influenza expressed as a whole number percentage? 1. 15% -2. 6% -3. 5% -4. _2%_ +2. 10% +3. 9% +4. _4%_ *** .hint -$A = Father$, $P(A) = .06$, $B = Mother$, $P(B) = .05$ +$A = Father$, $P(A) = .10$, $B = Mother$, $P(B) = .09$ $P(A\cup B) = .15$, *** .explanation -$P(A\cup B) = P(A) + P(B) - 2 P(AB)$ thus -$$.15 = .06 + .05 - 2 P(AB)$$ +$P(A\cup B) = P(A) + P(B) - P(AB)$ thus +$$.15 = .10 + .09 - P(AB)$$ ```r -(0.15 - .06 - .05) / 2 +.10 + .09 - .15 ``` ``` -[1] 0.02 +[1] 0.04 ``` @@ -55,7 +55,7 @@ A random variable, $X$, is uniform, a box from $0$ to $1$ of height $1$. (So tha 1. 1.00 2. 0.75 -3. 0.50 +3. _0.50_ 4. 0.25 *** .hint diff --git a/06_StatisticalInference/homework/hw2.Rmd b/06_StatisticalInference/homework/hw2.Rmd index 3a568425c..b38eab299 100644 --- a/06_StatisticalInference/homework/hw2.Rmd +++ b/06_StatisticalInference/homework/hw2.Rmd @@ -157,10 +157,10 @@ Let $p=.5$ and $X$ be binomial *** .explanation -<span class="answer">`r round(pbinom(4, prob = .5, size = 6, lower.tail = TRUE) * 100, 1)`</span> +<span class="answer">`r round(pbinom(4, prob = .5, size = 6, lower.tail = FALSE) * 100, 1)`</span> ```{r} -round(pbinom(4, prob = .5, size = 6, lower.tail = TRUE) * 100, 1) +round(pbinom(4, prob = .5, size = 6, lower.tail = FALSE) * 100, 1) ``` --- &multitext @@ -210,9 +210,9 @@ If you roll ten standard dice, take their average, then repeat this process over $$Var(\bar X) = \sigma^2 /n$$ *** .explanation -The answer will be <span class="answer">`r round( mean(1 : 6 - 3.5) ^2 / 100, 3)`</span> -since the variance of the sampling distribution of the mean is $\sigma^2/12$ -and the variance of a die roll is +The answer will be <span class="answer">`r round( mean( (1 : 6 - 3.5) ^2) / 10, 3)`</span> +since the variance of the sampling distribution of the mean is $\sigma^2/10$ +where $\sigma^2$ is the variance of a single die roll, which is ```{r} mean((1 : 6 - 3.5)^2) diff --git a/06_StatisticalInference/homework/hw2.html b/06_StatisticalInference/homework/hw2.html index 5bab28043..e7a3d6a50 100644 --- a/06_StatisticalInference/homework/hw2.html +++ b/06_StatisticalInference/homework/hw2.html @@ -48,12 +48,11 @@ <h2>About these slides</h2> </hgroup> <article data-timings=""> <ul> -<li>These are some practice problems for Statistical Inference Quiz 1</li> +<li>These are some practice problems for Statistical Inference Quiz 2</li> <li>They were created using slidify interactive which you will learn in Creating Data Products</li> <li>Please help improve this with pull requests here -(<a href="https://github.com/bcaffo/courses">https://github.com/bcaffo/courses</a>) -runif(1)</li> +(<a href="https://github.com/bcaffo/courses">https://github.com/bcaffo/courses</a>)</li> </ul> </article> @@ -288,12 +287,12 @@ <h2>About these slides</h2> </div> <div class="quiz-explanation"> - <p><span class="answer">89.1</span></p> + <p><span class="answer">10.9</span></p> -<pre><code class="r">round(pbinom(4, prob = .5, size = 6, lower.tail = TRUE) * 100, 1) +<pre><code class="r">round(pbinom(4, prob = .5, size = 6, lower.tail = FALSE) * 100, 1) </code></pre> -<pre><code>[1] 89.1 +<pre><code>[1] 10.9 </code></pre> </div> @@ -388,9 +387,9 @@ <h2>About these slides</h2> </div> <div class="quiz-explanation"> - <p>The answer will be <span class="answer">0</span> -since the variance of the sampling distribution of the mean is \(\sigma^2/12\) -and the variance of a die roll is </p> + <p>The answer will be <span class="answer">0.292</span> +since the variance of the sampling distribution of the mean is \(\sigma^2/10\) +where \(\sigma^2\) is the variance of a single die roll, which is </p> <pre><code class="r">mean((1 : 6 - 3.5)^2) </code></pre> diff --git a/06_StatisticalInference/homework/hw2.md b/06_StatisticalInference/homework/hw2.md index 32ef6b25f..44ecbe56b 100644 --- a/06_StatisticalInference/homework/hw2.md +++ b/06_StatisticalInference/homework/hw2.md @@ -16,12 +16,11 @@ mode : selfcontained # {standalone, draft} ## About these slides -- These are some practice problems for Statistical Inference Quiz 1 +- These are some practice problems for Statistical Inference Quiz 2 - They were created using slidify interactive which you will learn in Creating Data Products - Please help improve this with pull requests here (https://github.com/bcaffo/courses) -runif(1) --- &radio The probability that a manuscript gets accepted to a journal is 12% (say). However, @@ -182,15 +181,15 @@ Let $p=.5$ and $X$ be binomial *** .explanation -<span class="answer">89.1</span> +<span class="answer">10.9</span> ```r -round(pbinom(4, prob = .5, size = 6, lower.tail = TRUE) * 100, 1) +round(pbinom(4, prob = .5, size = 6, lower.tail = FALSE) * 100, 1) ``` ``` -[1] 89.1 +[1] 10.9 ``` @@ -247,9 +246,9 @@ If you roll ten standard dice, take their average, then repeat this process over $$Var(\bar X) = \sigma^2 /n$$ *** .explanation -The answer will be <span class="answer">0</span> -since the variance of the sampling distribution of the mean is $\sigma^2/12$ -and the variance of a die roll is +The answer will be <span class="answer">0.292</span> +since the variance of the sampling distribution of the mean is $\sigma^2/10$ +where $\sigma^2$ is the variance of a single die roll, which is ```r diff --git a/06_StatisticalInference/homework/hw3.Rmd b/06_StatisticalInference/homework/hw3.Rmd new file mode 100644 index 000000000..df1866fc0 --- /dev/null +++ b/06_StatisticalInference/homework/hw3.Rmd @@ -0,0 +1,206 @@ +--- +title : Homework 3 for Stat Inference +subtitle : Extra problems for Stat Inference +author : Brian Caffo +job : Johns Hopkins Bloomberg School of Public Health +framework : io2012 +highlighter : highlight.js +hitheme : tomorrow +#url: +# lib: ../../librariesNew #Remove new if using old slidify +# assets: ../../assets +widgets : [mathjax, quiz, bootstrap] +mode : selfcontained # {standalone, draft} +--- +```{r setup, cache = F, echo = F, message = F, warning = F, tidy = F, results='hide'} +# make this an external chunk that can be included in any file +library(knitr) +options(width = 100) +opts_chunk$set(message = F, error = F, warning = F, comment = NA, fig.align = 'center', dpi = 100, tidy = F, cache.path = '.cache/', fig.path = 'fig/') + +options(xtable.type = 'html') +knit_hooks$set(inline = function(x) { + if(is.numeric(x)) { + round(x, getOption('digits')) + } else { + paste(as.character(x), collapse = ', ') + } +}) +knit_hooks$set(plot = knitr:::hook_plot_html) +``` + +## About these slides +- These are some practice problems for Statistical Inference Quiz 3 +- They were created using slidify interactive which you will learn in +Creating Data Products +- Please help improve this with pull requests here +(https://github.com/bcaffo/courses) + + + +--- &multitext +Load the data set `mtcars` in the `datasets` R package. Calculate a +95% confidence interval to the nearest MPG. + +1. What is the lower endpoint of the interval? +2. What is the upper endpoint of the interval? + +*** .hint +Do `library(datasets)` and then `data(mtcars)` to get the data. +Consider `t.test` for calculations. You may have to install +the datasets package. + + +*** .explanation +```{r} +library(datasets); data(mtcars) +round(t.test(mtcars$mpg)$conf.int) +``` + +<span class="answer">`r round(min(t.test(mtcars$mpg)$conf.int))`</span> +<span class="answer">`r round(max(t.test(mtcars$mpg)$conf.int))`</span> + +--- &multitext +Suppose that data of 9 paired differences has a standard error of $1$, what value would the average difference have to be to have the lower endpoint of a 95% +students t confidence interval touch zero? + +1. Give the number here to two decimal places + +*** .hint +The t interval is $\bar x t_{.95, 8}\pm s /sqrt{n}$ + +*** .explanation +<span class="answer">`r round(qt(.95, df = 8) * 1 / 3, 2)`</span> + +We want $\bar x = t_{.95} s / sqrt{n}$ +```{r} +round(qt(.95, df = 8) * 1 / 3, 2) +``` + + +--- &radio +An independent group Student's T interval is used over +a paired T interval when: + +1. The observations are paired between the groups. +2. _The observations between the groups are natually assumed to be statistically independent_ +3. As long as you do it correctly, either is fine. +4. More details are needed to answer this question + +*** .hint +A paired interval is for paired observations. + +*** .explanation +We can't pair them if the groups are independent of each other as well as independent within themselves. + + +--- &multitext +Consider the `mtcars` dataset. Construct a 95% T interval for MPG comparing +4 to 6 cylinder cars (subtracting in the order of 4 - 6) +assume a constant variance. + +1. What is the lower endpoint of the interval to 1 decimal place? +2. What is the upper endpoint of the interval to 1 decimal place? + +*** .hint +Use `t.test` with `var.equal=TRUE` + +*** .explanation + +```{r} +m4 <- mtcars$mpg[mtcars$cyl == 4] +m6 <- mtcars$mpg[mtcars$cyl == 6] +#this does 4 - 6 +confint <- as.vector(t.test(m4, m6, var.equal = TRUE)$conf.int) +``` + +<span class="answer">`r round(min(confint), 1)`</span> +<span class="answer">`r round(max(confint), 1)`</span> + + +--- &radio +If someone put a gun to your head and said "Your confidence interval +must contain what it's estimating or I'll pull the trigger", what would +be the smart thing to do? + +1. _Make your interval as wide as possible_ +2. Make your interval as small as possible +3. Call the authorities + +*** .hint +C'mon. You don't need a hint + +*** .explanation +This is just an example of what happens to confidence intervals as you +increase the confidence level. You want to be quite sure in your interval (i.e. +have a large confidence level) and so you would increase the interval's width + +--- &radio + +Refer back to comparing MPG for 4 versus 6 cylinders. What do you conclude? + +1. The interval is above zero, suggesting 6 is better than 4 in the terms of MPG +2. _The interval is above zero, suggesting 4 is better than 6 in the terms of MPG_ +3. The interval does not tell you anything about the hypothesis test; you have to do the test. +4. The interval contains 0 suggesting no difference. + +*** .hint +Refer back to the problem, consider the implications of the interval being +larger than 0, double check the order in which things were subtracted and +make sure the results make sense in the context of the problem. + +*** .explanation +The interval was conducted subtracting 4 - 6 and was entirely above zero. + +--- &multitext +Suppose that 18 obese subjects were randomized, 9 each, to a new diet pill and a placebo. Subjects' body mass indices (BMIs) were measured at a baseline and again after having received the treatment or placebo for four weeks. The average difference from follow-up to the baseline (followup - baseline) was 3 kg/m2 for the treated group and 1 kg/m2 for the placebo group. The corresponding standard deviations of the differences was 1.5 kg/m2 for the treatment group and 1.8 kg/m2 for the placebo group. The study aims to answer whether the change in BMI over the four week period appear to differ between the treated and placebo groups. + +What is the pooled variance estimate? (to 2 decimal places) + + +*** .hint +The sample sizes are equal, so the pooled variance is the average of the +individual variances + + +*** .explanation +```{r} +n1 <- n2 <- 9 +x1 <- -3 ##treated +x2 <- 1 ##placebo +s1 <- 1.5 ##treated +s2 <- 1.8 ##placebo +spsq <- ( (n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2) +``` +<span class="answer">`r round(spsq, 2)`</span> + + +--- &radio + +For Binomial data the maximum likelihood estimate for the probability of +a success is + +1. _The proportion of successes_ +2. The proportion of failures +3. A shrunken version of the proportion of successes +4. A shrunken version of the proportion of failures + +*** .hint +Look back at the notes about likelihood. + +*** .explanation +The MLE for binomial data is always the proportion of successes. + +--- &radio + +Bayesian inference requires + +1. A type I error rate +2. Setting your confidence level +3. _Assigning a prior probability distribution_ +4. Evaluating frequency error rates + +*** .explanation +All of the other answers discuss frequentist concepts. All Bayesian analyses requiring setting a prior. + + diff --git a/06_StatisticalInference/homework/hw3.html b/06_StatisticalInference/homework/hw3.html new file mode 100644 index 000000000..6e54ea85e --- /dev/null +++ b/06_StatisticalInference/homework/hw3.html @@ -0,0 +1,476 @@ +<!DOCTYPE html> +<html> +<head> + <title>Homework 3 for Stat Inference</title> + <meta charset="utf-8"> + <meta name="description" content="Homework 3 for Stat Inference"> + <meta name="author" content="Brian Caffo"> + <meta name="generator" content="slidify" /> + <meta name="apple-mobile-web-app-capable" content="yes"> + <meta http-equiv="X-UA-Compatible" content="chrome=1"> + <link rel="stylesheet" href="libraries/frameworks/io2012/css/default.css" media="all" > + <link rel="stylesheet" href="libraries/frameworks/io2012/css/phone.css" + media="only screen and (max-device-width: 480px)" > + <link rel="stylesheet" href="libraries/frameworks/io2012/css/slidify.css" > + <link rel="stylesheet" href="libraries/highlighters/highlight.js/css/tomorrow.css" /> + <base target="_blank"> <!-- This amazingness opens all links in a new tab. --> <link rel=stylesheet href="libraries/widgets/quiz/css/demo.css"></link> +<link rel=stylesheet href="libraries/widgets/bootstrap/css/bootstrap.css"></link> + + + <!-- Grab CDN jQuery, fall back to local if offline --> + <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script> + <script>window.jQuery || document.write('<script src="libraries/widgets/quiz/js/jquery.js"><\/script>')</script> + <script data-main="libraries/frameworks/io2012/js/slides" + src="libraries/frameworks/io2012/js/require-1.0.8.min.js"> + </script> + + + +</head> +<body style="opacity: 0"> + <slides class="layout-widescreen"> + + <!-- LOGO SLIDE --> + <slide class="title-slide segue nobackground"> + <hgroup class="auto-fadein"> + <h1>Homework 3 for Stat Inference</h1> + <h2>Extra problems for Stat Inference</h2> + <p>Brian Caffo<br/>Johns Hopkins Bloomberg School of Public Health</p> + </hgroup> + <article></article> +</slide> + + + <!-- SLIDES --> + <slide class="" id="slide-1" style="background:;"> + <hgroup> + <h2>About these slides</h2> + </hgroup> + <article data-timings=""> + <ul> +<li>These are some practice problems for Statistical Inference Quiz 3</li> +<li>They were created using slidify interactive which you will learn in +Creating Data Products</li> +<li>Please help improve this with pull requests here +(<a href="https://github.com/bcaffo/courses">https://github.com/bcaffo/courses</a>)</li> +</ul> + + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-2" style="background:;"> + <article data-timings=""> + +<div class="quiz-text quiz-multitext well"> + <p>Load the data set <code>mtcars</code> in the <code>datasets</code> R package. Calculate a +95% confidence interval to the nearest MPG.</p> + +<ol> +<li>What is the lower endpoint of the interval?</li> +<li>What is the upper endpoint of the interval?</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>Do <code>library(datasets)</code> and then <code>data(mtcars)</code> to get the data. +Consider <code>t.test</code> for calculations. You may have to install +the datasets package.</p> + +</div> +<div class="quiz-explanation"> + <pre><code class="r">library(datasets); data(mtcars) +round(t.test(mtcars$mpg)$conf.int) +</code></pre> + +<pre><code>[1] 18 22 +attr(,"conf.level") +[1] 0.95 +</code></pre> + +<p><span class="answer">18</span> +<span class="answer">22</span></p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-3" style="background:;"> + <article data-timings=""> + +<div class="quiz-text quiz-multitext well"> + <p>Suppose that data of 9 paired differences has a standard error of \(1\), what value would the average difference have to be to have the lower endpoint of a 95% +students t confidence interval touch zero?</p> + +<ol> +<li>Give the number here to two decimal places</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>The t interval is \(\bar x t_{.95, 8}\pm s /sqrt{n}\)</p> + +</div> +<div class="quiz-explanation"> + <p><span class="answer">0.62</span></p> + +<p>We want \(\bar x = t_{.95} s / sqrt{n}\)</p> + +<pre><code class="r">round(qt(.95, df = 8) * 1 / 3, 2) +</code></pre> + +<pre><code>[1] 0.62 +</code></pre> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-4" style="background:;"> + <article data-timings=""> + +<div class="quiz quiz-single well "> + <p>An independent group Student's T interval is used over +a paired T interval when:</p> + +<ol> +<li>The observations are paired between the groups.</li> +<li><em>The observations between the groups are natually assumed to be statistically independent</em></li> +<li>As long as you do it correctly, either is fine.</li> +<li>More details are needed to answer this question</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>A paired interval is for paired observations.</p> + +</div> +<div class="quiz-explanation"> + <p>We can't pair them if the groups are independent of each other as well as independent within themselves.</p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-5" style="background:;"> + <article data-timings=""> + +<div class="quiz-text quiz-multitext well"> + <p>Consider the <code>mtcars</code> dataset. Construct a 95% T interval for MPG comparing +4 to 6 cylinder cars (subtracting in the order of 4 - 6) +assume a constant variance.</p> + +<ol> +<li>What is the lower endpoint of the interval to 1 decimal place?</li> +<li>What is the upper endpoint of the interval to 1 decimal place?</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>Use <code>t.test</code> with <code>var.equal=TRUE</code></p> + +</div> +<div class="quiz-explanation"> + <pre><code class="r">m4 <- mtcars$mpg[mtcars$cyl == 4] +m6 <- mtcars$mpg[mtcars$cyl == 6] +#this does 4 - 6 +confint <- as.vector(t.test(m4, m6, var.equal = TRUE)$conf.int) +</code></pre> + +<p><span class="answer">3.2</span> +<span class="answer">10.7</span></p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-6" style="background:;"> + <article data-timings=""> + +<div class="quiz quiz-single well "> + <p>If someone put a gun to your head and said "Your confidence interval +must contain what it's estimating or I'll pull the trigger", what would +be the smart thing to do?</p> + +<ol> +<li><em>Make your interval as wide as possible</em></li> +<li>Make your interval as small as possible</li> +<li>Call the authorities</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>C'mon. You don't need a hint</p> + +</div> +<div class="quiz-explanation"> + <p>This is just an example of what happens to confidence intervals as you +increase the confidence level. You want to be quite sure in your interval (i.e. +have a large confidence level) and so you would increase the interval's width</p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-7" style="background:;"> + <article data-timings=""> + +<div class="quiz quiz-single well "> + <p>Refer back to comparing MPG for 4 versus 6 cylinders. What do you conclude?</p> + +<ol> +<li>The interval is above zero, suggesting 6 is better than 4 in the terms of MPG</li> +<li><em>The interval is above zero, suggesting 4 is better than 6 in the terms of MPG</em></li> +<li>The interval does not tell you anything about the hypothesis test; you have to do the test.</li> +<li>The interval contains 0 suggesting no difference.</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>Refer back to the problem, consider the implications of the interval being +larger than 0, double check the order in which things were subtracted and +make sure the results make sense in the context of the problem.</p> + +</div> +<div class="quiz-explanation"> + <p>The interval was conducted subtracting 4 - 6 and was entirely above zero.</p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-8" style="background:;"> + <article data-timings=""> + +<div class="quiz-text quiz-multitext well"> + <p>Suppose that 18 obese subjects were randomized, 9 each, to a new diet pill and a placebo. Subjects' body mass indices (BMIs) were measured at a baseline and again after having received the treatment or placebo for four weeks. The average difference from follow-up to the baseline (followup - baseline) was 3 kg/m2 for the treated group and 1 kg/m2 for the placebo group. The corresponding standard deviations of the differences was 1.5 kg/m2 for the treatment group and 1.8 kg/m2 for the placebo group. The study aims to answer whether the change in BMI over the four week period appear to differ between the treated and placebo groups. </p> + +<p>What is the pooled variance estimate? (to 2 decimal places)</p> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>The sample sizes are equal, so the pooled variance is the average of the +individual variances</p> + +</div> +<div class="quiz-explanation"> + <pre><code class="r">n1 <- n2 <- 9 +x1 <- -3 ##treated +x2 <- 1 ##placebo +s1 <- 1.5 ##treated +s2 <- 1.8 ##placebo +spsq <- ( (n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2) +</code></pre> + +<p><span class="answer">2.75</span></p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-9" style="background:;"> + <article data-timings=""> + +<div class="quiz quiz-single well "> + <p>For Binomial data the maximum likelihood estimate for the probability of +a success is</p> + +<ol> +<li><em>The proportion of successes</em></li> +<li>The proportion of failures</li> +<li>A shrunken version of the proportion of successes</li> +<li>A shrunken version of the proportion of failures</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-hint"> + <p>Look back at the notes about likelihood.</p> + +</div> +<div class="quiz-explanation"> + <p>The MLE for binomial data is always the proportion of successes.</p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + +<slide class="" id="slide-10" style="background:;"> + <article data-timings=""> + +<div class="quiz quiz-single well "> + <p>Bayesian inference requires</p> + +<ol> +<li>A type I error rate</li> +<li>Setting your confidence level</li> +<li><em>Assigning a prior probability distribution</em></li> +<li>Evaluating frequency error rates</li> +</ol> + + <button class="quiz-submit btn btn-primary">Submit</button> + <button class="quiz-toggle-hint btn btn-info">Show Hint</button> + <button class="quiz-show-answer btn btn-success">Show Answer</button> + <button class="quiz-clear btn btn-danger">Clear</button> + + <div class="quiz-explanation"> + <p>All of the other answers discuss frequentist concepts. All Bayesian analyses requiring setting a prior.</p> + +</div> +</div> + </article> + <!-- Presenter Notes --> +</slide> + + <slide class="backdrop"></slide> + </slides> + <div class="pagination pagination-small" id='io2012-ptoc' style="display:none;"> + <ul> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=1 title='About these slides'> + 1 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=2 title=''> + 2 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=3 title=''> + 3 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=4 title=''> + 4 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=5 title=''> + 5 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=6 title=''> + 6 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=7 title=''> + 7 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=8 title=''> + 8 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=9 title=''> + 9 + </a> + </li> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=10 title=''> + 10 + </a> + </li> + </ul> + </div> <!--[if IE]> + <script + src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"> + </script> + <script>CFInstall.check({mode: 'overlay'});</script> + <![endif]--> +</body> + <!-- Load Javascripts for Widgets --> + <script src="libraries/widgets/quiz/js/jquery.quiz.js"></script> +<script src="libraries/widgets/quiz/js/mustache.min.js"></script> +<script src="libraries/widgets/quiz/js/quiz-app.js"></script> +<script src="libraries/widgets/bootstrap/js/bootstrap.min.js"></script> +<script src="libraries/widgets/bootstrap/js/bootbox.min.js"></script> + + <!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) --> + <script type="text/x-mathjax-config"> + MathJax.Hub.Config({ + tex2jax: { + inlineMath: [['$','$'], ['\\(','\\)']], + processEscapes: true + } + }); + </script> + <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> + </script> --> + <script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>') +</script> +<script> + $(function (){ + $("#example").popover(); + $("[rel='tooltip']").tooltip(); + }); + </script> + <!-- LOAD HIGHLIGHTER JS FILES --> + <script src="libraries/highlighters/highlight.js/highlight.pack.js"></script> + <script>hljs.initHighlightingOnLoad();</script> + <!-- DONE LOADING HIGHLIGHTER JS FILES --> + + </html> \ No newline at end of file diff --git a/06_StatisticalInference/homework/hw3.md b/06_StatisticalInference/homework/hw3.md new file mode 100644 index 000000000..93859ed5b --- /dev/null +++ b/06_StatisticalInference/homework/hw3.md @@ -0,0 +1,210 @@ +--- +title : Homework 3 for Stat Inference +subtitle : Extra problems for Stat Inference +author : Brian Caffo +job : Johns Hopkins Bloomberg School of Public Health +framework : io2012 +highlighter : highlight.js +hitheme : tomorrow +#url: +# lib: ../../librariesNew #Remove new if using old slidify +# assets: ../../assets +widgets : [mathjax, quiz, bootstrap] +mode : selfcontained # {standalone, draft} +--- + + + +## About these slides +- These are some practice problems for Statistical Inference Quiz 3 +- They were created using slidify interactive which you will learn in +Creating Data Products +- Please help improve this with pull requests here +(https://github.com/bcaffo/courses) + + + +--- &multitext +Load the data set `mtcars` in the `datasets` R package. Calculate a +95% confidence interval to the nearest MPG. + +1. What is the lower endpoint of the interval? +2. What is the upper endpoint of the interval? + +*** .hint +Do `library(datasets)` and then `data(mtcars)` to get the data. +Consider `t.test` for calculations. You may have to install +the datasets package. + + +*** .explanation + +```r +library(datasets); data(mtcars) +round(t.test(mtcars$mpg)$conf.int) +``` + +``` +[1] 18 22 +attr(,"conf.level") +[1] 0.95 +``` + + +<span class="answer">18</span> +<span class="answer">22</span> + +--- &multitext +Suppose that data of 9 paired differences has a standard error of $1$, what value would the average difference have to be to have the lower endpoint of a 95% +students t confidence interval touch zero? + +1. Give the number here to two decimal places + +*** .hint +The t interval is $\bar x t_{.95, 8}\pm s /sqrt{n}$ + +*** .explanation +<span class="answer">0.62</span> + +We want $\bar x = t_{.95} s / sqrt{n}$ + +```r +round(qt(.95, df = 8) * 1 / 3, 2) +``` + +``` +[1] 0.62 +``` + + + +--- &radio +An independent group Student's T interval is used over +a paired T interval when: + +1. The observations are paired between the groups. +2. _The observations between the groups are natually assumed to be statistically independent_ +3. As long as you do it correctly, either is fine. +4. More details are needed to answer this question + +*** .hint +A paired interval is for paired observations. + +*** .explanation +We can't pair them if the groups are independent of each other as well as independent within themselves. + + +--- &multitext +Consider the `mtcars` dataset. Construct a 95% T interval for MPG comparing +4 to 6 cylinder cars (subtracting in the order of 4 - 6) +assume a constant variance. + +1. What is the lower endpoint of the interval to 1 decimal place? +2. What is the upper endpoint of the interval to 1 decimal place? + +*** .hint +Use `t.test` with `var.equal=TRUE` + +*** .explanation + + +```r +m4 <- mtcars$mpg[mtcars$cyl == 4] +m6 <- mtcars$mpg[mtcars$cyl == 6] +#this does 4 - 6 +confint <- as.vector(t.test(m4, m6, var.equal = TRUE)$conf.int) +``` + + +<span class="answer">3.2</span> +<span class="answer">10.7</span> + + +--- &radio +If someone put a gun to your head and said "Your confidence interval +must contain what it's estimating or I'll pull the trigger", what would +be the smart thing to do? + +1. _Make your interval as wide as possible_ +2. Make your interval as small as possible +3. Call the authorities + +*** .hint +C'mon. You don't need a hint + +*** .explanation +This is just an example of what happens to confidence intervals as you +increase the confidence level. You want to be quite sure in your interval (i.e. +have a large confidence level) and so you would increase the interval's width + +--- &radio + +Refer back to comparing MPG for 4 versus 6 cylinders. What do you conclude? + +1. The interval is above zero, suggesting 6 is better than 4 in the terms of MPG +2. _The interval is above zero, suggesting 4 is better than 6 in the terms of MPG_ +3. The interval does not tell you anything about the hypothesis test; you have to do the test. +4. The interval contains 0 suggesting no difference. + +*** .hint +Refer back to the problem, consider the implications of the interval being +larger than 0, double check the order in which things were subtracted and +make sure the results make sense in the context of the problem. + +*** .explanation +The interval was conducted subtracting 4 - 6 and was entirely above zero. + +--- &multitext +Suppose that 18 obese subjects were randomized, 9 each, to a new diet pill and a placebo. Subjects' body mass indices (BMIs) were measured at a baseline and again after having received the treatment or placebo for four weeks. The average difference from follow-up to the baseline (followup - baseline) was 3 kg/m2 for the treated group and 1 kg/m2 for the placebo group. The corresponding standard deviations of the differences was 1.5 kg/m2 for the treatment group and 1.8 kg/m2 for the placebo group. The study aims to answer whether the change in BMI over the four week period appear to differ between the treated and placebo groups. + +What is the pooled variance estimate? (to 2 decimal places) + + +*** .hint +The sample sizes are equal, so the pooled variance is the average of the +individual variances + + +*** .explanation + +```r +n1 <- n2 <- 9 +x1 <- -3 ##treated +x2 <- 1 ##placebo +s1 <- 1.5 ##treated +s2 <- 1.8 ##placebo +spsq <- ( (n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2) +``` + +<span class="answer">2.75</span> + + +--- &radio + +For Binomial data the maximum likelihood estimate for the probability of +a success is + +1. _The proportion of successes_ +2. The proportion of failures +3. A shrunken version of the proportion of successes +4. A shrunken version of the proportion of failures + +*** .hint +Look back at the notes about likelihood. + +*** .explanation +The MLE for binomial data is always the proportion of successes. + +--- &radio + +Bayesian inference requires + +1. A type I error rate +2. Setting your confidence level +3. _Assigning a prior probability distribution_ +4. Evaluating frequency error rates + +*** .explanation +All of the other answers discuss frequentist concepts. All Bayesian analyses requiring setting a prior. + + diff --git a/06_StatisticalInference/homework/hw4.Rmd b/06_StatisticalInference/homework/hw4.Rmd new file mode 100644 index 000000000..bf5a8da3b --- /dev/null +++ b/06_StatisticalInference/homework/hw4.Rmd @@ -0,0 +1,37 @@ +--- +title : Homework 4 for Stat Inference +subtitle : Extra problems for Stat Inference +author : Brian Caffo +job : Johns Hopkins Bloomberg School of Public Health +framework : io2012 +highlighter : highlight.js +hitheme : tomorrow +#url: +# lib: ../../librariesNew #Remove new if using old slidify +# assets: ../../assets +widgets : [mathjax, quiz, bootstrap] +mode : selfcontained # {standalone, draft} +--- +```{r setup, cache = F, echo = F, message = F, warning = F, tidy = F, results='hide'} +# make this an external chunk that can be included in any file +library(knitr) +options(width = 100) +opts_chunk$set(message = F, error = F, warning = F, comment = NA, fig.align = 'center', dpi = 100, tidy = F, cache.path = '.cache/', fig.path = 'fig/') + +options(xtable.type = 'html') +knit_hooks$set(inline = function(x) { + if(is.numeric(x)) { + round(x, getOption('digits')) + } else { + paste(as.character(x), collapse = ', ') + } +}) +knit_hooks$set(plot = knitr:::hook_plot_html) +``` + +## About these slides +- These are some practice problems for Statistical Inference Quiz 4 +- They were created using slidify interactive which you will learn in +Creating Data Products +- Please help improve this with pull requests here +(https://github.com/bcaffo/courses) diff --git a/06_StatisticalInference/homework/hw4.html b/06_StatisticalInference/homework/hw4.html new file mode 100644 index 000000000..565621a6d --- /dev/null +++ b/06_StatisticalInference/homework/hw4.html @@ -0,0 +1,112 @@ +<!DOCTYPE html> +<html> +<head> + <title>Homework 4 for Stat Inference</title> + <meta charset="utf-8"> + <meta name="description" content="Homework 4 for Stat Inference"> + <meta name="author" content="Brian Caffo"> + <meta name="generator" content="slidify" /> + <meta name="apple-mobile-web-app-capable" content="yes"> + <meta http-equiv="X-UA-Compatible" content="chrome=1"> + <link rel="stylesheet" href="libraries/frameworks/io2012/css/default.css" media="all" > + <link rel="stylesheet" href="libraries/frameworks/io2012/css/phone.css" + media="only screen and (max-device-width: 480px)" > + <link rel="stylesheet" href="libraries/frameworks/io2012/css/slidify.css" > + <link rel="stylesheet" href="libraries/highlighters/highlight.js/css/tomorrow.css" /> + <base target="_blank"> <!-- This amazingness opens all links in a new tab. --> <link rel=stylesheet href="libraries/widgets/quiz/css/demo.css"></link> +<link rel=stylesheet href="libraries/widgets/bootstrap/css/bootstrap.css"></link> + + + <!-- Grab CDN jQuery, fall back to local if offline --> + <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script> + <script>window.jQuery || document.write('<script src="libraries/widgets/quiz/js/jquery.js"><\/script>')</script> + <script data-main="libraries/frameworks/io2012/js/slides" + src="libraries/frameworks/io2012/js/require-1.0.8.min.js"> + </script> + + + +</head> +<body style="opacity: 0"> + <slides class="layout-widescreen"> + + <!-- LOGO SLIDE --> + <slide class="title-slide segue nobackground"> + <hgroup class="auto-fadein"> + <h1>Homework 4 for Stat Inference</h1> + <h2>Extra problems for Stat Inference</h2> + <p>Brian Caffo<br/>Johns Hopkins Bloomberg School of Public Health</p> + </hgroup> + <article></article> +</slide> + + + <!-- SLIDES --> + <slide class="" id="slide-1" style="background:;"> + <hgroup> + <h2>About these slides</h2> + </hgroup> + <article data-timings=""> + <ul> +<li>These are some practice problems for Statistical Inference Quiz 4</li> +<li>They were created using slidify interactive which you will learn in +Creating Data Products</li> +<li>Please help improve this with pull requests here +(<a href="https://github.com/bcaffo/courses">https://github.com/bcaffo/courses</a>)</li> +</ul> + + </article> + <!-- Presenter Notes --> +</slide> + + <slide class="backdrop"></slide> + </slides> + <div class="pagination pagination-small" id='io2012-ptoc' style="display:none;"> + <ul> + <li> + <a href="#" target="_self" rel='tooltip' + data-slide=1 title='About these slides'> + 1 + </a> + </li> + </ul> + </div> <!--[if IE]> + <script + src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"> + </script> + <script>CFInstall.check({mode: 'overlay'});</script> + <![endif]--> +</body> + <!-- Load Javascripts for Widgets --> + <script src="libraries/widgets/quiz/js/jquery.quiz.js"></script> +<script src="libraries/widgets/quiz/js/mustache.min.js"></script> +<script src="libraries/widgets/quiz/js/quiz-app.js"></script> +<script src="libraries/widgets/bootstrap/js/bootstrap.min.js"></script> +<script src="libraries/widgets/bootstrap/js/bootbox.min.js"></script> + + <!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) --> + <script type="text/x-mathjax-config"> + MathJax.Hub.Config({ + tex2jax: { + inlineMath: [['$','$'], ['\\(','\\)']], + processEscapes: true + } + }); + </script> + <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> + </script> --> + <script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>') +</script> +<script> + $(function (){ + $("#example").popover(); + $("[rel='tooltip']").tooltip(); + }); + </script> + <!-- LOAD HIGHLIGHTER JS FILES --> + <script src="libraries/highlighters/highlight.js/highlight.pack.js"></script> + <script>hljs.initHighlightingOnLoad();</script> + <!-- DONE LOADING HIGHLIGHTER JS FILES --> + + </html> \ No newline at end of file diff --git a/06_StatisticalInference/homework/hw4.md b/06_StatisticalInference/homework/hw4.md new file mode 100644 index 000000000..a22e64543 --- /dev/null +++ b/06_StatisticalInference/homework/hw4.md @@ -0,0 +1,23 @@ +--- +title : Homework 4 for Stat Inference +subtitle : Extra problems for Stat Inference +author : Brian Caffo +job : Johns Hopkins Bloomberg School of Public Health +framework : io2012 +highlighter : highlight.js +hitheme : tomorrow +#url: +# lib: ../../librariesNew #Remove new if using old slidify +# assets: ../../assets +widgets : [mathjax, quiz, bootstrap] +mode : selfcontained # {standalone, draft} +--- + + + +## About these slides +- These are some practice problems for Statistical Inference Quiz 4 +- They were created using slidify interactive which you will learn in +Creating Data Products +- Please help improve this with pull requests here +(https://github.com/bcaffo/courses) diff --git a/08_PracticalMachineLearning/019predictingWithTrees/index.Rmd b/08_PracticalMachineLearning/019predictingWithTrees/index.Rmd index a3cccb90f..1c4dc6e20 100644 --- a/08_PracticalMachineLearning/019predictingWithTrees/index.Rmd +++ b/08_PracticalMachineLearning/019predictingWithTrees/index.Rmd @@ -124,7 +124,7 @@ plot(x,y,xaxt="n",yaxt="n",cex=3,col=c(rep("blue",8),rep("red",8)),pch=19) * __Misclassification:__ $8/16 = 0.5$ * __Gini:__ $1 - [(8/16)^2 + (8/16)^2] = 0.5$ -* __Information:__$-[1/16 \times log2(1/16) + 15/16 \times log2(15/16)] = 1$ +* __Information:__$-[8/16 \times log2(8/16) + 8/16 \times log2(8/16)] = 1$ diff --git a/08_PracticalMachineLearning/025combiningPredictors/index.Rmd b/08_PracticalMachineLearning/025combiningPredictors/index.Rmd index 958b2c4d8..ca6ec2f93 100644 --- a/08_PracticalMachineLearning/025combiningPredictors/index.Rmd +++ b/08_PracticalMachineLearning/025combiningPredictors/index.Rmd @@ -67,7 +67,7 @@ BellKor = Combination of 107 predictors Suppose we have 5 completely independent classifiers If accuracy is 70% for each: - * $10\times(0.7)^3(0.3)^2 + 5\times(0.7)^4(0.3)^2 + (0.7)^5$ + * $10\times(0.7)^3(0.3)^2 + 5\times(0.7)^4(0.3)^1 + (0.7)^5$ * 83.7% majority vote accuracy With 101 independent classifiers diff --git a/09_DevelopingDataProducts/rStudioPresent/index.Rpres b/09_DevelopingDataProducts/rStudioPresent/index.Rpres index a237721f7..00c9487c7 100644 --- a/09_DevelopingDataProducts/rStudioPresent/index.Rpres +++ b/09_DevelopingDataProducts/rStudioPresent/index.Rpres @@ -1,132 +1,132 @@ -RStudio Presenter -=== -author: Brian Caffo, Jeff Leek Roger Peng -date: `r format(Sys.Date(), format="%B %d %Y")` -transition: rotate - -<small> -Department of Biostatistics -Bloomberg School of Public Health -Johns Hopkins University -Coursera Data Science Specialization -</small> - - -RStudio Presentation -=== -- RStudio created a presentation authoring tool within their -development environment. -- If you are familiar with slidify, you will also be familiar with this tool - - Code is authored in a generalized markdown format that allows for code chunks - - The output is an html5 presentation - - The file index for the presenter file is .Rpres, which gets converted to an .md file and then to an html file if desired - - There's a preview tool in RStudio and GUIs for publishing to Rpubs or viewing/creating an html file - -Authoring content -=== -- This is a fairly complete guide - - http://www.rstudio.com/ide/docs/presentations/overview -- Quick start is - - `file` then `New File` then `R Presentation` - - (`alt-f` then `f` then `p` if you want key strokes) - - Use basically the same R markdown format for authoring as slidify/knitr - - Single quotes for inline code - - Tripple qutoes for block code - - Same options for code evaluation, caching, hiding etcetera - -Compiling and tools -=== -- R Studio auto formats and runs the code when you save the document -- Mathjax JS library is loaded by default so that `$x^2$` yields $x^2$ -- Slide navigation button on the preview; clicking on the notepad icon takes you to that slide in the deck -- Clicking on `more` yields options for - - Clearning the knitr cache - - Viewing in a browser (creates a temporay html file in `AppData/local/temp` for me) - - Create a html file to save where you want) -- A refresh button -- A zoom button that brings up a full window - -Visuals -=== -transition: linear - -- R Studio has made it easy to get some cool html5 effects, like cube transitions -with simple options in YAML-like code after the first slide such as -`transition: rotate` -- You can specify it in a slide-by-slide basis - -Here's the option "linear" -=== -transition: linear - -- Just put `transition: linear` right after the slide creation (three equal signs or more in a row) -- Tansition options - - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation - -Hierarchical organization -=== -type: section -- If you want a hierarchical organization structure, just add a `type: typename` option after the slide -- This changes the default appearance - - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation -- This is of type `section` - -Here's a subsection -=== -type: subsection - -Two columns -=== -- Do whatever for column one -- Then put `***` on a line by itself with blank lines before and after - -*** - -- Then do whatever for column two - - -Changing the slide font -========================================================== -font-import: http://fonts.googleapis.com/css?family=Risque -font-family: 'Risque' - -- Add a `font-family: fontname` option after the slide - - http://www.rstudio.com/ide/docs/presentations/customizing_fonts_and_appearance -- Specified in the same way as css font families - - http://www.w3schools.com/cssref/css_websafe_fonts.asp -- Use `font-import: url` to import fonts -- Important caveats - - Fonts must be present on the system that you're presenting on, or it will go to a fallback font - - You have to be connected to the internet to use an imported font (so don't rely on this for offline presentations) -- This is the `Risque` - - http://fonts.googleapis.com/css?family=Risque - -Really changing things -=== -- If you know html5 and CSS well, then you can basically change whatever you want -- A css file with the same names as your presentation will be autoimported -- You can use `css: file.css` to import a css file -- You have to create named classes and then use `class: classname` to get slide-specific style control from your css - - (Or you can apply then within a `<span>`) -- Ultimately, you have an html file, that you can edit as you wish - - This should be viewed as a last resort, as the whole point is to have reproducible presentations, but may be the easiest way to get the exact style control you want for a final product - -Slidify versus R Studio Presenter -=== -**Slidify** -- Flexible control from the R MD file -- Under rapid ongoing development -- Large user base -- Lots and lots of styles and options -- Steeper learning curve -- More command-line oriented - -*** -**R Studio Presenter** -- Embedded in R Studio -- More GUI oriented -- Very easy to get started -- Smaller set of easy styles and options -- Default styles look very nice -- Ultimately as flexible as slidify with a little CSS and HTML knowledge - +RStudio Presenter +=== +author: Brian Caffo, Jeff Leek Roger Peng +date: `r format(Sys.Date(), format="%B %d %Y")` +transition: rotate + +<small> +Department of Biostatistics +Bloomberg School of Public Health +Johns Hopkins University +Coursera Data Science Specialization +</small> + + +RStudio Presentation +=== +- RStudio created a presentation authoring tool within their +development environment. +- If you are familiar with slidify, you will also be familiar with this tool + - Code is authored in a generalized markdown format that allows for code chunks + - The output is an html5 presentation + - The file index for the presenter file is .Rpres, which gets converted to an .md file and then to an html file if desired + - There's a preview tool in RStudio and GUIs for publishing to Rpubs or viewing/creating an html file + +Authoring content +=== +- This is a fairly complete guide + - http://www.rstudio.com/ide/docs/presentations/overview +- Quick start is + - `file` then `New File` then `R Presentation` + - (`alt-f` then `f` then `p` if you want key strokes) + - Use basically the same R markdown format for authoring as slidify/knitr + - Single quotes for inline code + - Tripple qutoes for block code + - Same options for code evaluation, caching, hiding etcetera + +Compiling and tools +=== +- R Studio auto formats and runs the code when you save the document +- Mathjax JS library is loaded by default so that `$x^2$` yields $x^2$ +- Slide navigation button on the preview; clicking on the notepad icon takes you to that slide in the deck +- Clicking on `more` yields options for + - Clearning the knitr cache + - Viewing in a browser (creates a temporay html file in `AppData/local/temp` for me) + - Create a html file to save where you want) +- A refresh button +- A zoom button that brings up a full window + +Visuals +=== +transition: linear + +- R Studio has made it easy to get some cool html5 effects, like cube transitions +with simple options in YAML-like code after the first slide such as +`transition: rotate` +- You can specify it in a slide-by-slide basis + +Here's the option "linear" +=== +transition: linear + +- Just put `transition: linear` right after the slide creation (three equal signs or more in a row) +- Tansition options + - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation + +Hierarchical organization +=== +type: section +- If you want a hierarchical organization structure, just add a `type: typename` option after the slide +- This changes the default appearance + - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation +- This is of type `section` + +Here's a subsection +=== +type: subsection + +Two columns +=== +- Do whatever for column one +- Then put `***` on a line by itself with blank lines before and after + +*** + +- Then do whatever for column two + + +Changing the slide font +========================================================== +font-import: http://fonts.googleapis.com/css?family=Risque +font-family: 'Risque' + +- Add a `font-family: fontname` option after the slide + - http://www.rstudio.com/ide/docs/presentations/customizing_fonts_and_appearance +- Specified in the same way as css font families + - http://www.w3schools.com/cssref/css_websafe_fonts.asp +- Use `font-import: url` to import fonts +- Important caveats + - Fonts must be present on the system that you're presenting on, or it will go to a fallback font + - You have to be connected to the internet to use an imported font (so don't rely on this for offline presentations) +- This is the `Risque` + - http://fonts.googleapis.com/css?family=Risque + +Really changing things +=== +- If you know html5 and CSS well, then you can basically change whatever you want +- A css file with the same names as your presentation will be autoimported +- You can use `css: file.css` to import a css file +- You have to create named classes and then use `class: classname` to get slide-specific style control from your css + - (Or you can apply then within a `<span>`) +- Ultimately, you have an html file, that you can edit as you wish + - This should be viewed as a last resort, as the whole point is to have reproducible presentations, but may be the easiest way to get the exact style control you want for a final product + +Slidify versus R Studio Presenter +=== +**Slidify** +- Flexible control from the R MD file +- Under rapid ongoing development +- Large user base +- Lots and lots of styles and options +- Steeper learning curve +- More command-line oriented + +*** +**R Studio Presenter** +- Embedded in R Studio +- More GUI oriented +- Very easy to get started +- Smaller set of easy styles and options +- Default styles look very nice +- Ultimately as flexible as slidify with a little CSS and HTML knowledge + diff --git a/09_DevelopingDataProducts/rStudioPresent/index.md b/09_DevelopingDataProducts/rStudioPresent/index.md index 399fb071a..b998542ae 100644 --- a/09_DevelopingDataProducts/rStudioPresent/index.md +++ b/09_DevelopingDataProducts/rStudioPresent/index.md @@ -1,132 +1,132 @@ -RStudio Presenter -=== -author: Brian Caffo, Jeff Leek Roger Peng -date: April 24 2014 -transition: rotate - -<small> -Department of Biostatistics -Bloomberg School of Public Health -Johns Hopkins University -Coursera Data Science Specialization -</small> - - -RStudio Presentation -=== -- RStudio created a presentation authoring tool within their -development environment. -- If you are familiar with slidify, you will also be familiar with this tool - - Code is authored in a generalized markdown format that allows for code chunks - - The output is an html5 presentation - - The file index for the presenter file is .Rpres, which gets converted to an .md file and then to an html file if desired - - There's a preview tool in RStudio and GUIs for publishing to Rpubs or viewing/creating an html file - -Authoring content -=== -- This is a fairly complete guide - - http://www.rstudio.com/ide/docs/presentations/overview -- Quick start is - - `file` then `New File` then `R Presentation` - - (`alt-f` then `f` then `p` if you want key strokes) - - Use basically the same R markdown format for authoring as slidify/knitr - - Single quotes for inline code - - Tripple qutoes for block code - - Same options for code evaluation, caching, hiding etcetera - -Compiling and tools -=== -- R Studio auto formats and runs the code when you save the document -- Mathjax JS library is loaded by default so that `$x^2$` yields $x^2$ -- Slide navigation button on the preview; clicking on the notepad icon takes you to that slide in the deck -- Clicking on `more` yields options for - - Clearning the knitr cache - - Viewing in a browser (creates a temporay html file in `AppData/local/temp` for me) - - Create a html file to save where you want) -- A refresh button -- A zoom button that brings up a full window - -Visuals -=== -transition: linear - -- R Studio has made it easy to get some cool html5 effects, like cube transitions -with simple options in YAML-like code after the first slide such as -`transition: rotate` -- You can specify it in a slide-by-slide basis - -Here's the option "linear" -=== -transition: linear - -- Just put `transition: linear` right after the slide creation (three equal signs or more in a row) -- Tansition options - - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation - -Hierarchical organization -=== -type: section -- If you want a hierarchical organization structure, just add a `type: typename` option after the slide -- This changes the default appearance - - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation -- This is of type `section` - -Here's a subsection -=== -type: subsection - -Two columns -=== -- Do whatever for column one -- Then put `***` on a line by itself with blank lines before and after - -*** - -- Then do whatever for column two - - -Changing the slide font -========================================================== -font-import: http://fonts.googleapis.com/css?family=Risque -font-family: 'Risque' - -- Add a `font-family: fontname` option after the slide - - http://www.rstudio.com/ide/docs/presentations/customizing_fonts_and_appearance -- Specified in the same way as css font families - - http://www.w3schools.com/cssref/css_websafe_fonts.asp -- Use `font-import: url` to import fonts -- Important caveats - - Fonts must be present on the system that you're presenting on, or it will go to a fallback font - - You have to be connected to the internet to use an imported font (so don't rely on this for offline presentations) -- This is the `Risque` - - http://fonts.googleapis.com/css?family=Risque - -Really changing things -=== -- If you know html5 and CSS well, then you can basically change whatever you want -- A css file with the same names as your presentation will be autoimported -- You can use `css: file.css` to import a css file -- You have to create named classes and then use `class: classname` to get slide-specific style control from your css - - (Or you can apply then within a `<span>`) -- Ultimately, you have an html file, that you can edit as you wish - - This should be viewed as a last resort, as the whole point is to have reproducible presentations, but may be the easiest way to get the exact style control you want for a final product - -Slidify versus R Studio Presenter -=== -**Slidify** -- Flexible control from the R MD file -- Under rapid ongoing development -- Large user base -- Lots and lots of styles and options -- Steeper learning curve -- More command-line oriented - -*** -**R Studio Presenter** -- Embedded in R Studio -- More GUI oriented -- Very easy to get started -- Smaller set of easy styles and options -- Default styles look very nice -- Ultimately as flexible as slidify with a little CSS and HTML knowledge - +RStudio Presenter +=== +author: Brian Caffo, Jeff Leek Roger Peng +date: May 21 2014 +transition: rotate + +<small> +Department of Biostatistics +Bloomberg School of Public Health +Johns Hopkins University +Coursera Data Science Specialization +</small> + + +RStudio Presentation +=== +- RStudio created a presentation authoring tool within their +development environment. +- If you are familiar with slidify, you will also be familiar with this tool + - Code is authored in a generalized markdown format that allows for code chunks + - The output is an html5 presentation + - The file index for the presenter file is .Rpres, which gets converted to an .md file and then to an html file if desired + - There's a preview tool in RStudio and GUIs for publishing to Rpubs or viewing/creating an html file + +Authoring content +=== +- This is a fairly complete guide + - http://www.rstudio.com/ide/docs/presentations/overview +- Quick start is + - `file` then `New File` then `R Presentation` + - (`alt-f` then `f` then `p` if you want key strokes) + - Use basically the same R markdown format for authoring as slidify/knitr + - Single quotes for inline code + - Tripple qutoes for block code + - Same options for code evaluation, caching, hiding etcetera + +Compiling and tools +=== +- R Studio auto formats and runs the code when you save the document +- Mathjax JS library is loaded by default so that `$x^2$` yields $x^2$ +- Slide navigation button on the preview; clicking on the notepad icon takes you to that slide in the deck +- Clicking on `more` yields options for + - Clearning the knitr cache + - Viewing in a browser (creates a temporay html file in `AppData/local/temp` for me) + - Create a html file to save where you want) +- A refresh button +- A zoom button that brings up a full window + +Visuals +=== +transition: linear + +- R Studio has made it easy to get some cool html5 effects, like cube transitions +with simple options in YAML-like code after the first slide such as +`transition: rotate` +- You can specify it in a slide-by-slide basis + +Here's the option "linear" +=== +transition: linear + +- Just put `transition: linear` right after the slide creation (three equal signs or more in a row) +- Tansition options + - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation + +Hierarchical organization +=== +type: section +- If you want a hierarchical organization structure, just add a `type: typename` option after the slide +- This changes the default appearance + - http://www.rstudio.com/ide/docs/presentations/slide_transitions_and_navigation +- This is of type `section` + +Here's a subsection +=== +type: subsection + +Two columns +=== +- Do whatever for column one +- Then put `***` on a line by itself with blank lines before and after + +*** + +- Then do whatever for column two + + +Changing the slide font +========================================================== +font-import: http://fonts.googleapis.com/css?family=Risque +font-family: 'Risque' + +- Add a `font-family: fontname` option after the slide + - http://www.rstudio.com/ide/docs/presentations/customizing_fonts_and_appearance +- Specified in the same way as css font families + - http://www.w3schools.com/cssref/css_websafe_fonts.asp +- Use `font-import: url` to import fonts +- Important caveats + - Fonts must be present on the system that you're presenting on, or it will go to a fallback font + - You have to be connected to the internet to use an imported font (so don't rely on this for offline presentations) +- This is the `Risque` + - http://fonts.googleapis.com/css?family=Risque + +Really changing things +=== +- If you know html5 and CSS well, then you can basically change whatever you want +- A css file with the same names as your presentation will be autoimported +- You can use `css: file.css` to import a css file +- You have to create named classes and then use `class: classname` to get slide-specific style control from your css + - (Or you can apply then within a `<span>`) +- Ultimately, you have an html file, that you can edit as you wish + - This should be viewed as a last resort, as the whole point is to have reproducible presentations, but may be the easiest way to get the exact style control you want for a final product + +Slidify versus R Studio Presenter +=== +**Slidify** +- Flexible control from the R MD file +- Under rapid ongoing development +- Large user base +- Lots and lots of styles and options +- Steeper learning curve +- More command-line oriented + +*** +**R Studio Presenter** +- Embedded in R Studio +- More GUI oriented +- Very easy to get started +- Smaller set of easy styles and options +- Default styles look very nice +- Ultimately as flexible as slidify with a little CSS and HTML knowledge +