% \documentclass[serif]{beamer} % Serif for Computer Modern math font. \documentclass[serif, handout]{beamer} % Handout to ignore pause statements \hypersetup{colorlinks,linkcolor=,urlcolor=red} \usefonttheme{serif} % Looks like Computer Modern for non-math text -- nice! \setbeamertemplate{navigation symbols}{} % Suppress navigation symbols % \usetheme{Berlin} % Displays sections on top \usetheme{Frankfurt} % Displays section titles on top: Fairly thin but still swallows some material at bottom of crowded slides %\usetheme{Berkeley} \usepackage[english]{babel} \usepackage{amsmath} % for binom % \usepackage{graphicx} % To include pdf files! % \definecolor{links}{HTML}{2A1B81} % \definecolor{links}{red} \setbeamertemplate{footline}[frame number] \mode \title{Using R as a Calculator (on the final exam)\footnote{ This slide show is an open-source document. See last slide for copyright information.}} \subtitle{STA 260 Spring 2020} \date{} % To suppress date \begin{document} \begin{frame} \titlepage \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{R is a wonderful calculator} %\framesubtitle{} \begin{itemize} \item You are going to have access to a computer during the final exam anyway. \item Even a cell phone will do. \item You may already have it and know how to use it. \pause \item Free download at \href{https://www.r-project.org} {\small\texttt{https://www.r-project.org}} \item Run free online at \href{https://rdrr.io/snippets} {\small\texttt{https://rdrr.io/snippets}} \end{itemize} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{R is a Basic Calculator} \framesubtitle{} \pause {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > 1+1 \end{verbatim} } % End color \begin{verbatim} [1] 2 \end{verbatim} \pause {\color{blue} \begin{verbatim} > 1:40 \end{verbatim} } % End color \begin{verbatim} [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [21] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{R is an advanced calculator} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > n = 50; xbar = 1.56 > Gsq = 2*n*(xbar*log(xbar) - (1+xbar)*(log(1+xbar)-log(2))); Gsq \end{verbatim} } % End color \begin{verbatim} [1] 6.174808 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{No More Tables} %\framesubtitle{} We will use R for CDFs and quantiles of all the familiar distributions. \pause \begin{itemize} \item Critical values. \item $p$-values. \item Posterior probabilities. \end{itemize} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Normal Distribution} \framesubtitle{Faster than the table} \pause {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > pnorm(0) # CDF of standard normal \end{verbatim} } % End color \begin{verbatim} [1] 0.5 \end{verbatim} \pause } % End size You can specify $\mu$ and $\sigma$ (not $\sigma^2$). \pause \vspace{2mm} IQ tests are designed to have $\mu=100$ and $\sigma=15$. What's $P(IQ>160)$? \pause {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} 1 - pnorm(160,mean=100,sd=15) # Or just pnorm(160,100,15) \end{verbatim} } % End color \begin{verbatim} [1] 3.167124e-05 \end{verbatim} \pause {\color{blue} \begin{verbatim} > options(scipen=999) # Supress scientific notation > 1 - pnorm(160,mean=100,sd=15) \end{verbatim} } % End color \begin{verbatim} [1] 0.00003167124 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Quantiles} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > qnorm(0.975) \end{verbatim} } % End color \begin{verbatim} [1] 1.959964 \end{verbatim} \pause {\color{blue} \begin{verbatim} > # An IQ of ___ is higher than 90% of the population, > qnorm(0.90,100,15) # q for quantile \end{verbatim} } % End color \begin{verbatim} [1] 119.2233 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{$\chi^2$ Distribution} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > n = 50; xbar = 1.56 > Gsq = 2*n*(xbar*log(xbar) - (1+xbar)*(log(1+xbar)-log(2))); Gsq \end{verbatim} } % End color \begin{verbatim} [1] 6.174808 \end{verbatim} \pause {\color{blue} \begin{verbatim} > 1-pchisq(Gsq,df=1) # p-value \end{verbatim} } % End color \begin{verbatim} [1] 0.0129582 \end{verbatim} \pause {\color{blue} \begin{verbatim} > qchisq(0.95,1) # Critical value at alpha = 0.05 \end{verbatim} } % End color \begin{verbatim} [1] 3.841459 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{$t$ distribution} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > 2*(1 - pt(2.14,df=10) ) # Two-tailed p-value \end{verbatim} } % End color \begin{verbatim} [1] 0.05803497 \end{verbatim} \pause {\color{blue} \begin{verbatim} > qt(0.975,df=10) # Critical value \end{verbatim} } % End color \begin{verbatim} [1] 2.228139 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{$F$ Distribution} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > 1 - pf(3.17,6,114) \end{verbatim} } % End color \begin{verbatim} [1] 0.006504761 \end{verbatim} \pause {\color{blue} \begin{verbatim} > qf(0.95,6,114) # Not in the table \end{verbatim} } % End color \begin{verbatim} [1] 2.1791 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Gamma with $\alpha=$shape, $\lambda=$rate} \pause %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > pgamma(1,shape=21,rate=23.35) # P(Lambda < 1 |x) \end{verbatim} } % End color \begin{verbatim} [1] 0.7146466 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Beta Distribution} %\framesubtitle{} For the coffee taste test, 60/100 consumers chose the new blend of coffee beans, yielding $\alpha^\prime = \alpha + \sum_{i=1}^nx_i = 61$ and $\beta^\prime = \beta + n-\sum_{i=1}^nx_i = 41$. \pause \vspace{5mm} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > pbeta(1/2,61,41) \end{verbatim} } % End color \begin{verbatim} [1] 0.02302203 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Binomial Distribution} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > # 20-question abcd multiple choice, probability of passing > 1 - pbinom(9,20,0.25) \end{verbatim} } % End color \begin{verbatim} [1] 0.01386442 \end{verbatim} \pause {\color{blue} \begin{verbatim} > # Probability of exactly 50 heads in 100 tosses of a fair coin > dbinom(50,100,0.5) \end{verbatim} } % End color \begin{verbatim} [1] 0.07958924 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile] \frametitle{Poisson Distribution} %\framesubtitle{} If there are really only a population mean of 8 rat hairs in a peanut butter jar, what is the probability of obtaining a sample mean of 9.2 (or more) from a random sample of 30 jars? \pause Distribution of $S = \sum_{i=1}^nX_i$ is Poisson$(30*8)$. \pause {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} > 9.2*30 \end{verbatim} } % End color \begin{verbatim} [1] 276 \end{verbatim} \pause {\color{blue} \begin{verbatim} > 1 - ppois(275,240) # P(S geq 276) \end{verbatim} } % End color \begin{verbatim} [1] 0.01226396 \end{verbatim} } % End size \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame} \frametitle{Copyright Information} This slide show was prepared by \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner}, Department of Mathematical and Computational Sciences, University of Toronto Mississauga. It is licensed under a \href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US} {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website: \vspace{5mm} \href{http://www.utstat.toronto.edu/~brunner/oldclass/260s20} {\small\texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/260s20}} \end{frame} \end{document} \begin{frame}[fragile] \frametitle{Title here} %\framesubtitle{} {\footnotesize % or scriptsize {\color{blue} \begin{verbatim} R input in blue \end{verbatim} } % End color \begin{verbatim} R output in black \end{verbatim} } % End size \end{frame}