├── .gitignore ├── Homework Guidelines.ipynb ├── LICENSE ├── README.md ├── TODO ├── _config.yml ├── homework_2.ipynb ├── include ├── custom.css ├── custom_slides.tpl └── teaching.sty ├── project ├── README.md ├── project_description.ipynb ├── type1_examples │ ├── airlines.ipynb │ └── bikes.ipynb └── type3_examples │ ├── aa_sequences.ipynb │ ├── basketball.ipynb │ └── tea.ipynb ├── scripts ├── latex.sh └── slides.sh ├── unit_1 ├── hw_2015 │ ├── Homework_1.ipynb │ └── Homework_1_Key.ipynb ├── hw_2016 │ ├── homework_1.ipynb │ └── homework_1_key.ipynb ├── hw_2017 │ ├── problem_1.ipynb │ ├── problem_2.ipynb │ └── problem_3.ipynb ├── hw_2018 │ ├── homework_1.ipynb │ └── homework_1_key.ipynb ├── hw_2019 │ ├── homework_1.ipynb │ └── homework_1_key.ipynb ├── hw_2020 │ ├── homework_1.ipynb │ └── homework_1_key.ipynb └── lectures │ ├── lecture_1.pdf │ └── lecture_1.tex ├── unit_10 ├── hw_2015 │ ├── Homework_9.ipynb │ └── Homework_9_Key.ipynb ├── hw_2016 │ ├── homework_9.ipynb │ └── homework_9_key.ipynb ├── hw_2017 │ ├── december.csv │ ├── november.csv │ ├── problem_set_1.ipynb │ ├── problem_set_2.ipynb │ ├── problem_set_3.ipynb │ └── rdf.dat ├── hw_2018 │ ├── Homework_10.ipynb │ ├── Homework_10_Key.ipynb │ └── pvalue.png ├── hw_2019 │ ├── homework_10.ipynb │ └── homework_10_key.ipynb ├── hw_2020 │ ├── homework_10.ipynb │ └── homework_10_key.ipynb └── lectures │ ├── grades.csv │ ├── lecture_1.ipynb │ └── lecture_2.ipynb ├── unit_11 ├── hw_2015 │ ├── Homework_7.ipynb │ └── Homework_7_Key.ipynb ├── hw_2016 │ ├── homework_8.ipynb │ └── homework_8_key.ipynb ├── hw_2017 │ └── problem_set_1.ipynb ├── hw_2018 │ ├── Homework_11.ipynb │ └── Homework_11_Key.ipynb ├── hw_2019 │ ├── Homework_11.ipynb │ └── homework_11_key.ipynb └── lectures │ ├── lecture_1.ipynb │ └── lecture_2.ipynb ├── unit_12 ├── hw_2015 │ ├── Homework_14.ipynb │ └── Homework_14_Key.ipynb ├── hw_2016 │ ├── homework.ipynb │ └── homework_key.ipynb ├── hw_2017 │ ├── problem_set_1.ipynb │ └── problem_set_2.ipynb ├── hw_2018 │ ├── Homework_12.ipynb │ └── Homework_12_Key.ipynb ├── hw_2019 │ └── Homework_12.ipynb └── lectures │ ├── lecture_1.ipynb │ ├── lecture_2.ipynb │ ├── lecture_3.ipynb │ ├── lecture_4.ipynb │ ├── lecture_review.ipynb │ └── spectrum.txt ├── unit_13 ├── hw_2015 │ ├── Homework_12.ipynb │ └── Homework_12_Key.ipynb └── lectures │ ├── lecture_1.ipynb │ └── lecture_2.ipynb ├── unit_14 ├── hw_2016 │ ├── homework.ipynb │ └── homework_key.ipynb └── lectures │ ├── lecture_1.ipynb │ └── lecture_2.ipynb ├── unit_15 └── lectures │ └── lecture_1.ipynb ├── unit_16 └── lectures │ ├── fuel_cell.xlsx │ └── lecture_1.ipynb ├── unit_17 └── lectures │ ├── lecture_1.ipynb │ └── lecture_2.ipynb ├── unit_18 └── lectures │ └── lecture_1.ipynb ├── unit_2 ├── hw_2015 │ ├── Homework_2.ipynb │ └── Homework_2_Key.ipynb ├── hw_2016 │ ├── homework_2.ipynb │ └── homework_2_key.ipynb ├── hw_2017 │ ├── problem_set_1.ipynb │ └── problem_set_2.ipynb ├── hw_2018 │ ├── homework_2.ipynb │ └── homework_2_key.ipynb ├── hw_2019 │ ├── homework_2.ipynb │ └── homework_2_key.ipynb ├── hw_2020 │ ├── homework_2.ipynb │ └── homework_2_key.ipynb └── lectures │ ├── lecture_1.pdf │ ├── lecture_1.tex │ ├── lecture_2.pdf │ ├── lecture_2.tex │ ├── lecture_3.pdf │ ├── lecture_3.tex │ ├── probability_examples.pdf │ └── probability_examples.tex ├── unit_3 ├── hw_2015 │ ├── Homework_3.ipynb │ └── Homework_3_Key.ipynb ├── hw_2016 │ ├── homework_3.ipynb │ └── homework_3_key.ipynb ├── hw_2017 │ ├── problem_set_1.ipynb │ └── problem_set_2.ipynb ├── hw_2018 │ ├── homework_3.ipynb │ └── homework_3_key.ipynb ├── hw_2019 │ ├── Homework_3_Key.ipynb │ └── homework_3.ipynb ├── hw_2020 │ ├── homework_3.ipynb │ └── homework_3_key.ipynb └── lectures │ ├── lecture_1.ipynb │ └── lecture_2.ipynb ├── unit_4 ├── hw_2015 │ ├── Homework_4.ipynb │ └── Homework_4_Key.ipynb ├── hw_2016 │ ├── homework_4.ipynb │ └── homework_4_key.ipynb ├── hw_2017 │ ├── problem_set_1.ipynb │ ├── problem_set_2.ipynb │ └── problem_set_3.ipynb ├── hw_2018 │ ├── Homework_4.ipynb │ └── Homework_4_Key.ipynb ├── hw_2019 │ ├── Homework_4.ipynb │ └── Homework_4_Key.ipynb ├── hw_2020 │ ├── homework_4.ipynb │ └── homework_4_key.ipynb └── lectures │ ├── lecture_1.ipynb │ ├── lecture_2.pdf │ └── lecture_2.tex ├── unit_5 ├── hw_2015 │ ├── Homework_5.ipynb │ └── Homework_5_Key.ipynb ├── hw_2016 │ ├── homework_5.ipynb │ └── homework_5_key.ipynb ├── hw_2017 │ ├── problem_set_1.ipynb │ ├── problem_set_2.ipynb │ └── problem_set_3.ipynb ├── hw_2018 │ ├── Homework_5.ipynb │ └── Homework_5_Key.ipynb ├── hw_2019 │ ├── Homework_5.ipynb │ └── Homework_5_key.ipynb ├── hw_2020 │ ├── homework_5.ipynb │ └── homework_5_key.ipynb └── lectures │ ├── lecture_1.pdf │ ├── lecture_1.tex │ ├── lecture_2.pdf │ └── lecture_2.tex ├── unit_6 ├── hw_2017 │ ├── problem_set_1.ipynb │ ├── problem_set_2.ipynb │ └── problem_set_3.ipynb ├── hw_2018 │ ├── Homework_6.ipynb │ └── Homework_6_Key.ipynb ├── hw_2019 │ ├── Homework_6.ipynb │ └── Homework_6_key.ipynb ├── hw_2020 │ └── homework_6.ipynb └── lectures │ ├── lecture_1.ipynb │ ├── lecture_2.ipynb │ └── lecture_3.ipynb ├── unit_7 ├── hw_2016 │ ├── homework_7.ipynb │ └── homework_7_key.ipynb ├── hw_2017 │ ├── problem_set_1.ipynb │ └── problem_set_2.ipynb ├── hw_2018 │ ├── Homework_7.ipynb │ └── Homework_7_Key.ipynb ├── hw_2019 │ ├── Homework_7.ipynb │ └── Homework_7_Key.ipynb ├── hw_2020 │ └── homework_7.ipynb └── lectures │ ├── lecture_1.pdf │ ├── lecture_1.tex │ ├── lecture_2.ipynb │ ├── lecture_3.pdf │ ├── lecture_3.tex │ └── lecture_4.ipynb ├── unit_8 ├── hw_2015 │ ├── Homework_6.ipynb │ └── Homework_6_Key.ipynb ├── hw_2016 │ ├── homework_6.ipynb │ └── homework_6_key.ipynb ├── hw_2018 │ ├── Homework_8.ipynb │ └── Homework_8_Key.ipynb ├── hw_2019 │ ├── homework_8.ipynb │ └── homework_8_key.ipynb ├── hw_2020 │ ├── homework_8.ipynb │ └── homework_8_key.ipynb └── lectures │ ├── lecture_1.ipynb │ └── lecture_2.ipynb └── unit_9 ├── hw_2016 ├── homework_7.ipynb └── homework_7_key.ipynb ├── hw_2017 ├── problem_set_1.ipynb └── problem_set_2.ipynb ├── hw_2018 ├── Homework_9.ipynb └── Homework_9_Key.ipynb ├── hw_2019 ├── homework_9.ipynb └── homework_9_key.ipynb ├── hw_2020 ├── homework_9.ipynb └── homework_9_key.ipynb └── lectures ├── lecture_1.ipynb ├── lecture_2.ipynb └── lecture_3.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | #Emacs 2 | *~ 3 | .#* 4 | #* 5 | 6 | #LaTeX 7 | *.aux 8 | *.log 9 | *.out 10 | 11 | #pandoc 12 | README.html 13 | 14 | #jupyter 15 | *.ipynb_checkpoints/ 16 | *.html 17 | 18 | #custom.css in non-include directory 19 | unit_*/lectures/custom.css -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | teach t-test, it's not sensitive to normality assumption https://www.nature.com/articles/nmeth.2858 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | title: Numerical Methods and Statistics 2 | -------------------------------------------------------------------------------- /homework_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 2\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "1/24/2019\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Combinations and Permutation\n", 21 | "\n", 22 | "**For each problem, write out the number of objects ($n$), the length of the sequence/sample ($l$), if repeats are allowed, and if you are computing permutations or combinations. 1 point for this on each problem**\n", 23 | "\n", 24 | "1. [2 points] How many ways can you rearrange the letters in the word \"Python\"?\n", 25 | "2. [2 points] How many ways can you erarrange the letters in the word \"Coffee\"?\n", 26 | "3. [2 points] You have 5 close friends and are choosing which 3 friends will be in your wedding party. How many ways could you choose your friends that will be in your wedding party?\n", 27 | "4. [3 points] You now cannot decide either how many to be in your wedding party nor which friends to choose. Assuming you could have between 0 and 5 friends in the wedding party, how many ways could you choose them?\n", 28 | "5. [2 points] Quarks can have a \"color charge\" of red, blue, or green. If you have 5 distinguishable quarks, how many perumutations of charges could the quarks have?\n", 29 | "6. [2 points] Now the quarks are indistinguishable. How many combinations of quarks could you have?\n" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "# Stereo Chemistry\n", 37 | "\n", 38 | "1. [2 points] Consider an sp3 carbon atom. What elements could be bonded to carbon to satisfy its valencey? Only choose reasonable elements you would find in typical organic molecules. \n", 39 | "2. [6 points] With one sp3 carbon atom and the elements you've chosen, how many compounds are there? You can reuse your elements as many times as needed to satisfy the valency. What role does distinguishability play? Connect distinguishability with the conecpt of enantiomers." 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "# Medical Diagnosis\n", 47 | "\n", 48 | "**You do not need to use conditional probability to solve this problem**\n", 49 | "\n", 50 | "We are evaluating a new test to screen for Ebola that claims to identify Ebola in patients before symptoms are present . We want to use this test to quarantine probable cases to prevent the spread of Ebola. People can either not have Ebola or have Ebola and our test can be positive or negative. Let's take the random variable $E$ to indicate if the patient has Ebola and $T$ to indicate if the test is positive. We had 100 patients in our study who were at risk for Ebola. Our test indicated that 74 of the patients had Ebola and were quarantined to see if symptomps presented. After one week when symtpoms presented, we determined that 2 patients were not caught by the test and 6 of the quarantined patients presented with Ebola consistent with your test. The remianing patients did not have Ebola. Is catching 6/8, 75% of the patients with Ebola, indicate the test is effective? Answering this by completing the questions below.\n", 51 | "\n", 52 | "1. [1 point] Write out the sample space\n", 53 | "\n", 54 | "2. [1 point] What is the marginal probability of having Ebola?\n", 55 | "\n", 56 | "3. [1 point] What is the marginal probability of having a positive test result?\n", 57 | "\n", 58 | "3. [2 points] Compute $P(E = 1, T = 1)$\n", 59 | "\n", 60 | "4. [3 points] What concept did we learn that could tell us whether or not the test is effective? How could we make a numeric argument?\n", 61 | "\n", 62 | "5. [3 points] Is there compelling numerical evidence that the test is effective?" 63 | ] 64 | } 65 | ], 66 | "metadata": { 67 | "kernelspec": { 68 | "display_name": "Python 3", 69 | "language": "python", 70 | "name": "python3" 71 | }, 72 | "language_info": { 73 | "codemirror_mode": { 74 | "name": "ipython", 75 | "version": 3 76 | }, 77 | "file_extension": ".py", 78 | "mimetype": "text/x-python", 79 | "name": "python", 80 | "nbconvert_exporter": "python", 81 | "pygments_lexer": "ipython3", 82 | "version": "3.6.4" 83 | } 84 | }, 85 | "nbformat": 4, 86 | "nbformat_minor": 2 87 | } 88 | -------------------------------------------------------------------------------- /include/custom.css: -------------------------------------------------------------------------------- 1 | html{ 2 | background-color: inherit; 3 | } 4 | 5 | body { 6 | cursor: none; 7 | } 8 | 9 | .reveal .slides { 10 | overflow-y: auto; 11 | overflow-x: hidden; 12 | } 13 | .reveal .rendered_html code { 14 | border: 0; 15 | background-color: #ddd; 16 | color: #293; 17 | font-size: 100%; 18 | font-family: monospace; 19 | border-radius: 4px; 20 | margin:2px; 21 | padding: 5px; 22 | } 23 | 24 | .reveal pre code { 25 | padding: 10px; 26 | } 27 | 28 | .naked-img { 29 | margin-left: 15%; 30 | } 31 | 32 | .reveal .input_prompt { 33 | visibility:hidden; 34 | } 35 | 36 | 37 | .my-h2{ 38 | color: #FF00FF; 39 | } 40 | 41 | section:first-child > section:first-child > div { 42 | background-color: rgba(255, 255,255, 0.5); 43 | } -------------------------------------------------------------------------------- /include/custom_slides.tpl: -------------------------------------------------------------------------------- 1 | {% extends 'slides_reveal.tpl'%} 2 | {% block post_slides %} 3 | 6 | 59 | 60 | 61 | {% endblock post_slides %} -------------------------------------------------------------------------------- /include/teaching.sty: -------------------------------------------------------------------------------- 1 | \def\fileversion{1.0} 2 | \def\filedat{2012/29/03} 3 | 4 | 5 | 6 | \usepackage{graphicx} 7 | \usepackage{amsmath,amssymb,amsthm,amsfonts} 8 | 9 | 10 | %Page size 11 | \setlength{\oddsidemargin}{0pt} 12 | \setlength{\evensidemargin}{0pt} 13 | \setlength{\textwidth}{6.5in} 14 | \setlength{\topmargin}{0in} 15 | \setlength{\textheight}{8.5in} 16 | 17 | 18 | \newcommand{\ttt}[1]{\cdot 10^{#1}} %times ten to the 19 | \newcommand{\lp}{\left(} % left parenthesis 20 | \newcommand{\rp}{\right)} %right paranethesis 21 | \newcommand{\un}[1]{\textrm{#1}} % units 22 | \newcommand{\sizeof}[1]{\left|#1\right|} 23 | \newcommand{\vv}[1]{\textbf{#1}} 24 | \newcommand{\dirac}[1]{\delta\left(#1\right)} 25 | \newcommand{\di}[1]{\,\textrm{d}#1} 26 | \newcommand{\fo}[1]{\un{Fo}\left[\,#1\,\right]} 27 | \DeclareMathOperator*{\argmin}{argmin} 28 | \DeclareMathOperator*{\argmax}{argmax} 29 | 30 | %%numerical Constants 31 | \newcommand{\plancksi}{6.626069\ttt{-34}\,\textrm{J}\cdot \textrm{s}} 32 | \newcommand{\hbarsi}{1.054572\ttt{-34}\,\textrm{J}\cdot \textrm{s}} 33 | \newcommand{\boltz}{1.380 6504\ttt{-23}\,\textrm{J}\cdot\textrm{K}^{-1}} 34 | \newcommand{\Na}{6.02214\ttt{23}} 35 | \newcommand{\mesi}{9.109382\ttt{-31}\,\textrm{kg} } %mass of electron in si 36 | 37 | %Quantum Chemistry 38 | \newcommand{\ods}[1]{\frac{-\hbar^2}{2m}\frac{d^2\psi(x)}{dx^2} + #1\,\psi(x) = E\psi(x)} %1D schrodinger 39 | \newcommand{\bra}[1]{\left<#1\right|} 40 | \newcommand{\ket}[1]{\left|#1\right>} 41 | \newcommand{\braket}[2]{\left<#1\right|\left.#2\right>} 42 | 43 | %stat mech 44 | \newcommand{\sexp}[1]{\left<\,#1\,\right>} 45 | 46 | %Probability 47 | \renewcommand{\Pr}{\textrm{P}} 48 | \DeclareMathOperator{\E}{E} 49 | \newcommand{\Econd}[2]{\E \left( \left.#1 \, \right| \,#2 \right)} 50 | \newcommand{\Pcond}[2]{\Pr \left( \left.#1 \, \right| \,#2 \right)} 51 | \newcommand{\Escond}[2]{\E^* \left[ #1 \, \right|\left. \,#2 \right]} 52 | \newcommand{\pexp}[1]{\rm{E}\left[\,#1\,\right]} 53 | \newcommand{\Filt}[1]{\mathcal{F}_{#1}} 54 | \newcommand{\Ind}[1]{\mathbf{1}_{\left\{#1\right\}}} 55 | \DeclareMathOperator{\var}{Var} 56 | 57 | 58 | 59 | 60 | %Problem Environment 61 | %\begin{problem}{title} 62 | \newenvironment{problem}[1] 63 | {\vspace{1ex}\noindent\ignorespaces\refstepcounter{section}\textbf {Problem~\arabic{section}:~}\underline{#1}\vspace{0.5ex}\par\ignorespacesafterend} 64 | {\vspace{1ex}\par\noindent\ignorespacesafterend} 65 | 66 | %\begin{assumption} 67 | \newcounter{assumption}[section] 68 | \newenvironment{assumption} 69 | {\vspace{1ex}\noindent\ignorespaces\refstepcounter{assumption}\textbf {Assumption~\arabic{section}.\arabic{assumption}:~}}{\vspace{1ex}\par\noindent\ignorespacesafterend} 70 | 71 | %\begin{assumption} 72 | \newcounter{algorithm}[section] 73 | \newenvironment{algorithm} 74 | {\vspace{1ex}\noindent\ignorespaces\refstepcounter{algorithm}\textbf {Algorithm~\arabic{section}.\arabic{algorithm}:~}}{\vspace{1ex}\par\noindent\ignorespacesafterend} 75 | 76 | \renewcommand{\proof}{\textbf{Proof: }} 77 | %Homework setup 78 | 79 | \newcommand{\theader}[3]{ 80 | \noindent 81 | \begin{center} 82 | \framebox{ \vbox{ \hbox to 5.78in { {\bf #1} \hfill \today} 83 | \vspace{4mm} 84 | \hbox to 5.78in { {\Large \hfill #2 \hfill} } 85 | \vspace{2mm} 86 | \hbox to 5.78in { {\hfill \it #3 \hfill} } 87 | } 88 | } 89 | \end{center} 90 | \vspace*{4mm} 91 | } 92 | 93 | %\begin{homework}{Course Name}{Homework Number}{Course Number} 94 | \newenvironment{tdoc}[2]{\theader{#1}{#2}}{} 95 | -------------------------------------------------------------------------------- /project/README.md: -------------------------------------------------------------------------------- 1 | CHE 116 Projects 2 | ===== 3 | 4 | Description 5 | ----- 6 | 7 | See [here](https://nbviewer.jupyter.org/github/whitead/numerical_stats/blob/master/project/project_description.ipynb) 8 | 9 | Examples 10 | ----- 11 | 12 | These examples all received a B or A. Some of them may have 13 | mistakes. You be unable to execute the type 1 notebooks because data 14 | is missing or the project was done in Python 2. 15 | 16 | * [type 1](https://nbviewer.jupyter.org/github/whitead/numerical_stats/blob/master/project/type1_examples) 17 | * [type 2](https://nbviewer.jupyter.org/github/whitead/numerical_stats/blob/master/project/type1_examples) 18 | * [type 3](https://nbviewer.jupyter.org/github/whitead/numerical_stats/blob/master/project/type1_examples) -------------------------------------------------------------------------------- /scripts/latex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | env TEXINPUTS='.:../../include': pdflatex $1 4 | -------------------------------------------------------------------------------- /scripts/slides.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | cp `pwd`/include/custom.css `dirname $1` 3 | sudo docker run -p 8888:8888 -it -v `pwd`:/home/jovyan/work jupyter/scipy-notebook jupyter nbconvert --to slides $1 --post serve --ServePostProcessor.port=8888 --ServePostProcessor.ip=0.0.0.0 --template=include/custom_slides.tpl --ServePostProcessor.reveal_cdn=https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.4.1 4 | 5 | #windows 6 | #docker run --rm -it -p 8889:8888 -v C:\Users\white\numerical_stats:/home/jovyan jupyter/scipy-notebook jupyter nbconvert --to slides unit_11/lectures/lecture_2.ipynb --post serve --ServePostProcessor.port=8888 --ServePostProcessor.ip=0.0.0.0 --template=include/custom_slides.tpl --ServePostProcessor.reveal_cdn=https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.6.0 -------------------------------------------------------------------------------- /unit_1/hw_2016/homework_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 1\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "Version 1.1 (1/14/2015)\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "slideshow": { 20 | "slide_type": "slide" 21 | } 22 | }, 23 | "source": [ 24 | "1. Simple Probability (4 Points)\n", 25 | "====\n", 26 | "\n", 27 | "The probability of an event or sample is written as $P(A)$, where $A$ is the event or sample. **Answer the following problems symbolically and simplified.** Each problem is worth 1 point.\n", 28 | "\n", 29 | "1. If we observe an event, what is the probability that the event is $A$ or $B$ assuming that $A$ and $B$ are mutually exclusive?\n", 30 | "\n", 31 | "2. If we observe a sample, what is the probability of observing $A$ or $B$ if they are the only two possible samples?\n", 32 | "\n", 33 | "3. What is the probability of observing samples or events $A$ and $B$ if they are independent?\n", 34 | "\n", 35 | "4. Question 1.2 and question 1.3 were ambiguous about the number of observations. Specifically how many observations occur in each question?" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": { 41 | "slideshow": { 42 | "slide_type": "slide" 43 | } 44 | }, 45 | "source": [ 46 | "#### Question 1.1 Answer\n", 47 | "\n", 48 | "If we observe an event, what is the probability that the event is $A$ or $B$ assuming that $A$ and $B$ are mutually exclusive?\n", 49 | "\n" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": { 55 | "slideshow": { 56 | "slide_type": "slide" 57 | } 58 | }, 59 | "source": [ 60 | "$P(A) + P(B)$" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": { 66 | "slideshow": { 67 | "slide_type": "slide" 68 | } 69 | }, 70 | "source": [ 71 | "2. Die Probability (6 Points)\n", 72 | "====\n", 73 | " \n", 74 | " You are rolling a die with 6 sides. Event $A$ is that you roll a number greater than 3. Event $B$ is that you roll a $3$. Event $C$ rolling a number less than 3. **Answer these problems using python code**. Make sure your numbers contain decimals (write `1.0` instead of `1`) so python knows you want to have decimals. Each problem is worth 1 point.\n", 75 | " \n", 76 | "1. What is the probability of event $A$?\n", 77 | "2. If you roll once, what is the probability of rolling event $A$ or $C$?\n", 78 | "3. If you roll event $B$, on your next roll what is the probability of event $A$?\n", 79 | "4. What is the probability of rolling event $A$ followed by event $B$?\n", 80 | "5. What is the probability of rolling event $A$ and event $B$ in the course of two rolls?\n", 81 | "6. Why are your answers different for questions 2.4 and 2.5? Answer this in words using Markdown or Python." 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "#### Question 2.1 Answer\n", 89 | "What is the probability of event $A$?" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 1, 95 | "metadata": { 96 | "collapsed": false 97 | }, 98 | "outputs": [ 99 | { 100 | "data": { 101 | "text/plain": [ 102 | "0.5" 103 | ] 104 | }, 105 | "execution_count": 1, 106 | "metadata": {}, 107 | "output_type": "execute_result" 108 | } 109 | ], 110 | "source": [ 111 | "3.0 / 6.0" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "3. Sample Spaces (16 Points)\n", 119 | "====\n", 120 | "**Answers these problems symbolically**\n", 121 | "\n", 122 | "Each problem is worth 2 points\n", 123 | "\n", 124 | "1. You play a game where each time you flip a coin and roll a die. Both of these actions make up an observation. What is the size of the sample space?\n", 125 | "2. What is the sample space for kinetic energy?\n", 126 | "3. You have a random number with 3 digits places. What's the sample space size? What's the sample size of a 3 digit number in base 8?\n", 127 | "4. You have a 6 character password which can contain a-z (lowercase). What's the sample space size? \n", 128 | "5. You double the length of your password. What's the sample size now?\n", 129 | "6. With the 6 character password, you now include uppercase letters, the number 0-9 and and 4 punctuation characters. What's the sample size?\n", 130 | "7. Based on the previous problem, would a password that is a complete sentence (30 characters) with only lower case letters plus a space or a normal password (10 characters) involing symbols and numbers be more secure? Justify your answer. You may approximate your answer to the nearest order of magnitude.\n", 131 | "8. What is the sample space for 2 methane molecules and 4 oxygen atoms reacting assuming no radicals or ions are formed? Enumerate (list all) the sample space." 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": { 138 | "collapsed": true 139 | }, 140 | "outputs": [], 141 | "source": [] 142 | } 143 | ], 144 | "metadata": { 145 | "kernelspec": { 146 | "display_name": "Python 3", 147 | "language": "python", 148 | "name": "python3" 149 | }, 150 | "language_info": { 151 | "codemirror_mode": { 152 | "name": "ipython", 153 | "version": 3 154 | }, 155 | "file_extension": ".py", 156 | "mimetype": "text/x-python", 157 | "name": "python", 158 | "nbconvert_exporter": "python", 159 | "pygments_lexer": "ipython3", 160 | "version": "3.4.2" 161 | } 162 | }, 163 | "nbformat": 4, 164 | "nbformat_minor": 0 165 | } 166 | -------------------------------------------------------------------------------- /unit_1/hw_2017/problem_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbgrader": { 7 | "grade": false, 8 | "grade_id": "1_description", 9 | "locked": true, 10 | "schema_version": 1, 11 | "solution": false 12 | } 13 | }, 14 | "source": [ 15 | "1. Simple Probability\n", 16 | "===\n", 17 | "\n", 18 | "The probability of an event or sample is written as $P(A)$, where $A$ is the event or sample. **Answer the following problems symbolically and simplified**. Each problem is worth 4 point.\n", 19 | "\n", 20 | "1. Our sample space contains two elements: $1$ and $2$. What is $P(1) + P(2)$\n", 21 | "2. If $A$ and $C$ are independent events from different sample spaces, what is the probability of observing $A$ and then $C$?\n", 22 | "3. Does your answer change if $A$ and $C$ are independent events from the same sample space? \n", 23 | "4. If your event includes half the elements in the sample space, is the probability of the event $\\frac{1}{2}$?\n", 24 | "5. You have a sample space with three elements: $\\{A, B, C\\}$. Event 1 is the occurrence $A$ or $B$. Event 2 is $C$ or $B$. What is the probability of Event 1 or 2?" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "nbgrader": { 31 | "grade": false, 32 | "grade_id": "1_1_answer", 33 | "locked": true, 34 | "schema_version": 1, 35 | "solution": false 36 | } 37 | }, 38 | "source": [ 39 | "#### 1.1 Answer" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "collapsed": true, 46 | "nbgrader": { 47 | "grade": true, 48 | "grade_id": "1_1", 49 | "locked": false, 50 | "points": 4, 51 | "schema_version": 1, 52 | "solution": true 53 | } 54 | }, 55 | "source": [ 56 | "This is the sum of the entire sample space, so:\n", 57 | "$$\n", 58 | "P(1) + P(2) = 1\n", 59 | "$$" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "nbgrader": { 66 | "grade": false, 67 | "grade_id": "1_2_answer", 68 | "locked": true, 69 | "schema_version": 1, 70 | "solution": false 71 | } 72 | }, 73 | "source": [ 74 | "#### 1.2 Answer" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": { 80 | "collapsed": true, 81 | "nbgrader": { 82 | "grade": true, 83 | "grade_id": "1_2", 84 | "locked": false, 85 | "points": 4, 86 | "schema_version": 1, 87 | "solution": true 88 | } 89 | }, 90 | "source": [ 91 | "$$\n", 92 | "P(A) P(C)\n", 93 | "$$" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "nbgrader": { 100 | "grade": false, 101 | "grade_id": "1_3_answer", 102 | "locked": true, 103 | "schema_version": 1, 104 | "solution": false 105 | } 106 | }, 107 | "source": [ 108 | "#### 1.3 Answer" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": { 114 | "collapsed": true, 115 | "nbgrader": { 116 | "grade": true, 117 | "grade_id": "1_3", 118 | "locked": false, 119 | "points": 4, 120 | "schema_version": 1, 121 | "solution": true 122 | } 123 | }, 124 | "source": [ 125 | "No, the AND rule isn't affected" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": { 131 | "collapsed": true, 132 | "nbgrader": { 133 | "grade": false, 134 | "grade_id": "1_4_answer", 135 | "locked": true, 136 | "schema_version": 1, 137 | "solution": false 138 | } 139 | }, 140 | "source": [ 141 | "#### 1.4 Answer\n", 142 | "\n" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": { 148 | "collapsed": true, 149 | "nbgrader": { 150 | "grade": true, 151 | "grade_id": "1_4", 152 | "locked": false, 153 | "points": 4, 154 | "schema_version": 1, 155 | "solution": true 156 | } 157 | }, 158 | "source": [ 159 | "No, that is only true if the probability is uniform" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": { 165 | "collapsed": true, 166 | "nbgrader": { 167 | "grade": false, 168 | "grade_id": "1_5_answer", 169 | "locked": true, 170 | "schema_version": 1, 171 | "solution": false 172 | } 173 | }, 174 | "source": [ 175 | "#### 1.5 Answer" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": { 181 | "collapsed": true, 182 | "nbgrader": { 183 | "grade": true, 184 | "grade_id": "1_5", 185 | "locked": false, 186 | "points": 4, 187 | "schema_version": 1, 188 | "solution": true 189 | } 190 | }, 191 | "source": [ 192 | "$$\n", 193 | "P(1\\, \\textrm{OR}\\, 2) = P(A) + P(B) + P(B) + P(C) - P(B) = 1\n", 194 | "$$" 195 | ] 196 | } 197 | ], 198 | "metadata": { 199 | "celltoolbar": "Create Assignment", 200 | "kernelspec": { 201 | "display_name": "Python 3", 202 | "language": "python", 203 | "name": "python3" 204 | }, 205 | "language_info": { 206 | "codemirror_mode": { 207 | "name": "ipython", 208 | "version": 3 209 | }, 210 | "file_extension": ".py", 211 | "mimetype": "text/x-python", 212 | "name": "python", 213 | "nbconvert_exporter": "python", 214 | "pygments_lexer": "ipython3", 215 | "version": "3.5.2" 216 | } 217 | }, 218 | "nbformat": 4, 219 | "nbformat_minor": 2 220 | } 221 | -------------------------------------------------------------------------------- /unit_1/hw_2017/problem_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbgrader": { 7 | "grade": false, 8 | "grade_id": "2_description", 9 | "locked": true, 10 | "schema_version": 1, 11 | "solution": false 12 | } 13 | }, 14 | "source": [ 15 | "2. Die Probability\n", 16 | "====\n", 17 | " \n", 18 | " You are rolling a die with 6 sides. Event $A$ is that you roll a number greater than 4. Event $B$ is that you roll a $1$. Event $C$ rolling a number less than 3. **Answer these problems using python code**. Make sure your numbers contain decimals (write `1.0` instead of `1`) so python knows you want to have decimals. Each problem is worth 1 point.\n", 19 | " \n", 20 | "1. What is the probability of event $A$?\n", 21 | "2. If you roll once, what is the probability of rolling event $A$ or $C$?\n", 22 | "3. If you roll event $B$, on your next roll what is the probability of event $A$?\n", 23 | "4. What is the probability of rolling event $A$ followed by event $B$?\n", 24 | "5. What is the probability of rolling event $A$ and event $B$ in the course of two rolls?\n", 25 | "6. Why are your answers different for questions 2.4 and 2.5? Answer this in words using Markdown or Python." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 6, 31 | "metadata": { 32 | "collapsed": false, 33 | "nbgrader": { 34 | "grade": true, 35 | "grade_id": "2_1", 36 | "locked": false, 37 | "points": 2, 38 | "schema_version": 1, 39 | "solution": true 40 | } 41 | }, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "0.3333333333333333" 47 | ] 48 | }, 49 | "execution_count": 6, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "#Answer 2.1\n", 56 | "2 / 6" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 7, 62 | "metadata": { 63 | "collapsed": false, 64 | "nbgrader": { 65 | "grade": true, 66 | "grade_id": "2_2", 67 | "locked": false, 68 | "points": 2, 69 | "schema_version": 1, 70 | "solution": true 71 | } 72 | }, 73 | "outputs": [ 74 | { 75 | "data": { 76 | "text/plain": [ 77 | "0.6666666666666666" 78 | ] 79 | }, 80 | "execution_count": 7, 81 | "metadata": {}, 82 | "output_type": "execute_result" 83 | } 84 | ], 85 | "source": [ 86 | "#Answer 2.2\n", 87 | "2/ 6 + 2 / 6" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 8, 93 | "metadata": { 94 | "collapsed": false, 95 | "nbgrader": { 96 | "grade": true, 97 | "grade_id": "2_3", 98 | "locked": false, 99 | "points": 2, 100 | "schema_version": 1, 101 | "solution": true 102 | } 103 | }, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "0.3333333333333333" 109 | ] 110 | }, 111 | "execution_count": 8, 112 | "metadata": {}, 113 | "output_type": "execute_result" 114 | } 115 | ], 116 | "source": [ 117 | "#Answer 2.3\n", 118 | "2 / 6" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 9, 124 | "metadata": { 125 | "collapsed": false, 126 | "nbgrader": { 127 | "grade": true, 128 | "grade_id": "2_4", 129 | "locked": false, 130 | "points": 2, 131 | "schema_version": 1, 132 | "solution": true 133 | } 134 | }, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/plain": [ 139 | "0.05555555555555555" 140 | ] 141 | }, 142 | "execution_count": 9, 143 | "metadata": {}, 144 | "output_type": "execute_result" 145 | } 146 | ], 147 | "source": [ 148 | "#Answer 2.4\n", 149 | "2 / 6 * 1 / 6" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 10, 155 | "metadata": { 156 | "collapsed": false, 157 | "nbgrader": { 158 | "grade": true, 159 | "grade_id": "2_5", 160 | "locked": false, 161 | "points": 2, 162 | "schema_version": 1, 163 | "solution": true 164 | } 165 | }, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "0.1111111111111111" 171 | ] 172 | }, 173 | "execution_count": 10, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "#Answer 2.5\n", 180 | "2 * 2 / 6 * 1 / 6" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": { 186 | "collapsed": true, 187 | "nbgrader": { 188 | "grade": true, 189 | "grade_id": "2_6", 190 | "locked": false, 191 | "points": 2, 192 | "schema_version": 1, 193 | "solution": true 194 | } 195 | }, 196 | "source": [ 197 | "#### Answer 2.6\n", 198 | "2.5 Asks about a permutation and 2.6 about a combination. " 199 | ] 200 | } 201 | ], 202 | "metadata": { 203 | "celltoolbar": "Create Assignment", 204 | "kernelspec": { 205 | "display_name": "Python 3", 206 | "language": "python", 207 | "name": "python3" 208 | }, 209 | "language_info": { 210 | "codemirror_mode": { 211 | "name": "ipython", 212 | "version": 3 213 | }, 214 | "file_extension": ".py", 215 | "mimetype": "text/x-python", 216 | "name": "python", 217 | "nbconvert_exporter": "python", 218 | "pygments_lexer": "ipython3", 219 | "version": "3.5.2" 220 | } 221 | }, 222 | "nbformat": 4, 223 | "nbformat_minor": 2 224 | } 225 | -------------------------------------------------------------------------------- /unit_1/hw_2017/problem_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbgrader": { 7 | "grade": false, 8 | "grade_id": "3_description", 9 | "locked": true, 10 | "schema_version": 1, 11 | "solution": false 12 | } 13 | }, 14 | "source": [ 15 | "3. Sample Spaces\n", 16 | "====\n", 17 | "**Answers these problems symbolically**\n", 18 | "\n", 19 | "Each problem is worth 4 points\n", 20 | "\n", 21 | "1. You play a game where each time you flip a coin and draw a card. Both of these actions make up an observation. What is the size of the sample space?\n", 22 | "2. What is the sample space for temperature of macroscopic objects?\n", 23 | "2. You dial random 10 digit phone numbers. What's the sample size?\n", 24 | "4. You have a 6 character password which can contain uppercase, lowercase and numbers. What's the sample space size? \n", 25 | "5. You double the length of your password. What's the sample size now?\n", 26 | "7. Based on the previous problem, would a password that is a complete sentence (35 characters) with only lower case letters plus a space be more or less secure from the previous problem? Justify your answer." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "nbgrader": { 33 | "grade": true, 34 | "grade_id": "3_1", 35 | "locked": false, 36 | "points": 4, 37 | "schema_version": 1, 38 | "solution": true 39 | } 40 | }, 41 | "source": [ 42 | "#### Answer 3.1\n", 43 | "$$\n", 44 | "2 \\times 52 = 104\n", 45 | "$$" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": { 51 | "nbgrader": { 52 | "grade": true, 53 | "grade_id": "3_2", 54 | "locked": false, 55 | "points": 4, 56 | "schema_version": 1, 57 | "solution": true 58 | } 59 | }, 60 | "source": [ 61 | "#### Answer 3.2\n", 62 | "$$\n", 63 | "(0,\\infty)\n", 64 | "$$" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "nbgrader": { 71 | "grade": true, 72 | "grade_id": "3_3", 73 | "locked": false, 74 | "points": 4, 75 | "schema_version": 1, 76 | "solution": true 77 | } 78 | }, 79 | "source": [ 80 | "#### Answer 3.3\n", 81 | "$$\n", 82 | "10^{10}\n", 83 | "$$" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": { 89 | "nbgrader": { 90 | "grade": true, 91 | "grade_id": "3_4", 92 | "locked": false, 93 | "points": 4, 94 | "schema_version": 1, 95 | "solution": true 96 | } 97 | }, 98 | "source": [ 99 | "#### Answer 3.4\n", 100 | "$$\n", 101 | "\\left(26 + 26 + 10\\right)^6 = 62^6\n", 102 | "$$" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": { 108 | "nbgrader": { 109 | "grade": true, 110 | "grade_id": "3_5", 111 | "locked": false, 112 | "points": 4, 113 | "schema_version": 1, 114 | "solution": true 115 | } 116 | }, 117 | "source": [ 118 | "#### Answer 3.5\n", 119 | "$$\n", 120 | "62^{12}\n", 121 | "$$" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": { 127 | "nbgrader": { 128 | "grade": true, 129 | "grade_id": "3_6", 130 | "locked": false, 131 | "points": 4, 132 | "schema_version": 1, 133 | "solution": true 134 | } 135 | }, 136 | "source": [ 137 | "#### Answer 3.6\n", 138 | "$$\n", 139 | "\\textrm{sentence} = 27^{35} \\approx 10^{50}\n", 140 | "$$\n", 141 | "\n", 142 | "$$\n", 143 | "\\textrm{normal} = 62^{13} \\approx 10^{17}\n", 144 | "$$\n", 145 | "\n", 146 | "A sentence is significantly more secure" 147 | ] 148 | } 149 | ], 150 | "metadata": { 151 | "celltoolbar": "Create Assignment", 152 | "kernelspec": { 153 | "display_name": "Python 3", 154 | "language": "python", 155 | "name": "python3" 156 | }, 157 | "language_info": { 158 | "codemirror_mode": { 159 | "name": "ipython", 160 | "version": 3 161 | }, 162 | "file_extension": ".py", 163 | "mimetype": "text/x-python", 164 | "name": "python", 165 | "nbconvert_exporter": "python", 166 | "pygments_lexer": "ipython3", 167 | "version": "3.5.2" 168 | } 169 | }, 170 | "nbformat": 4, 171 | "nbformat_minor": 2 172 | } 173 | -------------------------------------------------------------------------------- /unit_1/hw_2018/homework_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 1\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "1/18/2018\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "1. Probability\n", 21 | "====\n", 22 | "\n", 23 | "The probability of an event or element in a sample space is written as $P(A)$, where $A$ is the event or element in the sample space. **Answer the following problems symbolically and simplified.** Each problem is worth 1 point.\n", 24 | "\n", 25 | "1. Our sample space contains three elements: $Q = \\{A, B, C\\}$. What is the probability of observing $P(A\\, \\textrm{OR}\\, \\textrm{B}\\, \\textrm{OR}\\, C)$\n", 26 | "\n", 27 | "2. If we observe two sequential independent samples with the same sample space as above, what is the probability of observing $A$ and then $B$?\n", 28 | "\n", 29 | "3. You have a sample space with the numbers 1-10, where each element in the sample space has the same probability. If event $E$ is elements $\\{2, 5, 7\\}$, then what is the probability of the event $E$, $P(E)$?\n", 30 | "\n", 31 | "4. What is the probability of not event $E$ from the previous question?\n", 32 | "\n", 33 | "5. State the number of observations/samples for the probabilities specified in questions 1.1-1.4. " 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "2. Die Probability\n", 41 | "====\n", 42 | " \n", 43 | " You are rolling a die with 6 sides. Event $A$ is that you roll a number less than 5. Event $B$ is that you roll a $6$. Event $C$ rolling a number less than 2. **Answer these problems using python code**. Each problem is worth 1 point.\n", 44 | " \n", 45 | "1. What is the probability of event $A$?\n", 46 | "2. If you roll once, what is the probability of rolling event $A$ or $C$?\n", 47 | "3. If you roll event $A$, on your next roll what is the probability of event $B$?\n", 48 | "4. What is the probability of rolling event $A$ and event $B$ in the course of two rolls?\n", 49 | "5. What is the probability of rolling event $A$ followed by event $B$?\n", 50 | "6. Why are your answers different for questions 2.4 and 2.5? Answer this in words using Markdown." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "3. Sample Spaces\n", 58 | "====\n", 59 | "**Answers these problems symbolically**\n", 60 | "\n", 61 | "Each problem is worth 4 points\n", 62 | "\n", 63 | "1. You play a game where each time you flip a coin and draw a card from a 52 card deck. Both of these actions make up an observation. What is the size of the sample space?\n", 64 | "2. What is the sample space for number of students attending lecture if there are 80 students enrolled?\n", 65 | "3. You dial random 10 digit phone numbers. What's the sample size?\n", 66 | "4. You have a 10 character password which can contain lowercase letters and numbers. What's the sample space size? \n", 67 | "5. You double the length of your password. What's the sample size now?\n", 68 | "6. Based on the previous problem, would a password that is a complete sentence (35 characters) with only lowercase letters plus a space be more or less secure than the previous problem? Justify your answer." 69 | ] 70 | } 71 | ], 72 | "metadata": { 73 | "kernelspec": { 74 | "display_name": "Python 3", 75 | "language": "python", 76 | "name": "python3" 77 | }, 78 | "language_info": { 79 | "codemirror_mode": { 80 | "name": "ipython", 81 | "version": 3 82 | }, 83 | "file_extension": ".py", 84 | "mimetype": "text/x-python", 85 | "name": "python", 86 | "nbconvert_exporter": "python", 87 | "pygments_lexer": "ipython3", 88 | "version": "3.6.2" 89 | } 90 | }, 91 | "nbformat": 4, 92 | "nbformat_minor": 2 93 | } 94 | -------------------------------------------------------------------------------- /unit_1/hw_2019/homework_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 1\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "Version 1.0 (1/17/2019)\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Probability\n", 21 | "\n", 22 | "The probability of an event or element in a sample space is written as $P(A)$, where $A$ is the event or element in the sample space. **Answer the following problems symbolically and simplified.** Each problem is worth 1 point.\n", 23 | "\n", 24 | "1. [2 points] Our sample space contains three elements: $Q = \\{A, B, C, D\\}$. What is the probability of observing $P(A \\,\\textrm{OR} \\,\\textrm{B}\\, \\textrm{OR}\\, C, \\textrm{OR} D)$\n", 25 | "\n", 26 | "2. [2 points] What has to be true of the two elements that are part of an OR statement? \n", 27 | "\n", 28 | "3. [2 points] Consider the sample space of months in a year and assume each month has equal probability. If event $E$ is elements $\\{\\textrm{September}, \\textrm{October}, \\textrm{December}\\}$, then what is the probability of the event $E$, $P(E)$?\n", 29 | "\n", 30 | "4. [2 points] What is the probability of observing September and then November?\n", 31 | "\n", 32 | "4. [2 points] What is the probability of not event $E$ from the previous question?\n", 33 | "\n", 34 | "5. [4 points] State the number of observations/samples for the probabilities specified in questions 1.1-1.5. " 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Die Probability\n", 42 | " \n", 43 | " You are rolling a die with **8 sides**. Event $A$ is that you roll a number less than 4. Event $B$ is that you roll a $6$. Event $C$ is rolling a number greater than 2. **Answer these problems using python code**. Each problem is worth 1 point.\n", 44 | " \n", 45 | "1. [1 point] What is the probability of event $A$?\n", 46 | "2. [1 point] If you roll a 4, what is then the probability of rolling event $A$ or $C$ on your next roll?\n", 47 | "4. [2 points] What is the probability of rolling event $A$ and event $C$ in the course of two rolls?\n", 48 | "3. [2 point] If you roll event $A$, on your next roll what is the probability of event $B$?\n", 49 | "5. [2 points] What is the probability of rolling event $A$ followed by event $C$?" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "# 3. Sample Spaces\n", 57 | "\n", 58 | "**Answers these problems symbolically**\n", 59 | "\n", 60 | "Each problem is worth 4 points\n", 61 | "\n", 62 | "1. [2 points] Each morning you grab one of your two necklaces randomly and then pick one of your three hats randomly. Both of these actions make up an observation. What is the single \"joined\" sample space?\n", 63 | "2. [1 point] What is the sample space for number of students attending lecture if there are 38 students enrolled? Do not report just the size.\n", 64 | "3. [1 point] You are trying to guess a 4 digit PIN. What's the sample space size?\n", 65 | "4. [1 point] You have an 8 character password which can contain lowercase letters, uppercase letters and numbers. What's the size of the sample space size? \n", 66 | "5. [1 point] You double the length of your password. What's the size of the sample size now?\n", 67 | "6. [4 points] Based on the previous problem, would a password that is a complete sentence (35 characters) with only lowercase letters be more or less secure than the previous problem? Justify your answer." 68 | ] 69 | } 70 | ], 71 | "metadata": { 72 | "kernelspec": { 73 | "display_name": "Python 3", 74 | "language": "python", 75 | "name": "python3" 76 | }, 77 | "language_info": { 78 | "codemirror_mode": { 79 | "name": "ipython", 80 | "version": 3 81 | }, 82 | "file_extension": ".py", 83 | "mimetype": "text/x-python", 84 | "name": "python", 85 | "nbconvert_exporter": "python", 86 | "pygments_lexer": "ipython3", 87 | "version": "3.6.3" 88 | } 89 | }, 90 | "nbformat": 4, 91 | "nbformat_minor": 2 92 | } 93 | -------------------------------------------------------------------------------- /unit_1/hw_2020/homework_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 1\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "Version 1.0 (1/17/2020)\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Probability\n", 21 | "\n", 22 | "The probability of an event or element in a sample space is written as $P(A)$, where $A$ is the event or element in the sample space. **Answer the following problems symbolically and simplified.**\n", 23 | "\n", 24 | "1. [2 points] Our sample space contains three elements: $Q = \\{1, 2, 3\\}$. What is the probability of observing $P(1 \\,\\textrm{OR} \\,2\\, \\textrm{OR}\\, 3)$?\n", 25 | "\n", 26 | "2. [2 points] What is the key differnce between $B_1$ and $B_2$ in these two expressions: $P( A \\,\\textrm{OR} \\,B_1)$ and $P(A \\,\\textrm{AND}\\, B_2)$ aside from the fact that OR is in the first expression and AND in the second. \n", 27 | "\n", 28 | "3. [2 points] Consider the sample space of days in 2020 and assume each day has equal probability. If event $E$ is elements $\\{\\textrm{September 3rd}, \\textrm{October 24th}, \\textrm{December 13th}\\}$, then what is the probability of the event $E$, $P(E)$?\n", 29 | "\n", 30 | "4. [2 points] What is the probability of not event $E$ from the previous question?\n", 31 | "\n", 32 | "5. [2 points] What is the probability of observing September 3rd and then September 4th?\n", 33 | "\n", 34 | "6. [4 points] State the number of observations/samples for the probabilities specified in questions 1.3-1.5. \n", 35 | " " 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "# Die Probability\n", 43 | " \n", 44 | " You are rolling a die with **6 sides**. Event $A$ is that you roll a 4. Event $B$ is that you roll a $6$. Event $C$ is rolling a number greater than 2. **Answer these problems using python code**. Each problem is worth 1 point.\n", 45 | " \n", 46 | "1. [1 point] What is the probability of event $A$?\n", 47 | "2. [1 point] If you roll a 4, what is then the probability of rolling event $A$ or $C$ on your next roll?\n", 48 | "3. [2 points] What is the probability of rolling event $A$ and event $C$ in the course of two rolls?\n", 49 | "4. [2 points] If you roll event $A$, on your next roll what is the probability of event $A$?\n", 50 | "5. [2 points] What is the probability of rolling event $A$ followed by event $B$?\n", 51 | "6. [4 points] What is the probability of having event $A$ occur within 10 rolls?" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "# 3. Sample Spaces\n", 59 | "\n", 60 | "**Answers these problems symbolically**\n", 61 | "\n", 62 | "1. [1 point] What could the sample space be for number of foxes on campus?\n", 63 | "2. [2 points] Each day I come to lecture with at most three whiteboard markers and each marker has ink or is out of ink. What is the sample space?\n", 64 | "3. [1 point] You are trying to guess a 10 digit phone numebr. What's the sample space size?\n", 65 | "4. [1 point] You have an 8 character password which can contain lowercase letters, uppercase letters, numbers, and 6 symbols (e.g., %, \\$, !). What's the size of the sample space size? \n", 66 | "5. [1 point] You double the length of your password. What's the size of the sample size now?\n", 67 | "6. [4 points] Many websites require having each of these characters (lowercase, uppercase, number). What is more effective, a 12 character password with only lowercase or an 8 character password requiring each of the extra classes?" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "# 4. Data Collection\n", 75 | "\n", 76 | "\n", 77 | "\n", 78 | "Choose two random things to observe over the course of the semester. Record your data youself and you should end up with at least 10 observations per month. Examples could be: screen time per day, time it takes to get to class, number of people you eat lunch with, colors in your outfit, number of birds in a particular tree, temperature at 9am.\n", 79 | "\n", 80 | "[8 points] write out the sample space of your two data and give an example of them." 81 | ] 82 | } 83 | ], 84 | "metadata": { 85 | "kernelspec": { 86 | "display_name": "Python 3", 87 | "language": "python", 88 | "name": "python3" 89 | }, 90 | "language_info": { 91 | "codemirror_mode": { 92 | "name": "ipython", 93 | "version": 3 94 | }, 95 | "file_extension": ".py", 96 | "mimetype": "text/x-python", 97 | "name": "python", 98 | "nbconvert_exporter": "python", 99 | "pygments_lexer": "ipython3", 100 | "version": "3.7.3" 101 | } 102 | }, 103 | "nbformat": 4, 104 | "nbformat_minor": 2 105 | } 106 | -------------------------------------------------------------------------------- /unit_1/lectures/lecture_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_1/lectures/lecture_1.pdf -------------------------------------------------------------------------------- /unit_10/hw_2018/Homework_10.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 10\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "5/5/2018\n", 12 | "\n", 13 | "----\n", 14 | "\n", 15 | "Homework Requirements:\n", 16 | "\n", 17 | "1. Write all equations in $\\LaTeX$\n", 18 | "2. Simplify all expressions\n", 19 | "2. Put comments in your Python code\n", 20 | "3. Explain or show your work\n", 21 | "4. Follow the academic honesty guidelines in the syllabus\n", 22 | "\n", 23 | "-----" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "1\\. Conceptual Questions (10 Points)\n", 31 | "====\n", 32 | "\n", 33 | "* 2 Points each *\n", 34 | "\n", 35 | "1. In the following picture, which color area corresponds to the p-value? \n", 36 | " ![image-not-visible](./pvalue.png)\n", 37 | "2. If a significance level goes up, is it easier or harder to reject a null hypothesis?\n", 38 | "3. If you only have one data point, which hypothesis test or tests can be used?\n", 39 | "4. Is it meaningful to perform a Wilcoxon Signed Rank Test if the two paired data are in different unit systems?\n", 40 | "5. We haven't learned about a \"binomial hypothesis test\", but what would the null hypothesis of such a test be and provide a situation where you would use it.\n", 41 | "\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "2\\. Hypothesis Tests (72 Points)\n", 49 | "====\n", 50 | "\n", 51 | "For the following questions, state the following in Markdown and show your numerical work in Python:\n", 52 | "\n", 53 | "* [2 points] The null hypothesis\n", 54 | "* [2 points] The choice of test\n", 55 | "* [6 points] $p$-value and if you are considering both tails\n", 56 | "* [2 point] If the null hypothesis is rejected\n", 57 | "\n", 58 | "*Each hypothesis test occurs once in the following, so make sure you do not repeat any of them!*\n", 59 | "\n", 60 | "1. On average, 3 people fall asleep in class. Today 11 fall asleep in class. Is this significant?\n", 61 | "2. Your average running pace over the last few years has been an 8:00 minute mile. You've tried changing running shoes and recorded the following paces on your most recent runs: 7:56, 7:45, 7:34, 8:05, 7:35. Is your running pace significantly different?\n", 62 | "3. You are comparing two batches of a compound prepared by different technicians. The following purities have been recorded for technician A: 0.87, 0.86, 0.88, 0.93, 0.85, 0.67 and the following by technician B: 0.86, 0.96, 0.90, 0.76, 0.87, 0.83, 0.84, 0.80. Are they achiving similar purity?\n", 63 | "4. You are assessing the efficacy of a drug that helps people lose weight. 13 people who enrolled had the following weights at admission and after 8 weeks of the drug:\n", 64 | "\n", 65 | "|Person|Weight at Start|Weight at 8 Weeks|\n", 66 | "|:----|:----:|----:|\n", 67 | "| 1 | 150 | 163 |\n", 68 | "| 2 | 212 | 194 |\n", 69 | "| 3 | 320 | 280 |\n", 70 | "| 4 | 250 | 265 |\n", 71 | "| 5 | 215 | 132 |\n", 72 | "| 6 | 186 | 172 |\n", 73 | "| 7 | 195 | 185 |\n", 74 | "| 8 | 203 | 187 |\n", 75 | "| 9 | 145 | 135 |\n", 76 | "| 10 | 168 | 140 |\n", 77 | "| 11 | 172 | 178 |\n", 78 | "| 12 | 240 | 211 |\n", 79 | "| 13 | 272 | 268 |\n", 80 | "\n", 81 | "is there a significant effect from the drug?\n", 82 | "\n", 83 | "5\\. A chemical refinery has input crude with a concentration of sulfor of 0.7% on average with a variance of 0.015%. A sample from the crude reveals a concentration of 1.2%. Is this significant enough that you should investigate?\n", 84 | "\n", 85 | "6\\. You are assessing if a correlation exists between literacy rate and birthrate. You've found the following data from countries:\n", 86 | "\n", 87 | "| Country | Literacy Rate | Birthrate per 1000 |\n", 88 | "| ---- | :-----------: | --------: |\n", 89 | "| Afghanistan | \t38.2% | 37.90 |\n", 90 | "| Belize | 82.7% | 24.00 |\n", 91 | "| Laos | 79.9%| 23.60|\n", 92 | "| Lebanon |\t93.9% | 14.30|\n", 93 | "| India |\t72.1% | 19.00 |\n", 94 | "| Russia | \t99.7% | 11.00|\n", 95 | "| Argentina | \t98.1% | 16.70|\n", 96 | "| South Africa \t| 94.3%| 20.20|\n", 97 | "|Venezuela | \t95.4%| 18.80 |\n", 98 | "| Cameroon | \t75% | 35.40|\n", 99 | "| Chad \t| 40.2%| 35.60| \n", 100 | "\n", 101 | "Is there a relationship between these two?" 102 | ] 103 | } 104 | ], 105 | "metadata": { 106 | "kernelspec": { 107 | "display_name": "Python 3", 108 | "language": "python", 109 | "name": "python3" 110 | }, 111 | "language_info": { 112 | "codemirror_mode": { 113 | "name": "ipython", 114 | "version": 3 115 | }, 116 | "file_extension": ".py", 117 | "mimetype": "text/x-python", 118 | "name": "python", 119 | "nbconvert_exporter": "python", 120 | "pygments_lexer": "ipython3", 121 | "version": "3.6.4" 122 | } 123 | }, 124 | "nbformat": 4, 125 | "nbformat_minor": 2 126 | } 127 | -------------------------------------------------------------------------------- /unit_10/hw_2018/pvalue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_10/hw_2018/pvalue.png -------------------------------------------------------------------------------- /unit_10/hw_2019/homework_10.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 10\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "*4/3/2019*\n", 11 | "\n", 12 | "----" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# 1. Conceptual Questions (12 Points)\n", 20 | "\n", 21 | "3 points each\n", 22 | "\n", 23 | "1. Describe the general process for parametric hypothesis tests.\n", 24 | "\n", 25 | "2. Why would you choose a non-parametric hypothesis test over a parametric one?\n", 26 | "\n", 27 | "3. Why would you choose a parametric hypothesis test over a non-parametric one?\n", 28 | "\n", 29 | "4. If you do not reject the null hypothesis, does that mean you've proved it?" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "# 2. Short Answer Questions (9 Points)\n", 37 | "\n", 38 | "1. [1 point] If your p-value is 0.4 and $\\alpha = 0.1$, should you reject the null hypothesis?\n", 39 | "2. [1 point] What is your p-value if your $T$-value is -2 in the two-tailed/two-sided $t$-test with a DOF of 4?\n", 40 | "3. [2 points] For a one-sample $zM$ test, what is the minimum number of standard deviations away from the population mean a sample should be to reject the null hypothesis with $\\alpha = 0.05$?\n", 41 | "4. [3 points]For an N-sample $zM$ test, what is the minimum number of standard deviations away from the population mean a sample should be to reject the null hypothesis with $\\alpha = 0.05$ in terms of $N$?\n", 42 | "5. [1 point] In a Poisson hypothesis test, what is the p-value if $\\mu = 4.3$ and the sample is 8?\n", 43 | "6. [1 point] What is the standard error for $\\bar{x} = 4$, $\\sigma_x = 0.4$ and $N = 11$?" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "# 3. Choose the hypothesis test (10 Points)\n", 51 | "\n", 52 | "State which hypothesis test best fits the example below **and state the null hypothesis**. You can justify your answer if you feel like mulitiple tests fit. \n", 53 | "\n", 54 | "1. You know that coffee should be brewed at 186 $^\\circ{}$F. You measure coffee from Starbuck 10 times over a week and want to know if they're brewing at the correct temperature.\n", 55 | "\n", 56 | "2. You believe that the real estate market in SF is the same as NYC. You gather 100 home prices from both markets to compare them. \n", 57 | "\n", 58 | "3. Australia banned most guns in 2002. You compare homicide rates before and after this date.\n", 59 | "\n", 60 | "4. A number of states have recently legalized recreational marijuana. You gather teen drug use data for the year prior and two years after the legislation took effect.\n", 61 | "\n", 62 | "5. You think your mail is being stolen. You know that you typically get five pieces of mail on Wednesdays, but this Wednesday you got no mail. " 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "# 4. Hypothesis Tests (18 Points)\n", 70 | "\n", 71 | "Do the following: \n", 72 | "\n", 73 | "1. [1 Point] State the test type\n", 74 | "2. [1 Point] State the null hypothesis\n", 75 | "3. [2 Points] State the p-value\n", 76 | "4. [1 Point] State if you accept/reject the null hypothesis\n", 77 | "5. [1 Point] Answer the question\n", 78 | "\n", 79 | "---\n", 80 | "\n", 81 | "1. You have heard an urban legend that you are taller in the morning. Using the height measurements in centimeters below, answer the question\n", 82 | "\n", 83 | "|Morning | Evening|\n", 84 | "|:---|----:|\n", 85 | "| 181 | 180 |\n", 86 | "| 182 | 179 |\n", 87 | "| 181 | 184 |\n", 88 | "| 182 | 179 |\n", 89 | "| 182 | 180 |\n", 90 | "| 183 | 183 |\n", 91 | "| 185 | 180 |\n", 92 | "\n", 93 | "2. On a typical day in Rochester, there are 11 major car accidents. On the Monday after daylight savings time in the Spring, there are 18 major car accidents. Is this significant?\n", 94 | "\n", 95 | "3. Your cellphone bill is typically \\\\$20. The last four have been \\\\$21, \\\\$30. \\\\$25, \\\\$23. Has it significantly changed?\n", 96 | "\n" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "# 5. Exponential Test (5 Bonus Points)\n", 104 | "\n", 105 | "Your dog typically greets you within 10 seconds of coming home. Is it significant that your dog took 16 seconds?" 106 | ] 107 | } 108 | ], 109 | "metadata": { 110 | "kernelspec": { 111 | "display_name": "Python 3", 112 | "language": "python", 113 | "name": "python3" 114 | }, 115 | "language_info": { 116 | "codemirror_mode": { 117 | "name": "ipython", 118 | "version": 3 119 | }, 120 | "file_extension": ".py", 121 | "mimetype": "text/x-python", 122 | "name": "python", 123 | "nbconvert_exporter": "python", 124 | "pygments_lexer": "ipython3", 125 | "version": "3.7.1" 126 | } 127 | }, 128 | "nbformat": 4, 129 | "nbformat_minor": 2 130 | } 131 | -------------------------------------------------------------------------------- /unit_10/hw_2020/homework_10.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 10\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "4/9/2020\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "## Problem 1 (10 Points)\n", 21 | "\n", 22 | "State which hypothesis test best matches the scenario and justify your answer. 2 points each.\n", 23 | "\n", 24 | "1. You have the historic mean and standard deviation of temperature for April and want to know if this year's temperature is significantly different.\n", 25 | "2. The number of days with snow in April is usually 4, this year it is 1. Is this significant?\n", 26 | "3. You take 5 measurements of snow depth in your front yard and 8 measurements in your backyard and want to know if they front and backyard have different amounts of snowfall.\n", 27 | "4. You have measured what day of the week it is and what time your phone battery goes dead. Is there a connection?\n", 28 | "5. You have measured how frequently your friends text you before and after COVID-19 quarantine and want to know if it has changed significantly." 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "# Problem 2 (24 Points)\n", 36 | "\n", 37 | "Choose and peform hypothesis tests for the following examples. **Report your p-values!!**.\n", 38 | "\n", 39 | "1. [4 points] The number of yellow skittles is on average 8 per bag. Your bag has 11. Is this significantly different?\n", 40 | "2. [4 points] You normally drink 8 oz of water with a standard deviation of 2 oz. Today you drank 12 oz. Is this significantly different?\n", 41 | "3. [6 points] Ting says your cellphone bill will be about \\\\$50 or lower if you switch. You switch and find your bills a are \\\\$48, \\\\$ 53, \\\\$67, \\\\$44. Was their claim correct?\n", 42 | "\n", 43 | "4. [4 points] You are testing the efficacy of a drug that causes weight loss. You have 15 patients try the drug. Their weights in pounds before are [178,189,136,134,172,171,178,179,154,159,167,149,125,180,135] and after are [174,178,139,133,166,165,172,180,141,145,176,151,108,174,131]. Is the drug effective?\n", 44 | "\n", 45 | "\n", 46 | "5. [6 points] You now add a control group which is given a placebo. Their before and after weights are [211,175,151,160,163,137,169,145,171,177,148,145,173,174,167] and [200,171,146,162,178,134,183,148,164,166,141,142,166,167,142]. Is your conclusion the same? Why or why not?" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "## Problem 3 (16 Points)\n", 54 | "\n", 55 | "Solve the following problems using optimization. **Report your answer in Markdown!**. 4 Points each\n", 56 | "\n", 57 | "1. Solve $\\tan x = x^2 + 1$. \n", 58 | "2. Minimize $(x - 4)^2$\n", 59 | "3. Is $x^2\\sin^2x$ non-convex or convex?\n", 60 | "4. Solve the following system of equations:\n", 61 | "\n", 62 | "$$\n", 63 | "x^2 - y = 18\n", 64 | "$$\n", 65 | "$$\n", 66 | "\\sqrt{x} + y^2 = 6\n", 67 | "$$" 68 | ] 69 | } 70 | ], 71 | "metadata": { 72 | "kernelspec": { 73 | "display_name": "Python 3", 74 | "language": "python", 75 | "name": "python3" 76 | }, 77 | "language_info": { 78 | "codemirror_mode": { 79 | "name": "ipython", 80 | "version": 3 81 | }, 82 | "file_extension": ".py", 83 | "mimetype": "text/x-python", 84 | "name": "python", 85 | "nbconvert_exporter": "python", 86 | "pygments_lexer": "ipython3", 87 | "version": "3.7.3" 88 | } 89 | }, 90 | "nbformat": 4, 91 | "nbformat_minor": 2 92 | } 93 | -------------------------------------------------------------------------------- /unit_10/lectures/grades.csv: -------------------------------------------------------------------------------- 1 | R1,R2,R3,R5,R6,HW1,HW2,HW3,HW4,HW5,HW6,Midterm 2 | 3,4,16,9,4,56,52,56,82,86,99,100 3 | 3,3,16,9,4,49,38,26,71,59,71,79 4 | 3,4,16,9,4,42,42,32,79,23,51,80 5 | 3,4,0,9,4,55,52,54.5,78,62,86,82 6 | 3,4,16,9,4,53,48,56,75.5,80,80,56 7 | 3,4,16,9,4,50,52,38,78.5,69,94,98 8 | 3,4,16,9,4,0,52,56,77.5,65,91,74 9 | 3,4,16,9,4,56,52,55,82,71,0,72 10 | 3,4,16,9,4,52,44,52,79.5,74.5,85,93 11 | 3,4,16,9,4,48,51,46,63,70,86,66 12 | 3,4,16,9,4,56,49,56,86,86,60,87 13 | 3,4,16,9,4,51,47,54,73,85.5,93,91 14 | 3,4,16,9,4,55,52,56,78.5,84.5,86,72 15 | 3,4,16,9,4,53,44,56,76,82,82,93 16 | 3,4,16,9,4,54,44,44,79.5,71,81,82 17 | 3,4,16,9,4,56,43,53,80,79,84,74 18 | 3,4,16,0,4,52,45,34,73,64.5,78,79 19 | 3,4,16,9,4,54,50,28,66,61.5,0,65 20 | 3,4,16,9,4,52,49,51,73,73.5,87,94 21 | 3,4,16,9,4,56,45,44,49.5,43,66,60 22 | 3,4,16,9,4,56,51.5,50,76,72,95,93 23 | 3,4,0,9,4,48,39,29,70,56,72,69 24 | 3,3,16,9,4,56,47,51,72,0,74,86 25 | 3,3.5,16,9,4,52,48,55,0,73,83,90 26 | 3,4,16,9,4,54,40,45,70,0,72.5,74 27 | 3,4,16,9,4,49,44,47,81.5,82,78,92 28 | 3,4,16,9,4,55,52,0,0,79,91,78 29 | 3,4,16,9,4,50.5,37,32,63,64,82,77 30 | 3,4,16,9,4,50,18,47,78,47,58,57 31 | 3,4,16,9,4,46,50,56,81,82,90,77 32 | 3,4,16,9,4,55,52,56,81,84,86,62 33 | 3,4,14,9,4,45,47,45,62.5,71,88,69 34 | 3,4,16,9,4,54,48,50,82,78,94,93 35 | 3,4,14,9,4,34,10,51,55,0,81,85 36 | 3,4,0,9,4,54,48,45,73,75,77,72 37 | 3,4,14,9,4,56,48,51,81.5,86,94,81 38 | 3,4,14,9,4,55,50,45,80.5,76,84,80 39 | 3,4,14,9,4,37,46,44,77.5,47,78,77 40 | 3,4,14,9,4,56,42,28,81.5,86,79,83 41 | 3,0,14,9,4,30,17,18,60.5,11,4,52 42 | 3,4,14,9,4,54,52,29,79,80,90,83 43 | 3,4,0,9,0,55.5,48,38,78,79,81,77 44 | 3,4,16,0,0,53,52,44,82,0,73,89 45 | 3,4,0,9,0,26,12,12,0,10,7,49 46 | 3,4,16,9,0,54,48,56,82,85.5,97,85 47 | 3,4,16,9,0,39,26,25.5,70,79,97,57 48 | 3,4,0,9,0,53,52,43,82,82,83,91 49 | 3,0,16,9,0,56,52,43,82,79,85,75 50 | 3,4,16,9,0,43,45,48,62,72,76,69 51 | 3,4,16,9,0,47,38,36,82,73,69,93 52 | 3,4,0,9,4,50,39,34,54,61,72,81 53 | 3,4,16,9,4,56,52,55,80,82,82.5,61 54 | 3,4,16,9,4,49,50,53,77,67,73,70 55 | 3,4,16,9,4,40,44,33,69.5,41,73,85 56 | 3,4,16,9,4,53,52,37,77,80,78,80 57 | 3,4,16,9,4,45,50,32,75.5,58,81,83 58 | 3,4,16,0,4,38,25.5,24,30.5,34,60,79 59 | 3,4,16,9,4,49,44,53,67,82,85,97 60 | 2.5,4,16,9,4,42,46,44,73,82,82,72 61 | 2.5,4,16,9,4,44,43,50,57,64,70,54.5 62 | 0,0,16,9,0,0,0,25,75.5,70.5,94,79 63 | 0,0,16,9,0,41,0,23,26.5,22,74,44 64 | 0,0,0,9,4,0,0,25,76,79.5,64,87 65 | 0,4,16,9,4,39,52,47,79,75,71,64 66 | 0,0,0,0,0,0,0,0,0,0,0,0 67 | -------------------------------------------------------------------------------- /unit_11/hw_2018/Homework_11.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 11\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "4/12/2018\n", 12 | "\n", 13 | "----\n", 14 | "\n", 15 | "Homework Requirements:\n", 16 | "\n", 17 | "1. Write all equations in $\\LaTeX$\n", 18 | "2. Simplify all expressions\n", 19 | "2. Put comments in your Python code\n", 20 | "3. Explain or show your work\n", 21 | "4. Follow the academic honesty guidelines in the syllabus\n", 22 | "\n", 23 | "-----" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Answer each using Python and Markdown. First, state what type of optimization (2 points), the number of dimensions (1 point), if it's convex (1 points), and if there are bounds or constraints (2 points). Next, write out any constraints or rearrangements of equations in Markdown. For example, if you use root finding you should write out the expression for which you're finding roots (e.g., $x^2 = 4$ becomes $x^2 - 4 = 0$). Solve the problem ( 6 points) and then graph your solution (4 points). **You must make a graph showing a graph of the equation and the otpimum point for each problem** 16 points per problem. You must also print your numerical answer.\n", 31 | "\n", 32 | "### 1\\. \n", 33 | "\n", 34 | "Solve the following equation\n", 35 | "\n", 36 | "$$\n", 37 | "\\sin x = \\sqrt{x} \\ln x\n", 38 | "$$\n", 39 | "\n", 40 | "### 2\\. \n", 41 | "\n", 42 | "Find the minimum value for this expression: \n", 43 | "\n", 44 | "$$\n", 45 | "x^4 - x^2 - x\n", 46 | "$$\n", 47 | "\n", 48 | "### 3\\. \n", 49 | "\n", 50 | "Find the positive root for this expression. Specify bounds in your call to the optimization function\n", 51 | "\n", 52 | "$$\n", 53 | "\\frac{x^3(1 - x)}{x^2 - x + 2} = -\\frac{1}{10}\n", 54 | "$$\n", 55 | "\n", 56 | "### 4\\.\n", 57 | "\n", 58 | "Take $p$ to be a probability. Find the maximum value for the following expression:\n", 59 | "\n", 60 | "$$\n", 61 | "p^{8} (1 - p)^{2}\n", 62 | "$$\n", 63 | "\n", 64 | "### 5\\. \n", 65 | "\n", 66 | "Minimize the following problem where $x$ and $y$ are bounded to lie between $-\\pi$ and $\\pi$.\n", 67 | "\n", 68 | "$$\n", 69 | "\\cos 3.1x \\sin 5.2y + \\frac{(x + y - 2)^2}{250}\n", 70 | "$$\n", 71 | "\n", 72 | "The following snippet will plot the function in 3D\n", 73 | "\n", 74 | "```python\n", 75 | "import numpy as np\n", 76 | "from mpl_toolkits.mplot3d import Axes3D\n", 77 | "from matplotlib import cm\n", 78 | "import matplotlib.pyplot as plt\n", 79 | "\n", 80 | "def fxn_5(x, y):\n", 81 | " return 2 * np.cos(3.1 * x) * np.sin(5.2 * y) + (x + y - 2)**2 / 250\n", 82 | "x = np.linspace(- np.pi, np.pi, 100)\n", 83 | "y = np.linspace(-np.pi, np.pi, 100)\n", 84 | "xx, yy = np.meshgrid(x, y, sparse=True)\n", 85 | "\n", 86 | "z = fxn_5(xx, yy)\n", 87 | "\n", 88 | "plt.contourf(x,y,z, cmap=cm.plasma)\n", 89 | "plt.colorbar()\n", 90 | "plt.show()\n", 91 | "\n", 92 | "```\n", 93 | "\n", 94 | "### 6\\.\n", 95 | "\n", 96 | "\n", 97 | "Maximize the following equation subject to the following constraints $x_0 > 0$, $x_1 > 0$, $ x_0 + x_1 = 1$. You do not need to plot this.\n", 98 | "\n", 99 | "$$\n", 100 | "f(x_0, x_1) = e^{-(x_0 - 4)^2}e^{-(x_1 + 2)^2}\n", 101 | "$$\n", 102 | "\n", 103 | "\n", 104 | "### 7\\.\n", 105 | "\n", 106 | "Solve the following system of equations. Remember that if there are multiple solutions, it is non-convex. You do not need to plot this problem\n", 107 | "\n", 108 | "$$\n", 109 | "xy - z = 1\n", 110 | "$$\n", 111 | "$$\n", 112 | "x + z = -2\n", 113 | "$$\n", 114 | "$$\n", 115 | "x^2 -y + z = 3\n", 116 | "$$" 117 | ] 118 | } 119 | ], 120 | "metadata": { 121 | "kernelspec": { 122 | "display_name": "Python 3", 123 | "language": "python", 124 | "name": "python3" 125 | }, 126 | "language_info": { 127 | "codemirror_mode": { 128 | "name": "ipython", 129 | "version": 3 130 | }, 131 | "file_extension": ".py", 132 | "mimetype": "text/x-python", 133 | "name": "python", 134 | "nbconvert_exporter": "python", 135 | "pygments_lexer": "ipython3", 136 | "version": "3.6.3" 137 | } 138 | }, 139 | "nbformat": 4, 140 | "nbformat_minor": 2 141 | } 142 | -------------------------------------------------------------------------------- /unit_11/hw_2019/Homework_11.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 11\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "*4/11/2019*\n", 11 | "\n", 12 | "----" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# 1. Conceptual Questions\n", 20 | "\n", 21 | "1. What is the difference between a bound and a constraint?\n", 22 | "2. What must you consider before choosing a method for minimization?\n", 23 | "3. Give an example of a non-convex problem you might see in chemical engineering. " 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "# 2. Optimization Problems\n", 31 | "\n", 32 | "Solve and plot the following expressions using python. Plot a red dot at your solution.\n", 33 | "\n", 34 | "1. Find all roots of this expression:\n", 35 | "\n", 36 | "$$\n", 37 | "\\frac{(x−4)^4}{8}+ \\frac{(x−2)^2}{2} - 4\n", 38 | "$$\n", 39 | "\n", 40 | "2. Find the minimum of this expression with $r$ bounded to be $[0.9,3]$\n", 41 | "\n", 42 | "$$\n", 43 | "4\\left[\\frac{1}{r^8} - \\frac{1}{r^4}\\right]\n", 44 | "$$\n", 45 | "\n", 46 | "\n", 47 | "3. Solve $e^{x / 4} = x$\n", 48 | "\n", 49 | "4. You do not need to plot this problem. Solve the following system of equations and report your answer.\n", 50 | "\n", 51 | "$$\n", 52 | "2\\sqrt{x} - 3 \\cos z = 3\n", 53 | "$$\n", 54 | "\n", 55 | "$$\n", 56 | "2 x - z^2 = 18\n", 57 | "$$" 58 | ] 59 | } 60 | ], 61 | "metadata": { 62 | "kernelspec": { 63 | "display_name": "Python 3", 64 | "language": "python", 65 | "name": "python3" 66 | }, 67 | "language_info": { 68 | "codemirror_mode": { 69 | "name": "ipython", 70 | "version": 3 71 | }, 72 | "file_extension": ".py", 73 | "mimetype": "text/x-python", 74 | "name": "python", 75 | "nbconvert_exporter": "python", 76 | "pygments_lexer": "ipython3", 77 | "version": "3.7.1" 78 | } 79 | }, 80 | "nbformat": 4, 81 | "nbformat_minor": 2 82 | } 83 | -------------------------------------------------------------------------------- /unit_12/hw_2018/Homework_12.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 12\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "4/19/2018\n", 12 | "\n", 13 | "----\n", 14 | "\n", 15 | "Homework Requirements:\n", 16 | "\n", 17 | "1. Write all equations in $\\LaTeX$\n", 18 | "2. Simplify all expressions\n", 19 | "2. Put comments in your Python code\n", 20 | "3. Explain or show your work\n", 21 | "4. Follow the academic honesty guidelines in the syllabus\n", 22 | "\n", 23 | "-----" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "1\\. Conceptual Questions (20 Points)\n", 31 | "====\n", 32 | "\n", 33 | "*Answer in Markdown* 2 Points each\n", 34 | "\n", 35 | "1. What assumption do we make on the noise terms when doing linear regression? How can we check it?\n", 36 | "\n", 37 | "2. Your friend tells you that it's important to minimize both the SSR and TSS. What's wrong with minimizing the TSS?\n", 38 | "\n", 39 | "3. How do you justify the presence of a slope?\n", 40 | "\n", 41 | "4. What is the best numeric value or statistic for justifying the existence of a correlation?\n", 42 | "\n", 43 | "5. What should you plot to justify an ordinary 4-dimensional least squares regression?\n", 44 | "\n", 45 | "6. Why do we use different number of deducted degrees of freedom when doing hypothesis testing vs performing the regression?\n", 46 | "\n", 47 | "7. Write a model equation for 3-dimensional ordinary least squares regression with an intercept. For example, a one dimensional model equation without an intercept would be $y = \\beta_0 x + \\epsilon$\n", 48 | "\n", 49 | "8. Write a model equation for when $y \\propto \\ln{x}$. Assume no intercept\n", 50 | "\n", 51 | "9. Write a model equation for a person's life expectancy ($l$) assuming it depends on gender ($s$) and if the person eats vegetables ($v$). Assume for this problem that gender and eating vegetables are both binary (0 or 1). \n", 52 | "\n", 53 | "10. Write a model equation for homework performanced ($h$) based on music genre listended to while working. The following genres are conisdered: Kwaito, Electroswing, and Djent Metal. You can only listen to one genre at a time. Use the letters $k$, $e$, and $d$." 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "2\\. Short Answer Questions (16 Points)\n", 61 | "====\n", 62 | "\n", 63 | "*Answer in Python or Markdown as appropiate* 4 Points each\n", 64 | "\n", 65 | "1. If $\\sigma_{xy} = -2.1$, $\\sigma_{x}^2 = 3.5$, $\\sigma_{y}^2 = 1.7$, what is the best fit slope? How does it change if the intercept is $-2.1$?\n", 66 | "\n", 67 | "2. If your model equation is $y = \\beta_0 + \\beta_1 x + \\beta_2 z + \\epsilon$, what is the deducted degrees of freedom?\n", 68 | "\n", 69 | "3. If $N = 12$, $D = 2$, and $S^2_{\\beta_0} = 2.5$, what is the width of a 90% confidence interval for $\\beta_0$?\n", 70 | "\n", 71 | "4. If your best fit intercept is $\\hat{\\alpha} = 3$ with a standard error of $0.7$, what is the $p$-value for the existence of the that intercept? Take $N = 15$ and assume it's 1D OLS.\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "3\\. Linearized Regression (24 Points)\n", 79 | "===\n", 80 | "\n", 81 | "Regress the following data to the model equation $y = \\beta_0 \\ln x + \\beta_1 x + \\beta_2 +\\epsilon$ using a linearization so that you use ND OLS. Report the following:\n", 82 | "\n", 83 | "1. [4 points] Justification for regression. Use words and statistics.\n", 84 | "2. [12 points] Fit coefficients with 95% confidence intervals.\n", 85 | "3. [4 points] Plot fit\n", 86 | "4. [4 points] Show if residuals are normal\n", 87 | "\n", 88 | "```python\n", 89 | "x = [0.2, 0.29, 0.39, 0.48, 0.57, 0.66, 0.76, 0.85, 0.94, 1.04, 1.13, 1.22, 1.31, 1.41, 1.5]\n", 90 | "y = [2.92, 2.58, 3.18, 4.27, 4.5, 3.93, 4.32, 4.57, 4.55, 4.7, 5.02, 4.21, 3.04, 4.98, 6.45]\n", 91 | "```" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "4\\. Non-Linear Regression (12 Points)\n", 99 | "====\n", 100 | "\n", 101 | "Repeat problem 3 with non-linear least squares instead. Only do the computation of the coefficients with confidence intervals. Be sure to write out your partials making up your $F$-matrix in markdown." 102 | ] 103 | } 104 | ], 105 | "metadata": { 106 | "kernelspec": { 107 | "display_name": "Python 3", 108 | "language": "python", 109 | "name": "python3" 110 | }, 111 | "language_info": { 112 | "codemirror_mode": { 113 | "name": "ipython", 114 | "version": 3 115 | }, 116 | "file_extension": ".py", 117 | "mimetype": "text/x-python", 118 | "name": "python", 119 | "nbconvert_exporter": "python", 120 | "pygments_lexer": "ipython3", 121 | "version": "3.6.3" 122 | } 123 | }, 124 | "nbformat": 4, 125 | "nbformat_minor": 2 126 | } 127 | -------------------------------------------------------------------------------- /unit_12/hw_2019/Homework_12.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 12\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "4/18/2019\n", 12 | "\n", 13 | "----\n" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Conceptual Questions (22 Points)\n", 21 | "\n", 22 | "*Answer in Markdown* 2 Points each\n", 23 | "\n", 24 | "1. What do we assume about noise in linear regression? Why is that often a reasonable assumption?\n", 25 | "\n", 26 | "2. Why are there no equations for an intercept for multidimensional ordinary least-squares regression?\n", 27 | "\n", 28 | "3. How could you justifiy using this simpler model $y = \\beta_1 x + \\beta_0 + \\epsilon$ over this one $y = \\beta_2 x^2 + \\beta_1 x + \\beta_0 + \\epsilon$ \n", 29 | "\n", 30 | "4. What two ways can you assess correlation **before** doing a regression?\n", 31 | "\n", 32 | "5. How might you justify correlation after regression? \n", 33 | "\n", 34 | "6. What is the model equation for a linearized version of $r = A e^{-E / RT}$ where you have $T$ and $r$ measurements?\n", 35 | "\n", 36 | "7. Is it valid to use OLS-ND for this linearized model?\n", 37 | "\n", 38 | "8. Write a model equation for how smoking affects someone's life expectancy. Indicate smoking with $s$.\n", 39 | "\n", 40 | "9. Write a model equation for how smoking and drinking affects life expectancy. Indicate drinking with $d$\n", 41 | "\n", 42 | "10. You can drink only coke, diet coke, diet pepsi, or pepsi. Write a model equation for choice of soda on IQ. \n", 43 | "\n", 44 | "11. What is attenuation error?" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "# 2. Linear Regression (25 Points)\n", 52 | "\n", 53 | "Report the p-values, confidence intervals, and justify your regression for the following linear data: \n", 54 | "Break your answer into three parts:\n", 55 | "\n", 56 | "1. [5 Points] Compute Regression\n", 57 | "2. [5 Points] Plot Regression\n", 58 | "3. [5 Points] Evaluate Fit\n", 59 | "4. [10 Points] Error (p-values and confidence intervals)\n", 60 | "\n", 61 | "```\n", 62 | "x = [0.5,1.3, 2.1, 1.0, 2.1, 1.7, 1.2, 3.9, 3.9, 1.5, 3.5, 3.9, 5.7, 4.7, 5.8, 4.6, 5.1, 5.9, 5.5, 6.4, 6.7, 7.8, 7.4, 6.7, 8.4, 6.9, 10.2, 9.7, 10.0, 9.9]\n", 63 | "y = [-1.6,0.5, 3.0, 3.1, 1.5, -1.8, -3.6, 7.0, 8.6, 2.2, 9.3, 3.6, 14.1, 9.5, 14.0, 7.4, 6.4, 17.2, 11.8, 12.2, 18.9, 21.9, 20.6, 15.7, 23.7, 13.6, 26.8, 22.0, 27.5, 23.3]\n", 64 | "```" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "# 3. More Regression (25 Points)\n", 72 | "\n", 73 | "Using this model equation: $y = \\beta_1 \\ln x + \\beta_0$, regress the following data. Break your answer into three parts:\n", 74 | "\n", 75 | "1. [5 Points] Compute Regression\n", 76 | "2. [5 Points] Plot Regression\n", 77 | "3. [5 Points] Evaluate Fit\n", 78 | "4. [10 Points] Error (p-values and confidence intervals)\n", 79 | "\n", 80 | "```\n", 81 | "x = [1.4,2.3, 3.7, 5.3, 6.6, 8.2, 10.2, 11.8, 12.7, 13.3, 14.6, 17.3, 18.6, 19.5, 21.6, 22.7, 23.6, 24.1]\n", 82 | "y = [1.0,0.3, -0.1, -0.1, -0.3, -0.4, -0.4, -0.5, -0.4, -0.5, -0.4, -0.6, -0.8, -0.8, -0.6, -0.9, -0.7, -1.1]\n", 83 | "```" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "language": "python", 91 | "name": "python3" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.7.1" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 2 108 | } 109 | -------------------------------------------------------------------------------- /unit_13/hw_2015/Homework_12.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:4c9e051d40b5f0ce16e8ae7ebc041ae259466cf97960e65094f1f59c8113b4fc" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "Homework 12\n", 16 | "====\n", 17 | "####CHE 116: Numerical Methods and Statistics\n", 18 | "Prof. Andrew White\n", 19 | "\n", 20 | "Version 1.1 (4/9/2015)\n", 21 | "\n", 22 | "----" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "1. Rearranging ODEs (4 Points)\n", 30 | "====\n", 31 | "Convert the following ODEs into standard form. If it is a second-order, make sure you specify both dimensions.\n", 32 | "\n", 33 | " 1. $\\frac{dx}{dt} - t = 2$\n", 34 | " \n", 35 | " 2. $\\frac{dx}{dt} = -rx$\n", 36 | " \n", 37 | " 3. $\\frac{d^2x}{dt^2} + k x = \\sin t$\n", 38 | " \n", 39 | " 4. $\\frac{d^2x}{dt^2} + b \\frac{dx}{dt} + k x = 0$" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "2. Solve This ODE (6 Points)\n", 47 | "===\n", 48 | "\n", 49 | "Solve the tank problem from lecture:\n", 50 | "\n", 51 | "$$\\frac{dV}{dt} + k_1 \\sqrt{V} = k_2$$\n", 52 | "\n", 53 | "and use $k_1 = 1$, $k_2 = 4$. Plot the solution from $t=0$ to $t=25$ with the initial condition that $V_0 = 10$" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "3. Solve This Other ODE (6 Points + 2 EC)\n", 61 | "====" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "Solve a forced, dampened ODE governed by this equation:\n", 69 | " \n", 70 | "$$\\frac{d^2x}{dt^2} + \\frac{1}{10}\\frac{dx}{dt} + k x = 5e^{-c / t}$$\n", 71 | "\n", 72 | "using $c=0.25$ and $k=2.5$. For 2 points extra credit, instead create an interactive widget. Use an initial condition of position 0.0 and velocity 1.0." 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "4. Linear Algebra (3 Points)\n", 80 | "===\n", 81 | "\n", 82 | "Given that:\n", 83 | "\n", 84 | "$$\\mathbf{A} = \\left[\\begin{array}{lcr}\n", 85 | "7 & 0 & 1\\\\\n", 86 | "1 & 3 & 4\\\\\n", 87 | "4 & 5 & 2\\\\\n", 88 | "\\end{array}\\right]$$\n", 89 | "\n", 90 | "$$\\mathbf{b} = \\left[\\begin{array}{lcr}\n", 91 | "4\\\\\n", 92 | "13\\\\\n", 93 | "-6\\\\\n", 94 | "\\end{array}\\right]$$\n", 95 | "\n", 96 | "Answer the following problems:\n", 97 | "\n", 98 | "1. What is $\\mathbf{A}\\mathbf{b}$?\n", 99 | "\n", 100 | "1. What is the largest eigenvector of $\\mathbf{A}$?\n", 101 | "\n", 102 | "2. Solve $\\mathbf{A}\\mathbf{x} = \\mathbf{b}$" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "collapsed": false, 108 | "input": [], 109 | "language": "python", 110 | "metadata": {}, 111 | "outputs": [] 112 | } 113 | ], 114 | "metadata": {} 115 | } 116 | ] 117 | } -------------------------------------------------------------------------------- /unit_16/lectures/fuel_cell.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_16/lectures/fuel_cell.xlsx -------------------------------------------------------------------------------- /unit_2/hw_2016/homework_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 2\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "Version 1.3 (1/19/2016)\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "1. Combiations and Permutations (8 Points)\n", 21 | "====\n", 22 | "\n", 23 | "1. [1 point] How many ways can you rearrange the letters 'fodbar'?\n", 24 | "2. [1 point] How many ways can the 75 students in this class enter the classroom? How does that compare to the number of atoms in the universe $\\left(10^{80}\\right)$\n", 25 | "3. [1 point] A family may have up to 4 cars. On a street with 3 families, how many permutations of car ownership among the 3 familaies can their be?\n", 26 | "4. [1 point] You and your friends are playing a MOBA game and there are 100 characters you can use. You may only be one character. You play as a team of 5 characters with no repeated characters. How many character combinations can be on one team?\n", 27 | "5. [4 points] How many unqiue match-ups of 5 vs 5 teams can there be for this MOBA game? *Hint: This will be a product of a few equations. Start by asking how many combinations of 10 there are and then think about splitting those up into 2 teams*. " 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "2. Two Dice (8 Points)\n", 35 | "===\n", 36 | "\n", 37 | "1. What is the sample space size for 2 dice?\n", 38 | "2. [2 points] Is the sum of the 2 dice, $S(roll)$,an event, element of the sample space or random variable? What is $P(S = s)$?\n", 39 | "3. [2 points] What are the minimum and maximum values for $P(s)$ and $S$?\n", 40 | "4. [2 points] What is the expected value of $S$?\n", 41 | "5. You are playing the game craps, where on the first roll a sum of 2,3 and 12 results in an immediate loss. If you know that you lost after the first roll, what is the probability of the sum of dice? That is, what is $P(s\\,|\\, \\textrm{loss})$? Show your work using the *definition of a conditional distribution* equation." 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "3. Playing the Lottery (13 Poitns)\n", 49 | "====\n", 50 | "To play the megamillions, you chose 5 unique numbers from 1 to 75 and then one number from 1 to 15 that can overlapp with the previous 5. The first 5 numbers are note replaced, meaning during the drawing there are no repeated numbers. Each ticket costs \\$2. Consider the following:\n", 51 | "\n", 52 | "1. [2 points] What is the sample space size for the lottery?\n", 53 | "2. [1 point] What is the probability of winning the lottery (matching all numbers)?\n", 54 | "3. [2 points] What is the expected value (in dollars) of the lottery as a function of jackpot amount? How big should the jackpot be for the expected value of playing exceed the cost of a ticket?\n", 55 | "4. [2 points] Assume that each ticket costs \\$2 and 50% goes to the jackpot (the other is kept for profit). How many people must be playing for the expected value to exceed the price of a ticket?\n", 56 | "5. [4 ponits] Given the answer from part 4, what is the probability that no one else wins? Answer symbolically and numerically. \n", 57 | "6. [2 points] Let's simplify (we'll revisit later) and assume that if someone else wins, you collect half the jackpot. What's the expected value now?" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "4. Countries & Career (8 Points)\n", 65 | "=====\n", 66 | "\n", 67 | "You are a baby being carried in a stork to your parents. Your parents live in either:\n", 68 | "\n", 69 | "1. USA (u, 320)\n", 70 | "2. China (c, 1300)\n", 71 | "3. Germany (g, 80)\n", 72 | "\n", 73 | "The probability of your birth location is proportional to the populations. As a baby, you are concerned with your career options, which are\n", 74 | "\n", 75 | "1. Rock star (r)\n", 76 | "2. Professor (p)\n", 77 | "3. Doctor (d)\n", 78 | "\n", 79 | "Answer the following using $B$ as the random variable for birthplace and $J$ as the random variable for job. We have the following information:\n", 80 | "\n", 81 | "$$P(J = r \\,|\\, B = c) = 0.05$$\n", 82 | "\n", 83 | "$$P(J = d \\,|\\, B = c) = 0.5$$\n", 84 | "\n", 85 | "$$P(J = r \\,|\\, B = u) = 0.8$$\n", 86 | "\n", 87 | "$$P(J = p\\,|\\, B = u) = 0.01$$\n", 88 | "\n", 89 | "$$P(J = p\\,|\\, B = g) = 0.75$$\n", 90 | "\n", 91 | "$$P(J = d \\,|\\, B = g) = 0.2$$\n", 92 | "\n", 93 | "1. [2 points] What is the probability that you will be a rockstar?\n", 94 | "2. [2 points] What is the probability that you will be a professor born in China?\n", 95 | "3. [1 point] You were born in Germany, what's the probability of becoming a rock star?\n", 96 | "4. [2 points] Consider the random variable $Z$, which indicates if you have a college degree (true for $J=d$ and $J=p$). What is $P(Z \\,|\\, B=g)$?\n", 97 | "5. [1 points] What is $P(B=u \\,|\\, Z)$?\n" 98 | ] 99 | } 100 | ], 101 | "metadata": { 102 | "kernelspec": { 103 | "display_name": "Python 2", 104 | "language": "python", 105 | "name": "python2" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": { 109 | "name": "ipython", 110 | "version": 2 111 | }, 112 | "file_extension": ".py", 113 | "mimetype": "text/x-python", 114 | "name": "python", 115 | "nbconvert_exporter": "python", 116 | "pygments_lexer": "ipython2", 117 | "version": "2.7.11" 118 | } 119 | }, 120 | "nbformat": 4, 121 | "nbformat_minor": 0 122 | } 123 | -------------------------------------------------------------------------------- /unit_2/hw_2019/homework_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 2\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "1/24/2019\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Combinations and Permutation\n", 21 | "\n", 22 | "**For each problem, write out the number of objects ($n$), the length of the sequence/sample ($l$), and if repeats are allowed. 1 point for this on each problem**\n", 23 | "\n", 24 | "1. [2 points] How many ways can you rearrange the letters in the word \"Python\"?\n", 25 | "2. [2 points] How many ways can you erarrange the letters in the word \"Coffee\"?\n", 26 | "3. [2 points] You have 5 close friends and you are choosing which 3 friends will be in your wedding party. How many ways could you choose your that friends that will be in your wedding party?\n", 27 | "4. [3 points] You now cannot decide either how many to be in your wedding party nor which friends to choose. Assuming you could have between 0 and 5 friends in the wedding party, how many ways could you choose them?\n", 28 | "5. [2 points] Quarks can have a \"color charge\" of red, blue, or green. If you have 5 distinguishable quarks, how many perumutations of charges could the quarks have?\n", 29 | "6. [2 points] Now the quarks are indistinguishable. How many permutations of quarks could you have?\n" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "# Stereo Chemistry\n", 37 | "\n", 38 | "1. [2 points] Consider an sp3 carbon atom. What elements could be bonded to carbon to satisfy its valencey? Only choose reasonable elements you would find in typical organic molecules. \n", 39 | "2. [6 points] With one sp3 carbon atom and the elements you've chosen, how many compounds are there? What role does distinguishability play? Connect distinguishability with the conecpt of enantiomers." 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "# Medical Diagnosis\n", 47 | "\n", 48 | "**You do not need to use conditional probability to solve this problem**\n", 49 | "\n", 50 | "We are evaluating a new test to screen for Ebola that claims to identify Ebola in patients before symptoms are present . We want to use this test to quarantine probable cases to prevent the spread of Ebola. People can either not have Ebola or have Ebola and our test can be positive or negative. Let's take the random variable $E$ to indicate if the patient has Ebola and $T$ to indicate if the test is positive. We had 100 patients in our study who were at risk for Ebola. Our test indicated that 74 of the patients had Ebola and were quarantined to see if symptomps presented. After one week when symtpoms presented, we determined that 2 patients were not caught by the test and 6 patients presented with Ebola. The remianing patients did not have Ebola.\n", 51 | "\n", 52 | "1. [1 point] Write out the sample space\n", 53 | "\n", 54 | "2. [1 point] What is the marginal probability of having Ebola?\n", 55 | "\n", 56 | "3. [1 point] What is the marginal probability of having a positive test result?\n", 57 | "\n", 58 | "3. [2 points] Compute $P(E = 1, T = 1)$\n", 59 | "\n", 60 | "4. [3 points] What concept did we learn that could tell us whether or not the test is effective? How could we make a numeric argument?\n", 61 | "\n", 62 | "5. [3 points] Is there compelling numerical evidence that the test is effective?" 63 | ] 64 | } 65 | ], 66 | "metadata": { 67 | "kernelspec": { 68 | "display_name": "Python 3", 69 | "language": "python", 70 | "name": "python3" 71 | }, 72 | "language_info": { 73 | "codemirror_mode": { 74 | "name": "ipython", 75 | "version": 3 76 | }, 77 | "file_extension": ".py", 78 | "mimetype": "text/x-python", 79 | "name": "python", 80 | "nbconvert_exporter": "python", 81 | "pygments_lexer": "ipython3", 82 | "version": "3.6.4" 83 | } 84 | }, 85 | "nbformat": 4, 86 | "nbformat_minor": 2 87 | } 88 | -------------------------------------------------------------------------------- /unit_2/hw_2020/homework_2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 2\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "1/23/2020\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Combinations and Permutation\n", 21 | "\n", 22 | "**For each problem, write out the number of objects ($n$), the length of the sequence/sample ($l$), if repeats are allowed, and if you are computing permutations or combinations.**\n", 23 | "\n", 24 | "1. [2 points] How many ways can you rearrange the letters in the word \"serif\"?\n", 25 | "2. [2 points] How many ways can you rearrange the letters in the word \"sans\"?\n", 26 | "3. [3 points] You are trying to decide which days of the week you will exercise. If you can exercise once or not at all on each day, how many ways can you choose?\n", 27 | "4. [3 points] You have instead decided that you should exercise four days per week. How many ways can you arrange your weekly exercise plan?\n", 28 | "5. [3 points] You are playing five games against your friend. You can either win, draw, or tie. How many possible scores (total number of wins, losses, ties) can occur?\n", 29 | "6. [3 points] You are playing five friends one at a time in the same type of game. How many scores are possible if you break them out per friend (wins, losses, ties against friend 1, wins losses ties against friend 2, ...)\n", 30 | "7. [5 points] You are manufacturing ink in a batch reactor. You need to manufactor five different colors per day and each color takes 1 hours. Assuming you can only begin/end on the hour, how many possibles schedules could you create?" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# 2. Working with Probability Expressions\n", 38 | "\n", 39 | "Simplfiy the following expression and write in words the probability law or definition being used to go from the left-hand-side to the right-hand-side. There should be no intermediate steps. **Answer the following questions in Markdown**. Worth 2 points each\n", 40 | "\n", 41 | "$\\DeclareMathOperator{\\P}{P}$\n", 42 | "$\\DeclareMathOperator{\\E}{E}$\n", 43 | "\n", 44 | "\n", 45 | "1. $\\sum_{y \\in \\mathcal{Y}}\\P(X = 3 | Y = y)P(Y = y) = $\n", 46 | "\n", 47 | "\n", 48 | "2. If $y$ and $x$ are independent: $\\P(X = 0|Y = 1) = $\n", 49 | "\n", 50 | "\n", 51 | "3. $\\sum_{y \\in \\mathcal{Y}}\\P(X = -1, Y = y) = $\n", 52 | "\n", 53 | "\n", 54 | "4. $\\sum_{x \\in \\mathcal{X}}\\P(X = x | Y = 1) = $\n", 55 | "\n", 56 | "\n", 57 | "5. $\\frac{\\P(X = 4,Y = 1)}{\\P(Y = 1)} = $\n", 58 | "\n", 59 | "\n", 60 | "6. If $x,y$ are conditionally independent on $z$ : $\\P(X = 0 | Z = 0, Y = 1) = $" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "# 3. Medical Diagnosis\n", 68 | "\n", 69 | "2019-nCoV (武汉肺炎, pronounced Wǔhàn fèiyán) is a new coronavirus first found in the city of Wuhan in the Hubei province of China. A new protocol has been suggested for screening people arriving from the Hubei region. We want to use this test to quarantine probable cases to prevent the spread of nCoV and predict probability of death. People can either not have nCov or have nCov and our test can be positive or negative and the person can be dead or alive from the disease. Let's take the random variable $C$ to indicate if the patient has nCov, $T$ to indicate if the test is positive, and $S$ to be their state (alive = 1) after 7 days. On our first day of testing, 1200 people were tested and 200 had a positive test. Follow-up testing of those 200 showed that 11 had confirmed infections by nCov. We also, to ensure accuracy, did additional tests on the 1,000 who had a negative test result and found that one had nCov. Separately, we know that out of the 560 confirmed cases of nCov, 17 people died from the disease. Using this information, answer the following question:\n", 70 | "\n", 71 | "1. [1 point] Write out the sample space\n", 72 | "\n", 73 | "2. [3 points] Write out three probability statements given by the prompt.\n", 74 | "\n", 75 | "3. [8 points] Make a markdown table showing the probability of every element in the state space. State any assumptions you make.\n", 76 | "\n", 77 | "3. [3 points] What is the probability of dying and having a positive test?\n", 78 | "\n", 79 | "4. [3 points] What is the probability of dying if your test was positive? So should you be worried about a positive test?\n", 80 | "\n", 81 | "5. [3 points] What is the probability of dying if your test was negative?\n", 82 | "\n", 83 | "5. [5 points] If we decide to use this test and 2,400 people arrive per day from Wuhan, how many will get through with nCov? Use $2,400 \\times P(C = 1, T = 0)$ Is this a good test?" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "language": "python", 91 | "name": "python3" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.7.3" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 2 108 | } 109 | -------------------------------------------------------------------------------- /unit_2/lectures/lecture_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_2/lectures/lecture_1.pdf -------------------------------------------------------------------------------- /unit_2/lectures/lecture_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_2/lectures/lecture_2.pdf -------------------------------------------------------------------------------- /unit_2/lectures/lecture_2.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{teaching, array} 4 | 5 | \begin{document} 6 | 7 | \begin{tdoc}{CHEM 116}{Unit 2, Lecture 2}{Numerical Methods and Statistics} 8 | 9 | \section{Equations with Random Variables} 10 | 11 | \subsection*{Companion Reading} 12 | \textbf{Bulmer} Chapter 3 13 | 14 | \subsection{Joint Probability Distribution} 15 | We will indicate the probability that two rvs, $X$ and $Y$, adopt a 16 | particular value $x$ and $y$ \emph{simultaneously} as $\Pr(x,y)$. This 17 | is called a joint probability distribution. Joints indicate 18 | simultaneous occurance, unlike our {\bf AND} from last lecture. 19 | 20 | To treat successive observations, we simply rearrange our current 21 | definitions. Take flipping a coin. We redefine our sample space to be 22 | the product space of trials flip 1 and flip 2, so $(H,H)$, $(H,T)$, 23 | $(T,H)$ and $(T,T)$ where $H=$heads, $T=$tails. Next, we say $X$ is the 24 | observation of trial 1 and $Y$ is the observation of trial 2. 25 | 26 | The continuous analogue is $p(x,y)$, which is not meaningful unless 27 | integrated over an area. Example: observing particle in fixed area. 28 | 29 | \subsection{Marginal Probability Distribution} 30 | The marginal probability distribution function is defined as 31 | \begin{equation} 32 | \Pr(x) = \sum_y P(x,y) 33 | \end{equation} 34 | The marginal means the probability of $X=x, Y=y_0$ \textbf{OR} $X=x, Y=y_1$ \textbf{OR} 35 | $X=x, Y=y_2$, etc. For example, if $X$ is the weather and $Y$ is the 36 | day of the week, it is the probability of the weather being a particular value (e.g., nice) `averaged' over 37 | all possible weekdays. 38 | 39 | The marginal allows us to remove a rv or sample space dimension. That 40 | process is called {\bf marginalizing} and the resulting $\Pr(x)$ is 41 | called the marginal. Marginalization is especially important if the two pieces of 42 | the joint are not independent. 43 | 44 | \subsection{Revisiting Independence} 45 | 46 | Recall that we defined independence in terms of multiple samples in Unit 1. Now, we'll discuss independence of \textit{random variables}. Conceptually, independence of two random variables means that if I know the value of one variable, I have no additional evidence for what the value of another random variable is. For example, if I roll two dice I can have a random variable indicating the roll of die 1, $R_1$, and die 2, $R_2$. If I know that $R_1 = 4$, that doesn't help me determine the value of $R_2$ therefore these two random variables are independent. Now consider $R_1$ and the sum of the two dice $S$. If I know that $R_1 = 4$, I know that the sum of the two dice has to be greater than 4. That's because you cannot have a sum of two dice be less than 5 if one of the rolls is 4. Therefore, $R_1$ and $S$ are \textit{not independent}. One way to assess independence is the following theorem which hold for 2 indenpendent random variables: 47 | 48 | \begin{equation} 49 | P(X = x, Y = y) = P(X = x) P(Y = y),\, \textrm{If } X \textrm{ and } Y \textrm{ are independent.} 50 | \end{equation} 51 | 52 | We can prove independence if that expression holds for all values of $X$ and $Y$. We can disprove independence by showing it doesn't hold for a single value. 53 | 54 | \section{Concept Review} 55 | 56 | \begin{description} 57 | 58 | \item[Product Spaces] A product space is for joining two possibly 59 | dependent sample spaces. It can also be used to join sequential trials. 60 | 61 | \item[Event vs Sample on Product Spaces] Things which were samples on 62 | the components of a product space are now events due to permutations 63 | 64 | \item[Random Variables] They assign a numerical value at each sample 65 | in a sample space, but we typically care about the probability of 66 | those numerical values (PMF). So $X$ goes from sample to number and 67 | $\Pr(x)$ goes from number to probability. 68 | 69 | \item[Continuous PDF] A pdf is a tool for computing things, not 70 | something meaningful by itself. 71 | 72 | \item[Marginal Probability Distribution] A marginal `integrates/sums' 73 | out other samples/random variables/events we are not interested in. 74 | 75 | \item[Independence of Random Variables] Random variables can be independent and can 76 | be numerically evaluated by seeing if the produce of their marginals are equal to their 77 | joints. 78 | 79 | 80 | \end{description} 81 | 82 | 83 | \subsection{Table of Equations} 84 | 85 | \begin{tabular}{lr} 86 | $P(x) = \sum_y P(x,y)$ & Definition of Marginal\vspace{0.15cm}\\ 87 | $\sum_x P(x) = 1$ & Law of Total Probability/Normalization\vspace{0.15cm}\\ 88 | $P(x,y) = P(x)P(y)$ & Definition of Independence\vspace{0.15cm}\\ 89 | \end{tabular} 90 | 91 | \end{tdoc} 92 | 93 | \end{document} 94 | -------------------------------------------------------------------------------- /unit_2/lectures/lecture_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_2/lectures/lecture_3.pdf -------------------------------------------------------------------------------- /unit_2/lectures/probability_examples.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_2/lectures/probability_examples.pdf -------------------------------------------------------------------------------- /unit_2/lectures/probability_examples.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{teaching, array} 4 | 5 | \begin{document} 6 | 7 | \begin{tdoc}{CHEM 116}{Unit 2, Extra Notes}{Numerical Methods and Statistics} 8 | 9 | \emph{The purpose of this document is to show you how English 10 | sentences represent probability equations} 11 | 12 | Consider the probability distribution 13 | \begin{equation} 14 | \Pr(X=x, Y=y, Z=z) 15 | \end{equation} 16 | 17 | with no assumptions of independence, the following is true 18 | 19 | \vspace{0.5cm} 20 | 21 | \begin{tabular}{lr} 22 | Sentence & Equation\\ 23 | \hline\\ 24 | What is the probability of $X=2$, $Y=2$, and $Z=0$? & $\Pr(X=2, Y=2, Z=0)$\\ 25 | What is the probability of $X=1$, $Y=5$? & $\Pr(X=1, Y=2) = \sum_z\Pr(X=1, Y=2, Z=z)$\\ 26 | If $Z=4$, what is the probability of $X=2$, $Y=4$? & $\Pcond{X=2, Y=4}{Z=4}$\\ 27 | What is the probability of $X=2$, $Y=4$, given $Z$ is 4? & $\Pcond{X=2, Y=4}{Z=4}$\\ 28 | If $Y=2$ and $Z = 0$, what is the probability of $X$? & $\Pcond{X=x}{Y=2, Z=0}$\\ 29 | \end{tabular} 30 | 31 | 32 | \end{tdoc} 33 | \end{document} 34 | -------------------------------------------------------------------------------- /unit_3/hw_2015/Homework_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 3\n", 8 | "====\n", 9 | "####CHE 116: Numerical Methods and Statistics\n", 10 | "Prof. Andrew White\n", 11 | "\n", 12 | "Version 1.6 (2/3/2015)\n", 13 | "\n", 14 | "----" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "1. Identifying Distributions (5 Points)\n", 22 | "====\n", 23 | "\n", 24 | "List if a distribution is continuous or discrete, its support, and an example of a random variable which follows the distribution. 1 Bonus point per problem for identifying a rv related to chemical engineering.\n", 25 | "\n", 26 | "1. Geometric distribution\n", 27 | "2. Poisson Distribution\n", 28 | "3. Binomial Distribution\n", 29 | "4. Exponential Distribution\n", 30 | "5. Bernoulli Distribution" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "####Answers\n", 38 | "1.1 Discrete, $[1,\\infty)$, the number of collisions until two molecules react" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "2. Slicing Lists (6 Points)\n", 46 | "====\n", 47 | "Using this sentence: \"The quick brown fox jumps over the lazy dog\", Create slices of the string to answer the following questions. Note that character/element mean the same thing, so that every element in the sentence is a character. **Answer in Python**\n", 48 | "\n", 49 | "1. What is the first characeter?\n", 50 | "2. What is the sentence without the last characeter?\n", 51 | "5. What are the first 5 characeters?\n", 52 | "3. What is the first half of the sentence?\n", 53 | "4. What is the second half?\n", 54 | "6. What is every 3rd character, starting from the 4th?" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "####Answers" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 2, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "T\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "#2.1\n", 79 | "string = 'The quick brown fox jumps over the lazy dog'\n", 80 | "print string[0]" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "3. Numpy Arrays and Arithmetic (12 Points)\n", 88 | "====\n", 89 | "\n", 90 | "1. Create a numpy array containing a set of points between 0 and 30 spaced apart by 0.02. This should be done with a numpy function.\n", 91 | "2. Using a `for` loop, sum all the elements in the array and print the sum. Check your answer using the numpy `sum` function.\n", 92 | "3. Using the array from question 3.1, create an array representing a $\\lambda = 3$ exponential distribution on the interval $[0,30)$. *Note: the word `lambda` is a reserved word in python, meaning you cannot use it for a variable name. You can tell if a variable is reserved because it is a different color/font than other variables in ipython. Also, when applying mathematical functions to numpy arrays, you must use the numpy versions, for example `numpy.cos` instead of `math.cos`*\n", 93 | "4. Using a `for` loop and the array from Question 3.1, compute the expected value of the exponential distribution. To evaluate the integral, use $\\int f(x)dx = \\sum_i f(x_i) \\Delta x$, where $\\Delta x$ is the spacing between your points and $f(x_i)$ is the function evaluated at point $x_i$. As you know, it should be $1/3$.\n", 94 | "5. Using both the arrays from Question 3.1 and 3.3 and the `sum` function from numpy, compute the expected value without a `for` loop. \n", 95 | "6. Using your equation from HW 2, problem 5 (see key), compute the expected value and variance of the sum of two dice" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "4. Plotting (4 Points)\n", 103 | "====\n", 104 | "\n", 105 | "1. Create a numpy array of points and evaluate the exponential distribution on it. Plot it from $0$ to $2\\lambda$.\n", 106 | "2. Do the same for the geometric distribution. Think carefully about whether it should be a line or a point plot and what the sample space of the distribution is.\n", 107 | "3. Plot the binomial distribution with $N=10$, $p=0.25$. To get a binomial coefficient for arrays, call `from scipy.special import comb` and use the `comb(N, n)` function, where `n` is your array. \n", 108 | "4. Plot the binomial distribution with $N=150$, $p=0.5$. " 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [] 117 | } 118 | ], 119 | "metadata": { 120 | "kernelspec": { 121 | "display_name": "Python 3", 122 | "language": "python", 123 | "name": "python3" 124 | }, 125 | "language_info": { 126 | "codemirror_mode": { 127 | "name": "ipython", 128 | "version": 3 129 | }, 130 | "file_extension": ".py", 131 | "mimetype": "text/x-python", 132 | "name": "python", 133 | "nbconvert_exporter": "python", 134 | "pygments_lexer": "ipython3", 135 | "version": "3.6.3" 136 | } 137 | }, 138 | "nbformat": 4, 139 | "nbformat_minor": 1 140 | } 141 | -------------------------------------------------------------------------------- /unit_3/hw_2016/homework_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 3\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "Prof. Andrew White\n", 11 | "\n", 12 | "Version 1.1 (1/26/2015)\n", 13 | "\n", 14 | "----" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "$\\DeclareMathOperator{\\P}{P}$\n", 22 | "$\\DeclareMathOperator{\\E}{E}$\n", 23 | "\n", 24 | "1. Python Math and Boolean (6 Points)\n", 25 | "====\n", 26 | "**Answer the following problems in Python**\n", 27 | "\n", 28 | "1. Is $3^{14}$ greater than $10^6$?\n", 29 | "\n", 30 | "2. Using the `frexp` function, show how the floating point number $0.4$ is represented and rebuild the number from its pieces. Use base 10\n", 31 | "\n", 32 | "2. Is $0.4 + 0.2$ exactly equal to $(4.0 + 2.0) / 10.0$ with floats? Why or why not? \n", 33 | "\n", 34 | "3. The next cell contains a joint probability mass function for $x$ and $y$. $x$ is the first number and $y$ is the second. You may access elements like this: `P[0,2]`. `P[0,2]` is the probability that $x=0$ and $y=2$. Demonstrate that the two random variables are not independent.\n", 35 | "\n", 36 | "4. Calculate the marginal $\\P(x=2)$, where $x$ is the first index using the next cell's joint probability mass function.\n", 37 | "\n", 38 | "5. Calculate the conditional $\\P(x=2 | y = 1)$, where $x$ is the first index using the next cell's joint probability mass function.\n" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 3, 44 | "metadata": { 45 | "collapsed": false 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "#This is loading the data for question 1.4 through 1.6\n", 50 | "#Execute this cell and use new cells below. Do not answer in this cell!\n", 51 | "\n", 52 | "import numpy as np\n", 53 | "P = np.zeros( (3,3) )\n", 54 | "P[0,0] = 0.\n", 55 | "P[0,1] = 1. / 9\n", 56 | "P[0,2] = 1. / 9.\n", 57 | "P[1,0] = 1. / 3\n", 58 | "P[1,1] = 0.\n", 59 | "P[1,2] = 1. / 9\n", 60 | "P[2,0] = 1. / 18\n", 61 | "P[2,1] = 1. / 9\n", 62 | "P[2,2] = 1. / 6" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "2. Slicing Lists (6 Points)\n", 70 | "====\n", 71 | "Using this sentence: \"This pangram contains four As, one B, two Cs, one D, thirty Es, six Fs, five Gs, seven Hs, eleven Is, one J, one K, two Ls, two Ms, eighteen Ns, fifteen Os, two Ps, one Q, five Rs, twenty-seven Ss, eighteen Ts, two Us, seven Vs, eight Ws, two Xs, three Ys, & one Z\", Create slices of the string to answer the following questions. Note that character/element mean the same thing, so that every element in the sentence is a character. **Answer in Python**\n", 72 | "\n", 73 | "1. What is the first characeter?\n", 74 | "2. What is the sentence without the last 10 characeter?\n", 75 | "5. What are the first 5 characeters?\n", 76 | "3. What is the first half of the sentence?\n", 77 | "4. What is the second half?\n", 78 | "6. What is every 8th character, starting from the 16th?" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "3. Loops (20 Points)\n", 86 | "====\n", 87 | "\n", 88 | "3. [4 points] Using a `for` loop, compute $10!$. \n", 89 | "4. [4 points] Using a `for` loop compute $$\\sum_{n=0}^{25}\\frac{1}{n!}$$ What famous number is that?\n", 90 | "6. [8 points] Now that you know what famous number that is, how many terms are required in the sum before it is accurate to 5 decimal places? Your code should print out the number of terms. Think carefully about how to turn \"accurate to 5 decimal places\" into a python expression." 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "Numpy (6 Points)\n", 98 | "====\n", 99 | "\n", 100 | "1. Create a numpy array containing a set of points between 5 and 10 spaced apart by 0.025. This should be done with a numpy function.\n", 101 | "2. Using a `numpy` array, compute: $$\\sum_{i=1}^{100} \\cos{i}$$ you should *not* use a `for` loop.\n", 102 | "3. Demonstrate 3 methods for creating a numpy array" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": { 109 | "collapsed": true 110 | }, 111 | "outputs": [], 112 | "source": [] 113 | } 114 | ], 115 | "metadata": { 116 | "kernelspec": { 117 | "display_name": "Python 2", 118 | "language": "python", 119 | "name": "python2" 120 | }, 121 | "language_info": { 122 | "codemirror_mode": { 123 | "name": "ipython", 124 | "version": 2 125 | }, 126 | "file_extension": ".py", 127 | "mimetype": "text/x-python", 128 | "name": "python", 129 | "nbconvert_exporter": "python", 130 | "pygments_lexer": "ipython2", 131 | "version": "2.7.11" 132 | } 133 | }, 134 | "nbformat": 4, 135 | "nbformat_minor": 0 136 | } 137 | -------------------------------------------------------------------------------- /unit_3/hw_2017/problem_set_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "nbgrader": { 8 | "grade": false, 9 | "grade_id": "0", 10 | "locked": true, 11 | "schema_version": 1, 12 | "solution": false 13 | } 14 | }, 15 | "source": [ 16 | "### Manipulating Probability Expressions\n", 17 | "\n", 18 | "Simplify the following expressions or say if they cannot be simplified. State which equation you used. See list of equations at bottom of unit 2, lecture 2 for names. " 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "nbgrader": { 25 | "grade": false, 26 | "grade_id": "1", 27 | "locked": true, 28 | "schema_version": 1, 29 | "solution": false 30 | } 31 | }, 32 | "source": [ 33 | "$$\n", 34 | "\\sum_X P(x)\n", 35 | "$$" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": { 41 | "nbgrader": { 42 | "grade": false, 43 | "grade_id": "2", 44 | "locked": true, 45 | "schema_version": 1, 46 | "solution": false 47 | } 48 | }, 49 | "source": [ 50 | "$$\n", 51 | "\\sum_X P(x) = 1\n", 52 | "$$\n", 53 | "due to law of total probability" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": { 59 | "nbgrader": { 60 | "grade": false, 61 | "grade_id": "3", 62 | "locked": true, 63 | "schema_version": 1, 64 | "solution": false 65 | } 66 | }, 67 | "source": [ 68 | "$$\n", 69 | "\\sum_X P(x \\,|\\, y)\n", 70 | "$$" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": { 76 | "nbgrader": { 77 | "grade": true, 78 | "grade_id": "4", 79 | "locked": false, 80 | "points": 4, 81 | "schema_version": 1, 82 | "solution": true 83 | } 84 | }, 85 | "source": [ 86 | "$$\n", 87 | "\\sum_X P(x \\,|\\, y) = 1\n", 88 | "$$\n", 89 | "\n", 90 | "due to law of total probability" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": { 96 | "nbgrader": { 97 | "grade": false, 98 | "grade_id": "5", 99 | "locked": true, 100 | "schema_version": 1, 101 | "solution": false 102 | } 103 | }, 104 | "source": [ 105 | "$$\n", 106 | "\\sum_Y P(x \\,|\\, y)\n", 107 | "$$" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": { 113 | "nbgrader": { 114 | "grade": true, 115 | "grade_id": "6", 116 | "locked": false, 117 | "points": 4, 118 | "schema_version": 1, 119 | "solution": true 120 | } 121 | }, 122 | "source": [ 123 | "cannot be simplified" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "metadata": { 129 | "nbgrader": { 130 | "grade": false, 131 | "grade_id": "7", 132 | "locked": true, 133 | "schema_version": 1, 134 | "solution": false 135 | } 136 | }, 137 | "source": [ 138 | "$$\n", 139 | "\\sum_Y P(x, y)\n", 140 | "$$" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": { 146 | "nbgrader": { 147 | "grade": true, 148 | "grade_id": "8", 149 | "locked": false, 150 | "points": 4, 151 | "schema_version": 1, 152 | "solution": true 153 | } 154 | }, 155 | "source": [ 156 | "$$\n", 157 | "\\sum_Y P(x,y) = P(x)\n", 158 | "$$\n", 159 | "due to definition of marginal" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": { 165 | "nbgrader": { 166 | "grade": false, 167 | "grade_id": "9", 168 | "locked": true, 169 | "schema_version": 1, 170 | "solution": false 171 | } 172 | }, 173 | "source": [ 174 | "$$\n", 175 | "\\sum_Y P(x\\, |\\, y) P(y)\n", 176 | "$$" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "metadata": { 182 | "nbgrader": { 183 | "grade": true, 184 | "grade_id": "10", 185 | "locked": false, 186 | "points": 4, 187 | "schema_version": 1, 188 | "solution": true 189 | } 190 | }, 191 | "source": [ 192 | "$$\n", 193 | "\\sum_Y P(x\\, |\\, y) P(y) = P(x)\n", 194 | "$$\n", 195 | "\n", 196 | "due to marginalization of the conditional" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": { 202 | "nbgrader": { 203 | "grade": false, 204 | "grade_id": "11", 205 | "locked": true, 206 | "schema_version": 1, 207 | "solution": false 208 | } 209 | }, 210 | "source": [ 211 | "$$\n", 212 | "\\frac{P(x, y)}{P(x)}\n", 213 | "$$" 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": { 219 | "nbgrader": { 220 | "grade": true, 221 | "grade_id": "12", 222 | "locked": false, 223 | "points": 4, 224 | "schema_version": 1, 225 | "solution": true 226 | } 227 | }, 228 | "source": [ 229 | "$$\n", 230 | "\\frac{P(x, y)}{P(x)} = P(y \\,|\\, x)\n", 231 | "$$\n", 232 | "\n", 233 | "due to definition of conditional" 234 | ] 235 | } 236 | ], 237 | "metadata": { 238 | "celltoolbar": "Create Assignment", 239 | "kernelspec": { 240 | "display_name": "Python 3", 241 | "language": "python", 242 | "name": "python3" 243 | }, 244 | "language_info": { 245 | "codemirror_mode": { 246 | "name": "ipython", 247 | "version": 3 248 | }, 249 | "file_extension": ".py", 250 | "mimetype": "text/x-python", 251 | "name": "python", 252 | "nbconvert_exporter": "python", 253 | "pygments_lexer": "ipython3", 254 | "version": "3.5.2" 255 | } 256 | }, 257 | "nbformat": 4, 258 | "nbformat_minor": 2 259 | } 260 | -------------------------------------------------------------------------------- /unit_3/hw_2018/homework_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 3\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "2/1/2018\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "1. Manipulating Probability Expression (12 Points)\n", 21 | "-----\n", 22 | "\n", 23 | "Simplify the following probability expressions if possible. Some may be as simple as possible. Recall that $P(x)$ is shorthand for $P(X = x)$.\n", 24 | "\n", 25 | "\n", 26 | "1. $$\\sum_y P(y)$$\n", 27 | "1. $$\\sum_x P(x\\,|\\,y)$$\n", 28 | "2. $$\\sum_y P(x\\,|\\,y)$$\n", 29 | "3. $$\\sum_x P(x,y)$$\n", 30 | "4. $$P(x | y)P(y)$$\n", 31 | "5. $$\\frac{P(x\\,|\\, y) P(y)}{P(x)}$$\n", 32 | "6. $$\\sum_x P(y \\, |\\, x)P(x)$$" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "2. Combinatorial Questions (16 Points)\n", 40 | "====\n", 41 | "\n", 42 | "*Answer these symbolically*\n", 43 | "\n", 44 | "1. [2 points] There are three people assigning five rooms in a house. How many room assignments are possible?\n", 45 | "2. [2 points] Students are handing in their homework in a pile. If there are 8 students, how many possible configurations of the pile are there?\n", 46 | "3. [2 points] You arrange 5 US currency notes in a row. US currency can be \\$1, \\$5, \\$10, \\$20, and \\$100. How many possible arrangements are possible?\n", 47 | "4. [2 points] You have a pendant molecule which has three *distinguishable* sites which can be decorated with a functional group. Assume that all sites are decorated. If you have 8 possible functional groups, how many unique molecules can you synthesize? You can use as many functional groups simultaneously as you want. \n", 48 | "5. [8 points] If you allow sites to be unreacted, so that you can have the pendant molecule with only 1 or 2 or 0 functional groups in addition to 3, how many unique molecules can you synthesize?\n" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "3. Loaded Die Problem (24 Points)\n", 56 | "====\n", 57 | "\n", 58 | "*Answer these symbolically*\n", 59 | "\n", 60 | "Let us continue our loaded die problem from unit 2, lecture 2. There are two possible dice being used. One is fair and one is unfair. Take $D = 0$ to indicate the fair die and $D = 1$ to indicate the unfair die. The unfair die has a probability of 90\\% of being chosen. The probability of a roll with the unfair die is $x / 21$, where $x$ is the value of the role. Answer the following questions symbolically. $X_i$ indicates the value of the roll on attempt $i$. The rolls are conditionally independent on the identity of the die. \n", 61 | "\n", 62 | "1. [4 points] Compute $P(X_0 = 3)$?\n", 63 | "\n", 64 | "2. [4 points] Compute $P(X_0, X_1 \\, | \\, D = 0)$?\n", 65 | "\n", 66 | "3. [2 points] Compute $P(D = 0, D = 1)$?\n", 67 | "\n", 68 | "4. [4 points] Compute $P(X_1 = 2,\\, X_0 = 4)$?\n", 69 | "\n", 70 | "4. [2 points] Describe in words what the following expression means:\n", 71 | "$$\n", 72 | "\\frac{P(X_1 = 6 \\,|\\, X_0 = 6)}{P(X_0 = 6)}\n", 73 | "$$\n", 74 | "\n", 75 | "5. [8 points] Calculate the above quantity and summarize in words what it means.\n" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "4. False Positives (28 Points)\n", 83 | "===\n", 84 | "\n", 85 | "*Answer Symbolically*\n", 86 | "\n", 87 | "One of the most famous applications of conditional probabilities is in medical tests. Consider a medical test for HIV. The test as a false positive rate of 2%. That means it indicates that someone has HIV when they *do not*. HIV has a false negative rate of 1%. That means the test indicates someone *does not* have HIV when in fact they do. The incidence rate of HIV is 0.3% in the US. Using this information, answer the following questions:\n", 88 | "\n", 89 | "1. [2 points] Write out the definition of a false negative and false positive using probability expressions.\n", 90 | "\n", 91 | "2. [2 points] Ignoring ethical concerns, if we randomly select someone, what is the probability that they have HIV?\n", 92 | "\n", 93 | "3. [6 points] If we randomly test someone for HIV, what is the probability that our test will show that they have HIV?\n", 94 | "\n", 95 | "4. [8 points] If a positive test indicates the presence of HIV, what is the probability that person has HIV? Is this surprising?\n", 96 | "\n", 97 | "5. [10 points] Assume each test is conditionally independent on whether or not the person has HIV. What is the probability that someone has HIV after two positive tests? The probabilities for false negative and positive are the same for the two tests." 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": { 104 | "collapsed": true 105 | }, 106 | "outputs": [], 107 | "source": [] 108 | } 109 | ], 110 | "metadata": { 111 | "kernelspec": { 112 | "display_name": "Python 3", 113 | "language": "python", 114 | "name": "python3" 115 | }, 116 | "language_info": { 117 | "codemirror_mode": { 118 | "name": "ipython", 119 | "version": 3 120 | }, 121 | "file_extension": ".py", 122 | "mimetype": "text/x-python", 123 | "name": "python", 124 | "nbconvert_exporter": "python", 125 | "pygments_lexer": "ipython3", 126 | "version": "3.6.2" 127 | } 128 | }, 129 | "nbformat": 4, 130 | "nbformat_minor": 2 131 | } 132 | -------------------------------------------------------------------------------- /unit_3/hw_2019/homework_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 3\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "*2/2/2019*\n", 11 | "\n", 12 | "----" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# 1. String Formatting\n", 20 | "\n", 21 | "1. [1 point] Using the `math` module, print euler's number to 5 digits precision in scientific notation format\n", 22 | "2. [1 point] Print the first 5 powers of 7 with exactly 5 spaces starting from $7^1$\n", 23 | "3. [1 point] Create a variable `v` whose value is None and print it out\n", 24 | "4. [4 points] Use the same variable, `v`, and print it with 3 digits of precision in scientific notation. You should receive an error. Using the definition of a sentinel value, why would we want to not have an error if printed without formatting (problem 1.3) but receieve an error when we format it?" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "# 2. Representing Numbers \n", 32 | "\n", 33 | "1. [1 point] What is the Manitissa for the number $0.4335 \\times 10^{-3}$?\n", 34 | "2. [1 point] How many numbers can be represented with 4 bytes?\n", 35 | "3. [1 point] Youtube previously represented view counts on videos with 4 bytes. What is the largest number of views that could be represented? \n", 36 | "4. [2 points] One more person viewed the video from 2.3? What would the view count be? What is this called?\n", 37 | "5. [3 points] We learned that we shouldn't compare floating point numbers with `==`. Compare `0.75` and `3 / 4` in Python using `==` (even though we said we should not). Explain why it worked. " 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "# 3. Booleans" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "1. [4 points] Write an `if` statement that prints a variable if it has a magnitude less than 40, otherwise it prints 'Error, number is too large'. Demonstrate with your variable being `-12`.\n", 52 | "2. [2 points] Write an `if` statement that compares two variables to see if they're equal. Demonstrate this with two strings.\n" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "# 4. Lists\n", 60 | "\n", 61 | "Use this list for the examples `[3, 6, 1, 12, 43, 3, 100]` and use *only* slicing to answer the questions.\n", 62 | "\n", 63 | "1. [2 points] Reverse the list \n", 64 | "2. [2 points] Print out every 3rd element starting from `6`\n", 65 | "3. [2 points] Print out the first 4 elements. \n", 66 | "5. [2 points] Print out the last element using negative indexing\n", 67 | "6. [2 points] Print out all elements except the last one" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "# 5. List Functinos \n", 75 | "\n", 76 | "[4 points] Using the `len` function, write a python expression that can print the second half of a list variable `a`. Your answer should be *exactly* 13 characters." 77 | ] 78 | } 79 | ], 80 | "metadata": { 81 | "kernelspec": { 82 | "display_name": "Python 3", 83 | "language": "python", 84 | "name": "python3" 85 | }, 86 | "language_info": { 87 | "codemirror_mode": { 88 | "name": "ipython", 89 | "version": 3 90 | }, 91 | "file_extension": ".py", 92 | "mimetype": "text/x-python", 93 | "name": "python", 94 | "nbconvert_exporter": "python", 95 | "pygments_lexer": "ipython3", 96 | "version": "3.6.4" 97 | } 98 | }, 99 | "nbformat": 4, 100 | "nbformat_minor": 2 101 | } 102 | -------------------------------------------------------------------------------- /unit_3/hw_2020/homework_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 3\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "1/31/2020\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. String Formatting\n", 21 | "\n", 22 | "Answer in Python\n", 23 | "\n", 24 | "1. [2 points] Print $\\sin 0.5$ to 5 digits of precision\n", 25 | "2. [2 points] Print 1.30, 21.83, and 0.21 on separate lines and aligned on the decimal place using only one print statement like this:\n", 26 | "\n", 27 | "```\n", 28 | " 1.30\n", 29 | " 21.83\n", 30 | " 0.21\n", 31 | "```\n", 32 | "\n", 33 | "3. [2 points] Create a variable with a value of pi using the `math` module. Print it with 3 digits of precision\n", 34 | "4. [2 points] Print out the number 65,535 as binary using string formatting." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# 2. Representing Numbers\n", 42 | "Answer in Markdown. You can use Python for supporting your answer.\n", 43 | "\n", 44 | "\n", 45 | "1. [2 points] The total number of people in a group chat is limited 256. What could be the reason for this very specific number?\n", 46 | "2. [3 points] What is the minimum number of bytes it will it take to encode a phone number with an area code?\n", 47 | "3. [4 points] In a certain video game, a very powerful boss has 32,000 health points represented as a signed integer. You dicover that if instead of fighting the boss, you cast a spell that heals it for 800 points you immediately kill it. Why might this be?\n", 48 | "4. [1 point] What is the mantissa for 1.0 in decimal? \n", 49 | "5. [4 points] We want to write a computer program to detect if a student is at the boarder between an A- and B+ (90% score) so that we can decide which grade better represents their performance. Essentially the program should check if the grade is right at the 90% cutoff. Why is it impossible for a computer program to accomplish this seemingly simple task? Prove your hypothesis with python code.\n", 50 | "6. [1 point] We want to write a computer program to detect if a student is at the boarder between B and B+ (87.5%) score. Why is this a trivial task for a computer program?" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "# 3. Booleans\n", 58 | "\n", 59 | "Answer in Python\n", 60 | "\n", 61 | "1. [2 points] Write an `if` statement that prints if a variable `v` is positive or negative. Demonstrate it by setting `v` to -1 and then 1.\n", 62 | "\n", 63 | "2. [2 points] Write an `if` statement that will print `foo` if a string has more than 5 characters and `bar` otherwise. Demonstrate with a variable whose value is `foobar`. \n", 64 | "\n", 65 | "3. [2 points] Write an `if` statement to check if the character `*` is in a string and prints `hello` if it is. Demonstrate with a varaible whose value is `fizz*buzz`. " 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "# 4. Lists\n", 73 | "\n", 74 | "Answer in Python\n", 75 | "\n", 76 | "Use this list to answer the questions: `['A', 'B', 'C', 'D', 'E', 'F', 'G']`\n", 77 | "\n", 78 | "1. [2 points] Print out the second to last element of the list using a negative index.\n", 79 | "2. [2 points] Print out the last three elements of the list using negative indices.\n", 80 | "3. [2 points] Print out the middle element of the list using the `len` function\n", 81 | "4. [2 points] Print every other element of the list.\n", 82 | "5. [2 points] Print every other element of the list starting from the second element." 83 | ] 84 | } 85 | ], 86 | "metadata": { 87 | "kernelspec": { 88 | "display_name": "Python 3", 89 | "language": "python", 90 | "name": "python3" 91 | }, 92 | "language_info": { 93 | "codemirror_mode": { 94 | "name": "ipython", 95 | "version": 3 96 | }, 97 | "file_extension": ".py", 98 | "mimetype": "text/x-python", 99 | "name": "python", 100 | "nbconvert_exporter": "python", 101 | "pygments_lexer": "ipython3", 102 | "version": "3.7.3" 103 | } 104 | }, 105 | "nbformat": 4, 106 | "nbformat_minor": 2 107 | } 108 | -------------------------------------------------------------------------------- /unit_4/hw_2017/problem_set_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true, 8 | "nbgrader": { 9 | "grade": false, 10 | "grade_id": "prompt", 11 | "locked": true, 12 | "schema_version": 1, 13 | "solution": false 14 | } 15 | }, 16 | "source": [ 17 | "Answer the following questions in Python. Do all calculations in Python" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "deletable": true, 24 | "editable": true, 25 | "nbgrader": { 26 | "grade": false, 27 | "grade_id": "1", 28 | "locked": true, 29 | "schema_version": 1, 30 | "solution": false 31 | } 32 | }, 33 | "source": [ 34 | "Print $\\pi/2$ with three digits of precision. Use the `pi` constant from the math module" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 3, 40 | "metadata": { 41 | "collapsed": false, 42 | "deletable": true, 43 | "editable": true, 44 | "nbgrader": { 45 | "grade": true, 46 | "grade_id": "1-a", 47 | "locked": false, 48 | "points": 1, 49 | "schema_version": 1, 50 | "solution": true 51 | } 52 | }, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "1.57\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "from math import pi\n", 64 | "print('{:.3}'.format(pi / 2))" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "deletable": true, 71 | "editable": true, 72 | "nbgrader": { 73 | "grade": false, 74 | "grade_id": "2", 75 | "locked": true, 76 | "schema_version": 1, 77 | "solution": false 78 | } 79 | }, 80 | "source": [ 81 | "Given a variable called `angle`, print out the sine of it like so:\n", 82 | "\n", 83 | "```text\n", 84 | "The sine of 1.2 radians is 0.932\n", 85 | "```\n", 86 | "\n", 87 | "Make sure that your code uses a variable, not literally 1.2 radians. Make your precision match what is shown above.\n" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 15, 93 | "metadata": { 94 | "collapsed": false, 95 | "deletable": true, 96 | "editable": true, 97 | "nbgrader": { 98 | "grade": true, 99 | "grade_id": "2-a", 100 | "locked": false, 101 | "points": 2, 102 | "schema_version": 1, 103 | "solution": true 104 | } 105 | }, 106 | "outputs": [ 107 | { 108 | "name": "stdout", 109 | "output_type": "stream", 110 | "text": [ 111 | "The sine of 1.2 radians is 0.93\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "from math import *\n", 117 | "\n", 118 | "x = 1.2\n", 119 | "print('The sine of {:.2} radians is {:.2}'.format(x, sin(x)))" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": { 125 | "deletable": true, 126 | "editable": true, 127 | "nbgrader": { 128 | "grade": false, 129 | "grade_id": "3", 130 | "locked": true, 131 | "schema_version": 1, 132 | "solution": false 133 | } 134 | }, 135 | "source": [ 136 | "Using string formatting show the decimal and binary representation of the number 34. Your format function should only take one argument, the number 34. " 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 16, 142 | "metadata": { 143 | "collapsed": false, 144 | "deletable": true, 145 | "editable": true, 146 | "nbgrader": { 147 | "grade": true, 148 | "grade_id": "3-a", 149 | "locked": false, 150 | "points": 2, 151 | "schema_version": 1, 152 | "solution": true 153 | } 154 | }, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "binary: 100010, decimal: 34\n" 161 | ] 162 | } 163 | ], 164 | "source": [ 165 | "print('binary: {0:b}, decimal: {0:}'.format(34))" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": { 171 | "deletable": true, 172 | "editable": true, 173 | "nbgrader": { 174 | "grade": false, 175 | "grade_id": "4", 176 | "locked": true, 177 | "schema_version": 1, 178 | "solution": false 179 | } 180 | }, 181 | "source": [ 182 | "Using a `for` loop, print the integers from 0 to 8 in binary such that each line is right-aligned. " 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 17, 188 | "metadata": { 189 | "collapsed": false, 190 | "deletable": true, 191 | "editable": true, 192 | "nbgrader": { 193 | "grade": true, 194 | "grade_id": "4-a", 195 | "locked": false, 196 | "points": 6, 197 | "schema_version": 1, 198 | "solution": true 199 | } 200 | }, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | " 0\n", 207 | " 1\n", 208 | " 10\n", 209 | " 11\n", 210 | " 100\n", 211 | " 101\n", 212 | " 110\n", 213 | " 111\n", 214 | " 1000\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "for i in range(9):\n", 220 | " print('{:5b}'.format(i))" 221 | ] 222 | } 223 | ], 224 | "metadata": { 225 | "celltoolbar": "Create Assignment", 226 | "kernelspec": { 227 | "display_name": "Python 3", 228 | "language": "python", 229 | "name": "python3" 230 | }, 231 | "language_info": { 232 | "codemirror_mode": { 233 | "name": "ipython", 234 | "version": 3 235 | }, 236 | "file_extension": ".py", 237 | "mimetype": "text/x-python", 238 | "name": "python", 239 | "nbconvert_exporter": "python", 240 | "pygments_lexer": "ipython3", 241 | "version": "3.5.3" 242 | } 243 | }, 244 | "nbformat": 4, 245 | "nbformat_minor": 2 246 | } 247 | -------------------------------------------------------------------------------- /unit_4/hw_2018/Homework_4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 4\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "2/8/2018\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "source": [ 22 | "1. String Formatting (4 Points)\n", 23 | "===\n", 24 | "\n", 25 | "*Answer these in Python*\n", 26 | "\n", 27 | "1. [1 point] Print $\\pi$ to 4 digits of precision. Use `pi` from the `math` module.\n", 28 | "2. [2 points] Print the square root of the first 5 integers starting from 1 with 4 digits of precision. Print the terms with one per line and have them all take up exactly 5 spaces. 2 Bonus points if you use a `for` loop\n", 29 | "3. [1 point] Show how to print the same variable twice using the variable index part of the `:` operator in a string.}" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "2. Representing Numbers (5 Points)\n", 37 | "====\n", 38 | "\n", 39 | "*Answers these symbolically*\n", 40 | "\n", 41 | "1. [1 point] What is the mantissa and what is the exponent of $0.3422 \\times 10^{-4}$. \n", 42 | "2. [1 point] What is the largest representable number with 10 bits?\n", 43 | "3. [1 point] In a number system of base 8, how many numbers can be represented with 4 digits places?\n", 44 | "4. [2 points] How do we do boolean expressions with floating numbers? Is it valid to compare floating numbers at all?" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "3. Booleans (20 Points)\n", 52 | "====\n", 53 | "\n", 54 | "1. [4 points] Write python code that will print 'greater than 10' when the variable `z` is greater than 10.\n", 55 | "2. [4 points] Write python code that will print 'special' if the variable `z` less than -25 but greater than -35.\n", 56 | "3. [2 points] Use the `%` operator in python, which computes the remainder of the left number after being divided by the right number, to compute the remainder of 12 divided by 5.\n", 57 | "4. [4 points] Use the `%` operator in a boolean expression to print 'even' if the variable `z` is even.\n", 58 | "5. [6 points] Write code that prints out if the variable `z` is positive or negative, even or odd, and greater in magnitude than 10." 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "4. Lists and Slicing (11 Points)\n", 66 | "===\n", 67 | "\n", 68 | "*Answers these questions in Python. Print your result*\n", 69 | "\n", 70 | "1. [2 points] Create a list of all positive even integers less than 20 using the `range` function.\n", 71 | "2. [1 point] Using the list created above and a slice, print out the third-largest even integer less than 20.\n", 72 | "3. [2 points] Print out the first 3 integers from your list in question 4.1\n", 73 | "4. [2 points] Create a list of the integers 1 to 10 and then using the assignment operator (`=`), override the last element to be 100. \n", 74 | "4. [4 points] Create a list of the integers 1 to 4 and then use a `for` loop print out $2^i$, where $i$ is the elements in your list." 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "5. Numpy (12 Points)\n", 82 | "====\n", 83 | "*Answers these questions in Python*\n", 84 | "\n", 85 | "When specifying an interval, parenthesis indicate an exclusive end-point and brackets indicate an inclusive end-point. So $\\left(0,1\\right)$ means from 0 to 1, not including 0 or 1. $\\left[0, 1\\right)$ means from 0 to 1 including 0 but not including 1. \n", 86 | "\n", 87 | "1. [2 points] Create an array of numbers that goes from $\\left[1, 10\\right)$ in increments of 0.25 using the `arange` function.\n", 88 | "2. [2 points] Create an array of numbers that goes from $\\left[1, 10\\right)$ in increments of 0.25 using the `linspace` function.\n", 89 | "3. [2 points] Create an array of 21 numbers that go from $\\left[0,1\\right]$ using the `arange` function.\n", 90 | "4. [2 points] Create an array of 21 numbers that go from $\\left[0,1\\right]$ using the `linspace` function.\n", 91 | "5. [4 points] Using an array, print out the first 8 powers of 3 (e.g., $3^0$, $3^1$, $3^2$, etc)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "6. Plotting (16 Points)\n", 99 | "===\n", 100 | "\n", 101 | "*Answer these in questions in Python. Label your axes as `x-axis` and `y-axis`. *\n", 102 | "\n", 103 | "1. [4 points] Make a plot of the cosine from $-pi$ to $0$.\n", 104 | "\n", 105 | "2. [4 points] We will see that the equation $e^{-x^2}$ is important in a few weeks. Make a plot of it from -2, to 2. \n", 106 | "\n", 107 | "3. [8 pints] Plot $x$, $x^2$, and $x^3$ from -1 to 1. Label your lines with a legend, add a title, use the `seaborn-darkgrid` style, and set the figure size as $4\\times3$." 108 | ] 109 | } 110 | ], 111 | "metadata": { 112 | "kernelspec": { 113 | "display_name": "Python 3", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.6.2" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 2 132 | } 133 | -------------------------------------------------------------------------------- /unit_4/hw_2019/Homework_4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 4\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "*(2/7/2019)*\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Lists and Arrays (20 Points)\n", 21 | "\n", 22 | "1. [2 points] Make a list of integers ranging from 0 to 100 in reverse order in increments of 2.\n", 23 | "\n", 24 | "2. [2 points] Modify the above list to have \"Happy\" as the 45th element and the word \"Friday\" as the last element. \n", 25 | "\n", 26 | "3. [2 points] Append 20 more integers ranging from 6 to 26, in increments of one, to the previous list.\n", 27 | "\n", 28 | "4. [3 points] What is the mean of the first quarter of the resulting list. Use `sum` and the `len` of the list to compute which index corresponds to the quarter. \n", 29 | "\n", 30 | "5. [5 points] Repeat problem 4 using a `for` loop.\n", 31 | "\n", 32 | "6. [3 points] Create 100 by 3 array of integers ranging from 0 to 300, not including 300 with increment of one in ascending order. Use `numpy` and not a for loop. *Hint: try using numpy.reshape() function*.\n", 33 | " The answer should be something like this:\n", 34 | " \n", 35 | " [[0 1 2] \n", 36 | " [3 4 5] \n", 37 | " [6 7 8] \n", 38 | " ...... \n", 39 | " [291 292 293] \n", 40 | " [294 295 296] \n", 41 | " [297 298 299]]\n", 42 | "\n", 43 | "7. [3 points] Find $\\cos(x)$ where $x = $ [0, $\\pi$] with 400 elements." 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "# 2. Plotting with Python (8 Points)\n", 51 | "\n", 52 | "\n", 53 | "1. [2 points] Plot $\\sin(x)$ where x is years ranging from 1998 to 2018 biannually.\n", 54 | "\n", 55 | "2. [3 points] In a different plot, plot $\\sin(x)$, $\\cos(x)$, $\\sin(2x)$, and $\\cos(2x)$ over the domain of $[-\\pi,\\pi]$ in increments of 0.1 radians. Colors for $\\sin(x)$, $\\cos(x)$, $\\sin(2x)$, and $\\cos(2x)$ should be red, blue, yellow and green, respectively. \n", 56 | "\n", 57 | "3. [3 points] Make a plot of $\\sin(x)$ ranging from (-$\\pi$,$\\pi$) with 4 data points, with 6 data points, with 8 data points and with 32 data points. Label plots with red, blue, green, and yellow colors for 4,8,16 and 32 points-containing plots.\n" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "# 3. Expected Value and Variance (13 Points)\n", 65 | "\n", 66 | "1. [3 points] For multiple generations, adults in Robertons family had 4 hieghts: 195cm, 180cm, 168cm, and 170cm with probablities of 0.2, 0.3, 0.1, and 0.4, respectively. What are expected height and the variance of the heights for adults in Robertson family?\n", 67 | "\n", 68 | "2. [3 points] Looking at historic data from Organic Chemistry course at University of Rochester, it was found that students were given the following grades, 100%, 95%, 80%, 75%, 70% and 65% with the following probabilites, 0.1,0.2,0.4,0.3, and 0.2 respectively. What is the expected value of a grade in organic chemistry class.\n", 69 | "\n", 70 | "\n", 71 | "3. [3 points] The unormalized probability distribution funciont of position, $x$, on [-2,2] is given by $-x^2+4$. What is the expected value of position $x$ in [-2,2]. Remember to normalize the probablity. \n", 72 | "\n", 73 | "4. [3 points] You are rolling an unfair dice. The probabilities of getting 6, 5, 4, 3, 2, and 1 are the following: 0.3, 0.25, 0.1, 0.1, 0.2, and 0.05. What is the expected value of rolling an unfair dice?\n", 74 | "\n", 75 | "5. [1 point] Your are thinking of investing in company that flips coin to determine whether you make a profit or do not make a profit. If the coin is heads, you make profit of 4 dollars and if the coin is tails, you lose 2 dollars. What is expected value of gaining/losing in this game? " 76 | ] 77 | } 78 | ], 79 | "metadata": { 80 | "kernelspec": { 81 | "display_name": "Python 3", 82 | "language": "python", 83 | "name": "python3" 84 | }, 85 | "language_info": { 86 | "codemirror_mode": { 87 | "name": "ipython", 88 | "version": 3 89 | }, 90 | "file_extension": ".py", 91 | "mimetype": "text/x-python", 92 | "name": "python", 93 | "nbconvert_exporter": "python", 94 | "pygments_lexer": "ipython3", 95 | "version": "3.6.4" 96 | } 97 | }, 98 | "nbformat": 4, 99 | "nbformat_minor": 2 100 | } 101 | -------------------------------------------------------------------------------- /unit_4/hw_2020/homework_4.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 4\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "*(2/6/2020)*\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Lists Problems\n", 21 | "\n", 22 | "1. [2 points] Create a variable called `x` which is a list containing all even numbers less than 100 using the `list(range(...))` syntax. \n", 23 | "\n", 24 | "2. [1 point] Compute the sum of `x` without using a `for` loop\n", 25 | "\n", 26 | "3. [4 points] Compute the sum of `x` with a `for ` loop.\n", 27 | "\n", 28 | "4. [1 point] Print the elements of `x` reversed using a slice\n", 29 | "\n", 30 | "5. [2 point] Print the second half of `x` using the `len(x) // 2` syntax\n", 31 | "\n", 32 | "6. [4 points] Create a new empty list `y`. Using a `for` loop and the `append` keyword, make `y` contain the square of each element of `x`. So it should contain: `[4, 16, ..., ]`." 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "# 2. Array Problem\n", 40 | "\n", 41 | "1. [2 points] Create a variable called `a` which is an array containing all even numbers less than 100 using the `numpy` `arange` syntax. \n", 42 | "\n", 43 | "2. [1 point] Compute the sum of `a` without using a `for` loop\n", 44 | "\n", 45 | "3. [1 point] Print the elements of `a` reversed using a slice\n", 46 | "\n", 47 | "4. [2 points] Print the minimum, maximum, and mean elements of `a` using `numpy` functions.\n", 48 | "\n", 49 | "5. [1 point] Print the square of each element in `a` without using a `for` loop or lists. You should just have one line of `numpy` code." 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "# 3 Plotting\n", 57 | "\n", 58 | "For each problem below, use numpy to create `x` and `y` arrays which are plotted. Be sure to label your x-axis, y-axis, put the problem number as the title, use at least 500 points, make your figures be 4x3 inches, and add a legend if you have more than one line being plotted.\n", 59 | "\n", 60 | "1. [6 points] Plot $y = x^2$ from $-1$ to $1$\n", 61 | "\n", 62 | "2. [8 points] A hanging rope, wire, or chain follows a catenary curve ($y = a\\textrm{cosh}\\frac{x}{a} - a$), although many including Galileo mistakenly believed hanging ropes a parabolas. Compare the catenary and parabolic ($y = x^2$) curves over $-1$ to $1$ where $a = 0.63$.\n", 63 | "\n", 64 | "3. [8 points] Compare the functions $\\cos x$ and $\\cosh x - 1$ from $-\\pi/2$ to $\\pi/2$" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "# 4 Expected Value/Variance\n", 72 | "\n", 73 | "\n", 74 | "Use this probability distribution:\n", 75 | "\n", 76 | "$$\n", 77 | "Q = \\{\\textrm{red},\\textrm{ green}, \\textrm{blue}\\}\n", 78 | "$$\n", 79 | "\n", 80 | "$$\n", 81 | "P(\\textrm{red}) = 0.1,\\, P(\\textrm{green}) = 0.5,\\, P(\\textrm{blue}),\\, = 0.4\n", 82 | "$$\n", 83 | "\n", 84 | "1. [2 points] Create a dictionary called `prob` where the key is the colors as a string and the values are the probability.\n", 85 | "\n", 86 | "2. [4 points] Starting with this fragment, show that your probability distribution is normalized.\n", 87 | "\n", 88 | "```\n", 89 | "for key,value in prob.items():\n", 90 | " print(key, value)\n", 91 | "```\n", 92 | "\n", 93 | "3. [4 points] Let's define a random variable $X$ that is 1 for red, 2 for green, and 0 for blue. Using your `for` loop from 4.2, use boolean statements to set a variable $x$ to what the value of $X$ should be using the `key` variable. Print out `key, x`, which should look like `red, 1`, `green, 2`...\n", 94 | "\n", 95 | "4. [4 points] Compute the expected value of `x` using the `for` loop from 4.3\n", 96 | "\n", 97 | "5. [4 points] Compute the variance by hand, showing the steps in Markdown" 98 | ] 99 | } 100 | ], 101 | "metadata": { 102 | "kernelspec": { 103 | "display_name": "Python 3", 104 | "language": "python", 105 | "name": "python3" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": { 109 | "name": "ipython", 110 | "version": 3 111 | }, 112 | "file_extension": ".py", 113 | "mimetype": "text/x-python", 114 | "name": "python", 115 | "nbconvert_exporter": "python", 116 | "pygments_lexer": "ipython3", 117 | "version": "3.7.3" 118 | } 119 | }, 120 | "nbformat": 4, 121 | "nbformat_minor": 2 122 | } 123 | -------------------------------------------------------------------------------- /unit_4/lectures/lecture_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_4/lectures/lecture_2.pdf -------------------------------------------------------------------------------- /unit_5/hw_2019/Homework_5.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 5\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "2/15/2019\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "source": [ 27 | "1 Standard Probility Distributions (7 Points)\n", 28 | "====\n", 29 | "\n", 30 | "Choose below the probability distribution that best fits the described process. Choose only from Bernoulli, Geometric, Binomial, Poisson, Exponential, and Normal. 1 Points each. \n", 31 | "\n", 32 | "\n", 33 | "1. Whether or not it snows on a given day.\n", 34 | "2. How much snow accumulates in one day.\n", 35 | "3. How many times you plow snow within one week.\n", 36 | "4. Plowing the snow only once in a week.\n", 37 | "5. The time difference between snowstorms in Rochester in June.\n", 38 | "6. The number of time it snows in Washinton DC?\n", 39 | "7. How many road tests one takes before gets the driver's license. " 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "2 Plotting Probability Distributions (20 Points)\n", 47 | "===\n", 48 | "Plot the probablities using Python. Accurately label x and y axis. State which distribution the plot is decribing. Make distinction in the use of discrete or continuous variables in the plots. Use `for` loops to compute probabilities.\n", 49 | "\n", 50 | "\n", 51 | "\n", 52 | "1. [6 points] Probablity of a rain in a given day is 0.2. A month contains 31 days. We are interested in probabilities of the first rain happening in any of the day of the month. Plot the probabilities of raining on a given day for the first time for every day of the month. Which day has the highest probability?\n", 53 | "2. [8 points] The probability of rain is 0.3 in a given day. Plot the number days it will rain and their corresponding probilities in a given month of 31 days. Show the expected value of the distribution as a red vertical line in the plot.\n", 54 | "\n", 55 | "3. [6 points]Probability of death cancer is 5%. Compute the probability of any number of people dying from cancer in group of 100 people\n", 56 | " \n" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "3 Working with Probability Distributions (10 Points)\n", 64 | "====\n", 65 | "For the following problems, choose and state an appropriate distribution, write out its parameters based on the problem statement and then compute the requested quantity. Write the distribution information in Markdown/LaTeX and compute answers in Python. Use `for` loops for computing expected value and prediction intervals. Do not use `numpy` or the formulas given in lecture notes. Assume in all these examples that multiple trials are independent.\n", 66 | "\n", 67 | "\n", 68 | "1. [2 points] Let's assume total solar eclipse happens in continental USA every 38 years. The Last total solar eclipse was in 2017 in USA. What is probability of total solar eclipse in continental USA in 2020? *Remember to read the instruction above!!*\n", 69 | "2. [2 points] Let's assume Lyft drivers pick up clients at probability of 3% at any given time. What is the probability of a Lyft driver taking only 10 people of out 400 clients. \n", 70 | "3. [2 points] You are teaching your son the alphabet, the probability of him saying the letter A correctly is 0.1. After 10 tries, what is probability he will say the letter A correctly once? \n", 71 | "4. [2 points] In January, you applied to 50 jobs. The probability of getting an interview is 0.3 for in January. What is the probablity that you get 7 interviews that month? What is the expected value of this distribution? \n", 72 | "\n", 73 | "5. [2 points] On average you run with probability of 0.4 per day. What is the the expected number of days on which you run?\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [] 82 | } 83 | ], 84 | "metadata": { 85 | "kernelspec": { 86 | "display_name": "Python 3", 87 | "language": "python", 88 | "name": "python3" 89 | }, 90 | "language_info": { 91 | "codemirror_mode": { 92 | "name": "ipython", 93 | "version": 3 94 | }, 95 | "file_extension": ".py", 96 | "mimetype": "text/x-python", 97 | "name": "python", 98 | "nbconvert_exporter": "python", 99 | "pygments_lexer": "ipython3", 100 | "version": "3.6.6" 101 | } 102 | }, 103 | "nbformat": 4, 104 | "nbformat_minor": 2 105 | } 106 | -------------------------------------------------------------------------------- /unit_5/hw_2020/homework_5.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 5\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "*(2/13/2020)*\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Probability Distribution Identification (7 Points)\n", 21 | "\n", 22 | "State what probability distribution best describes the following random numbers. 1 point each.\n", 23 | "\n", 24 | "1. The number of times you win in five boxing matches\n", 25 | "2. Number of days until you drop and break your phone. \n", 26 | "3. If the temperature is above or below freezing\n", 27 | "4. The value of the temperature outside\n", 28 | "5. The number of students who get 4.0 when graduating\n", 29 | "6. The number of minutes between emails\n", 30 | "7. The number of emails received in one minute" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# 2. Computing Outcome Probabilities (12 Points)\n", 38 | "\n", 39 | "For the following problems, choose and state an appropriate distribution, write out its parameters based on the problem statement and then compute the requested quantity. Write the distribution information in Markdown/LaTeX and compute answers in Python. Choose only from the distributions presented in lecture. 4 points each\n", 40 | "\n", 41 | "1. The probability of success for becoming a successful actor is 0.01. What is the probability of not becoming a successful actor?\n", 42 | "\n", 43 | "2. Five people are competing in an ultra marathon. The probability to complete the ultra marathon is 50%. What is the probability that 3 complete the ultra marathon?\n", 44 | "\n", 45 | "3. You are watching deer walk across a street. 10 deer take 5 minutes to cross the street. What is the probability of seeing a deer cross within the first minute?" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "# 3 Plotting Probability Distributions (24 Points)\n", 53 | "\n", 54 | "Plot the probablities using Python. Accurately label x and y axis. State which distribution the plot is decribing. Make distinction in the use of discrete or continuous variables in the plots. Use `for` loops to compute probabilities. Choose reasonalbe axes limits that encapsulate 99% of probability. Do not use numpy. 8 points each.\n", 55 | "\n", 56 | "\n", 57 | "1. Each time you make a post on Twitter, there is an 80% chance you get a retweet. Plot the probability of number of tweets before you get one with a retweet. \n", 58 | "\n", 59 | "2. You are racing your 3 friends in Mario Kart. Due to your practice, you have a 45% chance of winning in a match. Plot the probability of number of wins if you and your friends race in 14 matches. \n", 60 | "\n", 61 | "3. Over the past two hundred hunger games, district 9 has won 3 times. Plot the probability for number of district 9 wins in the next **10 years**." 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "# 4 Working with Probability Distributions (18 Points)\n", 69 | "\n", 70 | "\n", 71 | "Compute answers in Python using `for` loops. Do not use `numpy`. Use only the distributions from lecture notes. 6 points each\n", 72 | "\n", 73 | "\n", 74 | "1. Five people are competing in an ultra marathon. The probability to complete the ultra marathon is 50%. What is the probability that more than 3 complete the ultra marathon?\n", 75 | "\n", 76 | "2. Each time you make a post on Twitter, there is an 80% chance you get a retweet. What is the probability that it takes more than 4 tweets before you get a retweet?\n", 77 | "\n", 78 | "3. Show that the equation for the binomial distribution is normalized (sums to 1) for $n = 5$, $p = 0.2$." 79 | ] 80 | } 81 | ], 82 | "metadata": { 83 | "kernelspec": { 84 | "display_name": "Python 3", 85 | "language": "python", 86 | "name": "python3" 87 | }, 88 | "language_info": { 89 | "codemirror_mode": { 90 | "name": "ipython", 91 | "version": 3 92 | }, 93 | "file_extension": ".py", 94 | "mimetype": "text/x-python", 95 | "name": "python", 96 | "nbconvert_exporter": "python", 97 | "pygments_lexer": "ipython3", 98 | "version": "3.7.3" 99 | } 100 | }, 101 | "nbformat": 4, 102 | "nbformat_minor": 2 103 | } 104 | -------------------------------------------------------------------------------- /unit_5/lectures/lecture_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_5/lectures/lecture_1.pdf -------------------------------------------------------------------------------- /unit_5/lectures/lecture_1.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{teaching, array} 4 | 5 | \begin{document} 6 | 7 | \begin{tdoc}{CHEM 116}{Unit 5, Lecture 1}{Numerical Methods and Statistics} 8 | 9 | \subsection*{Companion Reading} 10 | \textbf{Bulmer} Chapter 6 11 | 12 | \section{Distributions} 13 | 14 | Some random variables/sample spaces are so common, we have a name and 15 | equations that describe them. For example, consider the simplest 16 | probability mass function/distribution: 17 | 18 | \subsection{Bernoulli Distribution} 19 | 20 | The Bernoulli distribution has a sample space of size 2 (e.g., 0, 1) with probability: 21 | \begin{equation} 22 | \Pr(X = 1) = p,\: \Pr(X = 0) = 1 - p 23 | \end{equation} 24 | The expected value is $p$ and the variance is $p(1-p)$. An example of 25 | a process that follows a Bernoulli distribution is flipping a coin 26 | once. Typically 1 is denoted as success and 0 as failure. 27 | 28 | There are three important things to recall about a distribution: its 29 | {\bf sample space type} (continuous/discrete), its {\bf support} or 30 | {\bf sample space}, and what it describes. You should remember these 31 | things for many common distributions and then look up the details such 32 | as their variance in your textbook or online. Support (the probability 33 | is greater than $0$) is 34 | \begin{equation} 35 | x \in \Pr(X = x) > 0 36 | \end{equation} 37 | 38 | Support is important when the sample space contains zero probability 39 | elements. For example, if in a Bernoulli $p = 0$, that means there is no probabilitiy mass for $x = 1$ and thus 40 | $x = 1$ is no longer in the support. 41 | 42 | \subsection{Geometric Distribution} 43 | A geometric distribution is discrete and has a sample space of 44 | $[1,\infty)$. It is the number of trials required until 45 | success. Specifically, we have a Bernoulli process where the 46 | probability of success is a constant $p$ and $n$ is the number of 47 | failures until a success is achieved: 48 | \begin{equation} 49 | \Pr(X = n) = (1 - p)^{n - 1}p 50 | \end{equation} 51 | 52 | The expected value is $1 / p$ and the variance is: 53 | \begin{equation} 54 | \frac{1 - p}{p^2} 55 | \end{equation} 56 | 57 | An example is the number of times until a heads is seen while flipping 58 | a coin. Notice that the Geometric is unbounded in sample space. This 59 | makes it simple to distinguish between the other discrete probability 60 | distributions. For example, a Bernoulli distribution could be if you 61 | like a Facebook post or not. There are two outcomes. A Geometric 62 | distribution could be the number of Facebook posts you view before you 63 | like one. Depending on how cynical you are, there is no upper bound on 64 | the number you view. 65 | 66 | \subsection{Binomial Distribution} 67 | A binomial distribution is discrete and has a sample space of 68 | $[0,N]$. It is the number of successes in $N$ trials. It is an 69 | important distribution for considering permutations. Its equation is: 70 | \begin{equation} 71 | \Pr(X=n) = {N \choose n} p^n(1 - p)^{N - n} 72 | \end{equation} 73 | 74 | \begin{equation} 75 | {N \choose n} = \frac{N!}{(N - n)! n!} 76 | \end{equation} 77 | 78 | and the expected value is $Np$. The variance is $Np(1-p)$. An example 79 | is the number of boys in a family of eight children. 80 | 81 | An easy way to distinguish a Bernoulli from a Binomial is to think 82 | about if the sample space has more than 2 elements. For example, I may 83 | retweet a tweet or not. That's a Bernoulli. If I examine 5 tweets and 84 | I may retweet any of them, the number of retweets I make is a 85 | Binomial, since it can vary from 0 to 5 (6 possibilities). 86 | 87 | \subsection{Poisson Distribution} 88 | A Poisson distribution is discrete and has a sample space of 89 | $[0,\infty)$. It can be thought of an approximation to the Binomial 90 | distribution in the case of very low chances of success ($p << 0.5$), 91 | where $\mu = Np$. Its equation is 92 | \begin{equation} 93 | \Pr(X = x) = \frac{e^{-\mu}{\mu^x}}{x!} 94 | \end{equation} 95 | and the expected value is $\mu$. The variance is also $\mu$. An 96 | example is the number of deaths by horse kick in the 14 corps of the 97 | Prussian Army. It can also be viewed as the number of events in a 98 | fixed time interval. For example, if we are watching a live stream of 99 | an event, the number of comments could be modeled by a Poisson 100 | distribution. 101 | 102 | \subsection{Exponential Distribution} 103 | The exponential distribution is a continuous distribution with a 104 | support of $[0,\infty)$. It generally describes time between events, 105 | especially events whose occurrence follow the Poisson distribution. 106 | Its distribution is 107 | \begin{equation} 108 | p(x) = \lambda e^{-\lambda x} 109 | \end{equation} 110 | 111 | and the expected value is $ 1 / \lambda$. You may also think of it in 112 | terms of a residence time $\tau = 1 / \lambda$. Note that the equation is for its probability distribution functin (pdf) and not probability \textit{mass} function. This is indicated by the lower case $p$. The variance is 113 | $\lambda^{-2}$ or $\tau^2$. Note that we can more easily imagine the process in 114 | terms of its cumulative probability (see drawing) and not 115 | instantaneous pdf. 116 | 117 | Following our previous example of a live stream, the time between 118 | comments will follow an exponential distribution if the comments 119 | follow a Poisson distribution. Even though the Poisson is discrete, 120 | the time between comments is continuous since time is a continuous 121 | value. 122 | 123 | 124 | \subsection{Normal Distribution} 125 | 126 | The normal distribution is a continuous distribution with a support 127 | of $(-\infty, \infty)$. We will see why later in the semester, but a 128 | normal distribution is almost always a good guess for the 129 | description of a process if it is continuous. Its equation is: 130 | 131 | \begin{equation} 132 | p(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x - \mu)^2}{2\sigma ^2}} 133 | \end{equation} 134 | 135 | \end{tdoc} 136 | 137 | \end{document} 138 | -------------------------------------------------------------------------------- /unit_5/lectures/lecture_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_5/lectures/lecture_2.pdf -------------------------------------------------------------------------------- /unit_5/lectures/lecture_2.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{teaching, array} 4 | 5 | \begin{document} 6 | 7 | \begin{tdoc}{CHEM 116}{Unit 5, Lecture 2}{Numerical Methods and Statistics} 8 | 9 | \subsection*{Companion Reading} 10 | \textbf{Bulmer} Chapter 6 11 | 12 | \section{Working With Distributions} 13 | 14 | \subsection{Computing the Probability of a Sample} 15 | 16 | You are on Facebook. You see a post. The probability you like a post 17 | is 0.10. What kind of distribution is this? Bernoulli because there 18 | are two outcomes and fixed probability for each. [Draw a Picture] 19 | 20 | You scroll down Facebook and decide to stop once you like a single 21 | post. Again you like a post with probability 0.1. What is the 22 | probability you liked a single post and stopped after seeing 10 23 | posts? This is a geometric distribution because we stop as soon as we 24 | succeed and the number of trials is unbounded. [Draw a Picture] 25 | \[ 26 | P(n=10) = (1 - 0.1)^{10 - 1}(0.1) = 0.039 27 | \] 28 | 29 | You no longer stop after liking a post, you just scroll through a 30 | fixed number. What is the probability you liked 3 posts after seeing 31 | 10 posts? This is a binomial distribution because it has a fixed 32 | number of trials and the order does not matter. [Draw a Picture] 33 | \[ 34 | P(n=3) = {10 \choose 3} (1 - 0.1)^{10 -3 }(0.1)^{3} = 0.057 35 | \] 36 | 37 | You've become very cynical and only like 2\% of posts now. You scroll 38 | through 250 posts. What is the probability you liked 4 posts? This is 39 | a Poisson distribution because it is the same as set-up as a binomial 40 | but the probability is low and the trial number is high. First, to 41 | get the parameter for the Poisson, $\mu$, we must compute it. It's 42 | the expected number of successes $\mu = Np = 250 \times 0.02 = 5.0$ 43 | [Draw a Picture] 44 | \[ 45 | P(n=4) = \frac{e^{-5}5^4}{4!} = 0.175 46 | \] 47 | 48 | \subsection{Computing the Probability of an Interval} 49 | 50 | All of these examples have small probabilities because we're looking 51 | at single points. What about intervals. 52 | 53 | Return to the geometric example. What's the probability that you liked 54 | a post and stopped scrolling in less than 10 posts? [Draw a picture] 55 | 56 | \[ 57 | P(n = 1) + P(n = 2) + ... = \sum_{i=1}^{9} P(n = i) 58 | \] 59 | Using Python... 60 | \[ 61 | P(n < 10) = 0.724 62 | \] 63 | 64 | What about the opposite? What's the probability it took more than or 65 | 10 posts? 66 | \[ 67 | P(n >= 10) = 1 - P(n < 10) = 0.276 68 | \] 69 | [Draw a picture]. An example of the NOT rule. 70 | 71 | We can use the same equation, $\sum_{i=1}^N P(i)$, to compute these 72 | intervals with discrete probability mass functions. 73 | 74 | \subsection{Computing the Probability of an Interval for Continuous Distributions} 75 | 76 | Let's assume Facebook posts arrive according to an exponential 77 | distribution. This makes sense because time is continuous, cannot be 78 | negative, and exponential distributions describe the time between 79 | random events. If on average 10 posts occur per hour, $\lambda$ the 80 | exponential parameter is $1/6$ inverse minutes. What is the probability of a 81 | new post within the 5 minutes? [Draw a picture] 82 | \[ 83 | \Pr(t < 5) = \int_0^{5} \lambda e^{-\lambda t}\,dt = -\frac{\lambda}{\lambda}\left.e^{-\lambda t}\right]_0^{5} = 0.63 84 | \] 85 | 86 | What is the probability a new post arrives after 2 minutes but before 10 minutes? 87 | \[ 88 | \Pr(2 < t < 10) = \int_{2}^{10} \lambda e^{-\lambda t}\,dt = 0.53 89 | \] 90 | [Draw a picture] 91 | 92 | What is the probability the new post comes after 4 minutes? 93 | \[ 94 | \Pr(t > 4) = \int_4^{\infty} \lambda e^{-\lambda t}\,dt = \left.-e^{-\lambda t}\right]_4^{\infty} = 0.51 95 | \] 96 | [Draw a picture] 97 | 98 | You decide to stop playing on the Internet so much, but you only like 99 | going outside if the temperature is greater than 65 degrees and less 100 | then 80 degrees. Assume the temperature has a mean of 45 degrees in 101 | Rochester and the standard deviation is 15 degrees. Assume you measure 102 | the temperature once per day. What's the probability you'll go outside? 103 | \[ 104 | \Pr(65 < T < 80) = \int_{65}^{80} \frac{1}{\sigma\sqrt{2\pi}}e^{\frac{-(x - \mu)^2}{2\sigma ^2}} = 0.15 105 | \] 106 | Note, the above equation must be evaluated numerically. [Draw a 107 | picture] 108 | 109 | \subsection{Finding Prediction Intervals} 110 | 111 | Let's return to the geometric distribution. What if we're interested 112 | in solving this equation? [Draw a Picture] 113 | \[ 114 | \argmin_x P(1 \geq n \leq x) = 0.9 115 | \] 116 | What is the number of trials for which there is a 90\% probability we 117 | succeeded? This called a \emph{Prediction Interval}. This generally 118 | must be solved with Python. The answer is 15. Compare that with the 119 | expected value, which is 10. The answer to the question: ``How long 120 | will it take to find a post you like?'' is about 10. A prediction 121 | interval allows us to give a worst-case value, where we are wrong 122 | about it 10\% of the time. We state it as ``With a prediction level of 123 | 10\%, the number of posts I will see before liking one is 15''. 124 | 125 | The interval should also exceed or be equal to the desired probability. The reason for the $\argmin_x$ is that we could trivially choose $x$ to be 126 | $\infty$. When we work with other distributions, the lower point can change. For example, in a binomial we would have: 127 | \[ 128 | \argmin_x P(0 \leq n \leq x) = 0.95 129 | \] 130 | 131 | for a 95\% prediction interval. When the lower-bound is the lowest value in the sample space (i.e., 0 for binomial or 1 for geometric), this is called a ``lower'' prediction interval. We can swap where $x$ goes to create an ``upper'' prediction interval. For example, again with geometric: 132 | \[ 133 | \argmax_x P(x \leq n \leq \infty) = 0.80 134 | \] 135 | Notice we now have an $\argmax_x$. In words, we're asking at what value will 80\% of samples fall above. 136 | 137 | \end{tdoc} 138 | 139 | \end{document} 140 | -------------------------------------------------------------------------------- /unit_6/hw_2017/problem_set_3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Answer the following questions in Python by defining a function. Ensure you have a docstring and that your function succeeds on the example use. " 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": { 13 | "nbgrader": { 14 | "grade": false, 15 | "grade_id": "45345", 16 | "locked": true, 17 | "schema_version": 1, 18 | "solution": false 19 | } 20 | }, 21 | "source": [ 22 | "Write your own implementation of the cumulative distribution function for the Binomial distribution. Your function should be called `binom_cdf` and take in `x, p, N` as arguments. It should return the probability of a sample between `0` and `x`, including `x`. It should return `None` if the arguments are invalid (e.g., `x = 'foo'` or `p = -4` or `x = -4`)" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 31, 28 | "metadata": { 29 | "collapsed": false, 30 | "nbgrader": { 31 | "grade": true, 32 | "grade_id": "24242", 33 | "locked": false, 34 | "points": 4, 35 | "schema_version": 1, 36 | "solution": true 37 | } 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "#The points awarded this cell corresopnd to partial credit and/or documentation\n", 42 | "\n", 43 | "### BEGIN SOLUTION\n", 44 | "import numpy as np\n", 45 | "from scipy.special import binom\n", 46 | "def binom_cdf(x, p, N):\n", 47 | " '''The binomial distribution cumulative probability function\n", 48 | " \n", 49 | " Args:\n", 50 | " x: the inclusive upper bound\n", 51 | " p: the probability of success\n", 52 | " N: the number of trials of the binomial \n", 53 | " \n", 54 | " returns: the sum of probability of samples from 0 to x\n", 55 | " '''\n", 56 | " \n", 57 | " if(type(x) != int or type(x) != int or type(N) != int):\n", 58 | " return None\n", 59 | " if(p < 0 or p > 1):\n", 60 | " return None\n", 61 | " if(N < 1):\n", 62 | " return None\n", 63 | " if x < 0 or x > N:\n", 64 | " return None\n", 65 | " \n", 66 | " n = np.arange(0,x + 1)\n", 67 | " Pn = binom(N, n) * p**n * (1 - p)**(N - n)\n", 68 | " return np.sum(Pn)\n", 69 | "### END SOLUTION" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 32, 75 | "metadata": { 76 | "collapsed": false, 77 | "nbgrader": { 78 | "grade": true, 79 | "grade_id": "4534", 80 | "locked": true, 81 | "points": 4, 82 | "schema_version": 1, 83 | "solution": false 84 | } 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "'''Check that your answer is correct on some test inputs using scipy stats'''\n", 89 | "\n", 90 | "from numpy import testing as t\n", 91 | "import scipy.stats as ss\n", 92 | "\n", 93 | "t.assert_almost_equal( binom_cdf(2, 0.5, 5), ss.binom.cdf(2, p=0.5, n=5) )\n", 94 | "\n", 95 | "### BEGIN HIDDEN TESTS\n", 96 | "t.assert_almost_equal( binom_cdf(2, 0.1, 5), ss.binom.cdf(2, p=0.1, n=5) )\n", 97 | "t.assert_almost_equal( binom_cdf(0, 0.7, 15), ss.binom.cdf(0, p=0.7, n=15) )\n", 98 | "### END HIDDEN TESTS" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 33, 104 | "metadata": { 105 | "collapsed": false, 106 | "nbgrader": { 107 | "grade": true, 108 | "grade_id": "34", 109 | "locked": true, 110 | "points": 4, 111 | "schema_version": 1, 112 | "solution": false 113 | } 114 | }, 115 | "outputs": [], 116 | "source": [ 117 | "'''Check that your answer deals with invalid input correclty'''\n", 118 | "\n", 119 | "from numpy import testing as t\n", 120 | "import scipy.stats as ss\n", 121 | "\n", 122 | "t.assert_equal( binom_cdf('test', 0.5, 5), None)\n", 123 | "\n", 124 | "### BEGIN HIDDEN TESTS\n", 125 | "t.assert_equal( binom_cdf(-4, 0.5, 5), None)\n", 126 | "t.assert_equal( binom_cdf(6, 0.5, 5), None)\n", 127 | "t.assert_equal( binom_cdf(2, 5, 5), None)\n", 128 | "t.assert_equal( binom_cdf(2, 0.4, -4), None)\n", 129 | "### END HIDDEN TESTS" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "celltoolbar": "Create Assignment", 135 | "kernelspec": { 136 | "display_name": "Python 3", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.5.3" 151 | } 152 | }, 153 | "nbformat": 4, 154 | "nbformat_minor": 2 155 | } 156 | -------------------------------------------------------------------------------- /unit_7/hw_2018/Homework_7.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 7\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "3/8/2018\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "1. Conceptual Questions (8 Points)\n", 21 | "===\n", 22 | "*Answer these in Markdown*\n", 23 | "\n", 24 | "1. [1 point] In problem 4 from HW 3 we discussed probabilities of having HIV and results of a test being positive. What was the sample space for this problem? \n", 25 | "2. [4 points] One of the notations in the answer key is a random variable $H$ which indicated if a person has HIV. Make a table showing this functions inputs and outputs for the sample space. [Making Markdown Tables](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables)\n", 26 | "3. [1 point] A probability density function is used for what types of probability distributions?\n", 27 | "4. [2 points] What is the probability of $t > 4$ in an exponential distribution with $\\lambda = 1$? Leave your answer in terms of an exponential." 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "2. The Nile (10 Points)\n", 35 | "===\n", 36 | "\n", 37 | "*Answer in Python*\n", 38 | "\n", 39 | "1. [4 points] Load the Nile dataset and convert to a numpy array. It contains measurements of the annual flow of the river Nile at Aswan. Make a scatter plot of the year vs flow rate. If you get an error when loading `pydataset` that says `No Module named 'pydataset'`, then execute this code in a new cell once: `!pip install pydataset`\n", 40 | "\n", 41 | "2. [2 points] Report the correlation coefficient between year and flow rate.\n", 42 | "\n", 43 | "2. [4 points] Create a histogram of the flow rates and show the median with a vertical line. Labels your axes and make a legend indicating what the vertical line is." 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "2. Insect Spray (10 Points)\n", 51 | "===\n", 52 | "\n", 53 | "*Answer in Python*\n", 54 | "\n", 55 | "1. [2 points] Load the 'InsectSpray' dataset, convert to a numpy array and print the number of rows and columns. Recall that numpy arrays can only hold one type of data (e.g., string, float, int). What is the data type of the loaded dataset?\n", 56 | "\n", 57 | "2. [2 points] Using `np.unique`, print out the list of insect spray used. This data is a count insects on a crop field with various insect sprays.\n", 58 | "\n", 59 | "3. [4 points] Create a violin plot of the data. Label your axes.\n", 60 | "\n", 61 | "4. [2 points] Which insect spray worked best? What is the mean number of insects for the best insect spray?" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": { 67 | "collapsed": true 68 | }, 69 | "source": [ 70 | "3. NY Air Quality (6 Points)\n", 71 | "===\n", 72 | "\n", 73 | "Load the 'airquality' dataset and convert into to a numpy array. Make a scatter plot of wind (column 2, mph) and ozone concentration (column 0, ppb). Using the `plt.text` command, display the correlation coefficient in the plot. This data has `nan`s, which means \"not a number\". You can select non-nans by using `x[~numpy.isnan(x)]`. You'll need to remove these to calculate correlation coefficient. " 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": { 80 | "collapsed": true 81 | }, 82 | "outputs": [], 83 | "source": [] 84 | } 85 | ], 86 | "metadata": { 87 | "kernelspec": { 88 | "display_name": "Python 3", 89 | "language": "python", 90 | "name": "python3" 91 | }, 92 | "language_info": { 93 | "codemirror_mode": { 94 | "name": "ipython", 95 | "version": 3 96 | }, 97 | "file_extension": ".py", 98 | "mimetype": "text/x-python", 99 | "name": "python", 100 | "nbconvert_exporter": "python", 101 | "pygments_lexer": "ipython3", 102 | "version": "3.6.2" 103 | } 104 | }, 105 | "nbformat": 4, 106 | "nbformat_minor": 2 107 | } 108 | -------------------------------------------------------------------------------- /unit_7/hw_2019/Homework_7.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 1. Conceptual Questions (7 Points)\n", 8 | "\n", 9 | "*Answer these in Markdown*\n", 10 | "\n", 11 | "1. [1 point] What is the difference between a probability mass function and a probability density function?\n", 12 | "2. [1 point] What is the difference between a cumulative distribution function and a prediction interval?\n", 13 | "3. [1 point] Is the exponential distribution a continuous or discrete distribution? Is it valid to compute the probability of a single element in the sample space?\n", 14 | "4. [2 points] What is the probability of $t > 8$ in an exponential distribution with $\\lambda = \\frac{1}{4}$? Leave your answer as an unevaluated exponential. \n", 15 | "5. [1 point] This slice must have how many elements: `a[5:2]`? How can you tell without counting?" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# 2. Car Stopping Distance (10 Points)\n", 23 | "\n", 24 | "1. [4 points] Load the cars dataset and create a scatter plot. It contains measurements a cars' stopping distance in feet as a function of speed in mph. If you get an error when loading `pydataset` that says `No Module named 'pydataset'`, then execute this code in a new cell once: `!pip install --user pydataset`\n", 25 | "\n", 26 | "2. [4 points] Compute the sample correlation coefficient between stopping distance and speed in python and report your answer by writing a complete sentence in Markdown.\n", 27 | "\n", 28 | "2. [2 points] Why might there be multiple stopping distances for a single speed?" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "# 3. Housing Prices (24 Points)\n", 36 | "\n", 37 | "1. [8 points] Load the 'House' dataset and use `pydataset.data('Housing', show_doc=True)` to see information about the dataset. Use the snippet below to format your ticks with dollar signs and commas for thousands. Note that this data is from the 1970s. Assess the correlation between lotsize and price. Use plots and sample correlation coefficient as evidence to support a written answer.\n", 38 | "\n", 39 | "```python\n", 40 | "import matplotllib.ticker\n", 41 | "fmt = '${x:,.0f}'\n", 42 | "tick = matplotllib.ticker.StrMethodFormatter(fmt)\n", 43 | "plt.gca().yaxis.set_major_formatter(tick) \n", 44 | "```\n", 45 | "\n", 46 | "2. [8 points] Use a violin plot to show if being in a preferred neighborhood affects price. You may use any other calculations (e.g., sample standard deviation) to support your conclusions. Write out your conclusion.\n", 47 | "\n", 48 | "3. [8 points] Use a boxplot to determine if bedroom number affects price. What is your conclusion?" 49 | ] 50 | } 51 | ], 52 | "metadata": { 53 | "kernelspec": { 54 | "display_name": "Python 3", 55 | "language": "python", 56 | "name": "python3" 57 | }, 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.6.3" 69 | } 70 | }, 71 | "nbformat": 4, 72 | "nbformat_minor": 2 73 | } 74 | -------------------------------------------------------------------------------- /unit_7/hw_2020/homework_7.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 7\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "2/27/2020\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Midterm Review Question\n", 21 | "\n", 22 | "1. [8 points] Please complete the following table:\n", 23 | "\n", 24 | "\n", 25 | "| Name | Abbreviation | Mathematical Expression | input | output | \n", 26 | "|:-----|:------------:|:---------:|:-----:|-------:|\n", 27 | "| Probability Mass Function | PMF | $P(q)$ | element in sample space | probability |\n", 28 | "| ? | PDF | $p(q)$ | ? | must be integrated, outputs probability of interval |\n", 29 | "| ? | ? | $P(x < y)$ | upper bound of interval ($y)$ | ? |\n", 30 | "| ? | PPF | $y$ such that ? | probability of interval ($p$) | ? |\n", 31 | "\n", 32 | "2. [2 point] What are the inputs/outputs to a random variable?\n", 33 | "\n", 34 | "3. [2 points] If a problem statement gives you $P(X = 3 | Y = 4)$ and $P(Y = 4)$, what equation gives you $P(X = 3, Y = 4)$?\n", 35 | "\n", 36 | "4. [4 points] If you flip a coin twelve times, how many permutations are possible and how many combinations of heads/tails are possible?\n" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "# 2 Analyzing 1D Data\n", 44 | "\n", 45 | "1. [4 points] Load the sunspot.month dataset and histogram the **last** column (number of sunspots per month). Use this code snippet: `sunspot_data = pydataset.data('sunspot.month').values`. If you get an error when loading `pydataset` that says `No Module named 'pydataset'`, then execute this code in a new cell once: `!pip install --user pydataset`.\n", 46 | "\n", 47 | "2. [4 points] Using numpy compute the sample mean and sample standard deviation\n", 48 | "\n", 49 | "3. [6 points] Convert your data into a list (e.g., `l = list(sunspot_data[:,1])`) and write a `for` loop to compute the sample mean without using `numpy`\n", 50 | "\n", 51 | "4. [4 points] Use the `sort` method to find the median. " 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "# 3. Sleep deprevation\n", 59 | "\n", 60 | "1. [4 points] Load the sleep data. It contains change in reaction times in milliseconds of participants as a funciton of their sleep deprevation. Create a boxplot of the data where the x-axis is days of sleep deprevation.\n", 61 | "\n", 62 | "2. [2 points] Based on your plot, does reaction time change as you get less sleep?" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "# 4. Your Data\n", 70 | "\n", 71 | "In homework 1, I asked you to begin collecting data on two random processes. Please list again what your two things were and compute their mean, median and standard deviation. If your data does not have numerical values (e.g., colors, clothes), choose a random variable based on your data and compute it's mean. 6 points." 72 | ] 73 | } 74 | ], 75 | "metadata": { 76 | "kernelspec": { 77 | "display_name": "Python 3", 78 | "language": "python", 79 | "name": "python3" 80 | }, 81 | "language_info": { 82 | "codemirror_mode": { 83 | "name": "ipython", 84 | "version": 3 85 | }, 86 | "file_extension": ".py", 87 | "mimetype": "text/x-python", 88 | "name": "python", 89 | "nbconvert_exporter": "python", 90 | "pygments_lexer": "ipython3", 91 | "version": "3.7.3" 92 | } 93 | }, 94 | "nbformat": 4, 95 | "nbformat_minor": 2 96 | } 97 | -------------------------------------------------------------------------------- /unit_7/lectures/lecture_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_7/lectures/lecture_1.pdf -------------------------------------------------------------------------------- /unit_7/lectures/lecture_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitead/numerical_stats/21e391bcaca4983226f5d85a9ebdd3353379f028/unit_7/lectures/lecture_3.pdf -------------------------------------------------------------------------------- /unit_8/hw_2015/Homework_6.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:c61060666a7ce3a7505e1ee782530ed8662f00ee9c86c775bf36afea1d351334" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "Homework 6\n", 16 | "====\n", 17 | "####CHE 116: Numerical Methods and Statistics\n", 18 | "Prof. Andrew White\n", 19 | "\n", 20 | "Version 1.5 (2/20/2015)\n", 21 | "\n", 22 | "----" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "0. Warmup (2 Points)\n", 30 | "====\n", 31 | "\n", 32 | "1. We've seen two types of confidence intervals. One type is for predicting where the next sample will be in a known distribution and one type is for predicting where a true mean will be given some data. For the latter type, predicting the true mean, we saw how with many data points or if we know the true standard deviation we can use a normal distribution. When predicting the true mean with a few data points, the confidence interval for error in the mean follows a $t$-distribution. Thus there are three possible confidence interval problems. Write out and label an example problem that demonstrates each of the confidence intervals. Refer back to the example problems in Unit 6, Lecture 2. You only need to set-up your problems, not solve them.\n", 33 | "\n", 34 | "2. Find a problem you missed in any of your homeworks. Look at the key and state what mistake you made and how it would be fixed. Indicate which homework and problem you're referring to." 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "1. Book Problems (5 Points)\n", 42 | "====\n", 43 | "Complete the following problems from Bulmer. Use Python or Markdown where appropiate. \n", 44 | "\n", 45 | "* Exercise 6.10\n", 46 | "* Exercise 7.1\n", 47 | "\n", 48 | "Complete the following problems from Langley:\n", 49 | "\n", 50 | "* Q15 on pg 66 (you can skip the shortcut method and Snedecor's check)\n", 51 | "* Q17 on pg 88\n", 52 | "* Q25 on pg 90" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "2. CLT Theory (5 Points)\n", 60 | "====\n", 61 | "Indicate if the CLT applies with yes or no. If no, state why.\n", 62 | "\n", 63 | "1. You measure the density of a solution 5 times and take the average\n", 64 | "2. You sum the volume of oil in 20 barrels\n", 65 | "3. You record your electricity bill 25 times\n", 66 | "4. Flip a coin 25 times and consider a heads 0 and a tails 1 and take the average\n", 67 | "5. Your grade is the average of 20 homework" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "3. Confidence Intervals (4 Points)\n", 75 | "====\n", 76 | "Report the given confidence interval for error in the mean using the data in the next cell and describe in words what the confidence interval is for each example\n", 77 | "\n", 78 | "1. 90% Double\n", 79 | "2. 95% Double\n", 80 | "3. 99% Double\n", 81 | "4. 90% Lower (a value such that the mean lies below that value 90% of the time)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "collapsed": false, 87 | "input": [ 88 | "data_3_1 = [5.81, 5.27, 5.4, 4.9, 5.83, 3.2, 6.76, 4.29, 4.76, 5.51]\n", 89 | "data_3_2 = [51.47, 48.18, 48.35, 53.57]\n", 90 | "data_3_3 = [91.8, 104.04, 129.62, 99.34, 75.92, 56.03, 103.87, 66.27, 88.41, 105.17, 115.05, 111.13, 86.2, 113.48, 96.25, 100.81, 96.56, 89.02, 111.9, 106.55, 117.35, 87.61, 81.97, 106.32, 78.38, 102.38, 80.87, 110.6, 89.09, 132.1]\n", 91 | "data_3_4 = [5.89, 3.73, -10.77, -13.92, 0.73, -2.52, -9.69, 14.15, -8.16, 2.62, -0.93, -13.46, -2.95, -7.13, 1.01, 1.45, 16.0, -17.47, 9.58, 13.3]" 92 | ], 93 | "language": "python", 94 | "metadata": {}, 95 | "outputs": [], 96 | "prompt_number": 3 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "4. Math Equations (3 Points)\n", 103 | "====\n", 104 | "\n", 105 | "Solve the following equations using Newton's metod\n", 106 | "\n", 107 | "\n", 108 | "1. $\\cos(x^2) = x$\n", 109 | "2. $x^2 = 4839$\n", 110 | "3. $\\int_{\\pi}^{x} \\sin^2{s}\\,ds = 1$ *Hint: Review your previous homeworks to recall how to use quad to integrate*" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "collapsed": false, 116 | "input": [], 117 | "language": "python", 118 | "metadata": {}, 119 | "outputs": [] 120 | } 121 | ], 122 | "metadata": {} 123 | } 124 | ] 125 | } -------------------------------------------------------------------------------- /unit_8/hw_2016/homework_6.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 6\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "Version 1.0 (2/17/2016)\n", 11 | "\n", 12 | "----" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "1. Misc Distribution Problems (10 Points)\n", 20 | "====\n", 21 | "Answer symbolically first, indicating what equations your Python program is using, and then compute the answer in Python. If not specified, say which distribution you're assuming.\n", 22 | "\n", 23 | "1. [1] The time between traffic tickets is exponentially distributed. Based on past experience, you receive a traffic ticket about every 3 years. What's the probability of having one traffic ticket within 12 months? For two bonus points, what about have two traffic tickets within 12 months? Use scipy stats.\n", 24 | "\n", 25 | "2. [2] You see two deer per day on average. How many days must pass before you have a 99% of having seen a deer? Answer in days, hours, and minutes.\n", 26 | "\n", 27 | "3. [1] The expected score on a test is 90% with a standard deviation of 15%. You cannot receive more than 100% on this test. What's the probability failing (< 60%)?\n", 28 | "\n", 29 | "4. [2] Using the above parameters, what's the probability of getting an A (93%-100%)?\n", 30 | "\n", 31 | "7. [4] Using the definition of expected value, write a for loop that computes the expected value of a binomial distribution with $N = 10$ and $p = 0.3$. Do not use scipy stats. Compre with the fomula $E[x] = pN$ for binomial." 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "2. CLT Theory (4 Points)\n", 39 | "====\n", 40 | "Indicate if the CLT applies with yes or no. If no, state why.\n", 41 | "\n", 42 | "1. You measure the density of a solution 50 times and take the average\n", 43 | "2. You sum the number of students who attended the last 20 lectures\n", 44 | "4. Flip a coin 25 times and consider a heads 0 and a tails 1 and take the average\n", 45 | "5. Your final grade, which is the average of 25 homeworks, tests, and a project" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "3. Confidence Intervals (12 Points)\n", 53 | "====\n", 54 | "Report the given confidence interval for error in the mean using the data in the next cell and describe in words what the confidence interval is for each example\n", 55 | "\n", 56 | "1. 80% Double\n", 57 | "2. 99% Upper ( a value such that the mean lies above that value 99% of the time)\n", 58 | "3. 95% Double\n", 59 | "5. Redo part 3 with a known standard deviation of 2" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 4, 65 | "metadata": { 66 | "collapsed": false 67 | }, 68 | "outputs": [], 69 | "source": [ 70 | "data_3_1 = [93.14,94.66, 102.1, 79.98, 96.85, 106.79, 101.92, 91.99, 97.22, 99.1, 88.7, 123.66, 99.7, 115.03, 99.28, 114.59, 102.25, 88.4, 111.06, 75.19, 107.32, 81.21, 100.49, 109.04, 105.09, 96.17, 78.13, 98.37, 104.47, 95.41]\n", 71 | "data_3_2 = [2.24,3.86, 2.19, 1.5, 2.34, 2.55, 1.8, 3.99, 2.64, 3.8]\n", 72 | "data_3_3 = [53.43,50.49, 52.55, 51.73]" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "4. Sample Statistics (17 Points)\n", 80 | "=====\n", 81 | "\n", 82 | "Answer the following questions using the data given in the next cell.\n", 83 | "\n", 84 | "1. [1] What is the sample correlation between $X$ and $Y$?\n", 85 | "4. [5] Write your own method to compute sample covariance using a for loop. Use the code in the second cell below as a starting point. Do not use any numpy methods except to check your answer. *Hint: You will need to use two loops*\n", 86 | "3. [5 + 1] What is the median of $Y$? Use Python and Numpy. Be careful if you use the sort method, since it will permanently alter your $Y$ array. Use `y2 = Y[:]` to copy the list\n", 87 | "\n" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 2, 93 | "metadata": { 94 | "collapsed": true 95 | }, 96 | "outputs": [], 97 | "source": [ 98 | "X = [1.6,0.4, -1.05, -0.08, 0.99, -1.89, 0.29, 0.71, -0.47, 1.15]\n", 99 | "Y = [3.59,1.49, -2.57, -0.0, 2.0, -3.48, 0.14, 1.38, -1.48, 2.6]" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 3, 105 | "metadata": { 106 | "collapsed": false 107 | }, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "1.6 3.59\n", 114 | "0.4 1.49\n", 115 | "-1.05 -2.57\n", 116 | "-0.08 -0.0\n", 117 | "0.99 2.0\n", 118 | "-1.89 -3.48\n", 119 | "0.29 0.14\n", 120 | "0.71 1.38\n", 121 | "-0.47 -1.48\n", 122 | "1.15 2.6\n" 123 | ] 124 | } 125 | ], 126 | "source": [ 127 | "for xi, yi in zip(X, Y): \n", 128 | " print(xi, yi)" 129 | ] 130 | } 131 | ], 132 | "metadata": { 133 | "kernelspec": { 134 | "display_name": "Python 3", 135 | "language": "python", 136 | "name": "python3" 137 | }, 138 | "language_info": { 139 | "codemirror_mode": { 140 | "name": "ipython", 141 | "version": 3 142 | }, 143 | "file_extension": ".py", 144 | "mimetype": "text/x-python", 145 | "name": "python", 146 | "nbconvert_exporter": "python", 147 | "pygments_lexer": "ipython3", 148 | "version": "3.4.2" 149 | } 150 | }, 151 | "nbformat": 4, 152 | "nbformat_minor": 0 153 | } 154 | -------------------------------------------------------------------------------- /unit_8/hw_2018/Homework_8.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Homework 8\n", 8 | "====\n", 9 | "#### CHE 116: Numerical Methods and Statistics\n", 10 | "\n", 11 | "3/22/2018\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "1.CLT Concepts (8 Points)\n", 21 | "====\n", 22 | "\n", 23 | "1. If you sum together 20 numbers sampled from a binomial distribution and 10 from a Poisson distribution, how is your sum distribted?\n", 24 | "\n", 25 | "2. If you sample 25 numbers from *different* beta distributions, how will each of the numbers be distributed?\n", 26 | "\n", 27 | "3. Assume a HW grade is determined as the average of 3 HW assignments. How is the HW grade distributed?\n", 28 | "\n", 29 | "4. You measure the height of 3 people. What distribution will the uncertainty of the mean of the heights follow?\n" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "2. Confidence Interval (16 Points)\n", 37 | "===\n", 38 | "\n", 39 | "Report the given confidence interval for error in the mean using the data in the next cell and describe in words what the confidence interval is for each example. 4 points each\n", 40 | "\n", 41 | "1. 80% Double. \n", 42 | "2. 99% Upper ( a value such that the mean lies above that value 99% of the time)\n", 43 | "3. 95% Double\n", 44 | "4. Redo part 3 with a known standard deviation of 2\n", 45 | "\n", 46 | "`\n", 47 | "data_1 = [0.41,2.69,3.82,0.42,1.20]\n", 48 | "`\n", 49 | "\n", 50 | "`\n", 51 | "data_2 = [5.07,2.79,1.24,6.50,3.17,3.59,5.42,4.10,1.26,0.54,1.22,4.43,3.83,0.93,3.45,5.24,3.51,4.64,0.65,3.27,2.41,4.31,4.15,2.24,2.30,3.3]\n", 52 | "`\n", 53 | "\n", 54 | "`\n", 55 | "data_3 = [5.62,2.34,2.76,2.80,1.15,5.19,-0.91]\n", 56 | "`\n" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "Confidence Intervals (8 Points)\n", 64 | "====\n", 65 | "\n", 66 | "State what distribution and its parameters for each of the following cases. 2 points each.\n", 67 | "\n", 68 | "1. $P(\\mu - \\bar{x})$, $\\sigma = 2.4$, $N = 4$\n", 69 | "2. $P(\\mu)$, $\\bar{x} = 11$, $\\sigma_x = 3.2$, $N = 11$\n", 70 | "3. $P(\\mu)$, $\\bar{x} = -3$, $\\sigma_x = 2.1$, $N = 35$\n", 71 | "4. $P(\\mu)$, $\\bar{x} = 6$, $\\sigma = 11$, $N = 30$" 72 | ] 73 | } 74 | ], 75 | "metadata": { 76 | "kernelspec": { 77 | "display_name": "Python 3", 78 | "language": "python", 79 | "name": "python3" 80 | }, 81 | "language_info": { 82 | "codemirror_mode": { 83 | "name": "ipython", 84 | "version": 3 85 | }, 86 | "file_extension": ".py", 87 | "mimetype": "text/x-python", 88 | "name": "python", 89 | "nbconvert_exporter": "python", 90 | "pygments_lexer": "ipython3", 91 | "version": "3.6.4" 92 | } 93 | }, 94 | "nbformat": 4, 95 | "nbformat_minor": 2 96 | } 97 | -------------------------------------------------------------------------------- /unit_8/hw_2019/homework_8.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 8\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "2/21/2019\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Short Answer (12 Points)\n", 21 | "\n", 22 | "1. [2 points] If you sum together 20 numbers sampled from a binomial distribution and 10 from a Poisson distribution, how is your sum distribted?\n", 23 | "\n", 24 | "2. [2 points] If you sample 25 numbers from different beta distributions, how will each of the numbers be distributed?\n", 25 | "\n", 26 | "3. [4 points] Assume a HW grade is determined as the sample mean of 3 HW problems. How is the HW grade distributed if we do not know the population standard deviation? Why?\n", 27 | "\n", 28 | "4. [4 points] For part 3, how could not knowing the population standard deviation change how it's distributed? How does knowledge of that number change the behavior of a random variable?\n", 29 | "\n" 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "# 2. Confidence Intervals (30 Points)\n", 37 | "Report the given confidence interval for error in the mean using the data given for each problem and **describe in words** what the confidence interval is for each example. 6 points each\n", 38 | "\n", 39 | "### 2.1\n", 40 | "\n", 41 | "80% Double. \n", 42 | "\n", 43 | "`data_21 = [65.58, -28.15, 21.17, -0.57, 6.04, -10.21, 36.46, 10.67, 77.98, 15.97]`\n", 44 | "\n", 45 | "### 2.2\n", 46 | "\n", 47 | "99% Upper (lower bound, a value such that the mean lies above that value 99% of the time)\n", 48 | "\n", 49 | "`data_22 = [-8.78, -6.06, -6.03, -6.9, -13.57, -18.76, 1.5, -8.21, -3.21, -11.85, -2.72, -10.38, -11.03, -10.85, -7.6, -7.76, -5.99, -10.02, -6.32, -8.35, -19.28, -11.53, -6.04, -0.81, -12.01, -3.22, -9.25, -4.13, -7.22, -11.0, -14.42, 1.07]`\n", 50 | "\n", 51 | "### 2.3\n", 52 | "\n", 53 | "95% Double\n", 54 | "\n", 55 | "`data_23 = [14.62, 10.34, 7.68, 15.81, 14.48]`\n", 56 | "\n", 57 | "### 2.4\n", 58 | "\n", 59 | "Redo part 3 with a known standard deviation of 2\n", 60 | "\n", 61 | "\n", 62 | "### 2.5\n", 63 | "\n", 64 | "95% Lower (upper bound)\n", 65 | "\n", 66 | "`data_25 = [2.47, 2.03, 1.82, 6.98, 2.41, 2.32, 7.11, 5.89, 5.77, 3.34, 2.75, 6.51]`" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "# 3. Identifiying Distributions (12 Points)\n", 74 | "\n", 75 | "For each problem state if it is a t or normal distribution and reports the distribution's $\\mu$ and $\\sigma$. Note that $\\mu, \\sigma$s listed below are the population sigmas. Report your answer like: $T(0, 4.3, 4)$ to indicate a $t$-distribution with $\\mu = 0$, $\\sigma = 4.3$ and degrees of freedom of 3. 2 Points each\n", 76 | "\n", 77 | "1. $P(\\mu)$, $\\bar{x} = -2$, $\\sigma = 4$, $N = 30$\n", 78 | "2. $P(\\bar{x})$, $\\mu = 1$, $\\sigma = 2$, $N = 5$\n", 79 | "3. $P(\\mu - \\bar{x})$, $\\sigma = 4.3$, $N = 2$\n", 80 | "4. $P(\\mu)$, $\\bar{x} = 4$, $\\sigma_x = 1.7$, $N = 50$\n", 81 | "5. $P(\\mu)$, $\\bar{x} = 5.5$, $\\sigma_x = 2.1$, $N = 9$\n", 82 | "6. $P(\\mu - \\bar{x})$, $\\sigma_x = 4.3$, $N = 5$\n", 83 | "\n" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "language": "python", 91 | "name": "python3" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.6.4" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 2 108 | } 109 | -------------------------------------------------------------------------------- /unit_8/hw_2020/homework_8.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 8\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "3/27/2020\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "## 1. Central Limit Theorem (10 Points)\n", 21 | "\n", 22 | "State whether the CLT applies to the following cases. 2 points each\n", 23 | "\n", 24 | "1. You average crops harvested across 24 fields\n", 25 | "2. You sum the crops harvested from 24 fields\n", 26 | "3. You compute the maximum height among 25 people\n", 27 | "4. You compute the average tire pressure of the four tires on a car\n", 28 | "5. You measure the weight of 25 pumpkins" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "# 2. Confidence Intervals (30 Points)\n", 36 | "Report the given confidence interval for error in the mean using the data given for each problem what the confidence interval is for each example. 5 points each\n", 37 | "\n", 38 | "### 2.1\n", 39 | "\n", 40 | "95% Double. \n", 41 | "\n", 42 | "`data_21 = [65.58, -28.15, 21.17, -0.57, 6.04, -10.21, 36.46, 10.67, 77.98, 15.97]`\n", 43 | "\n", 44 | "### 2.2\n", 45 | "\n", 46 | "80% Upper (lower bound, a value such that the mean lies above that value 80% of the time)\n", 47 | "\n", 48 | "`data_22 = [-8.78, -6.06, -6.03, -6.9, -13.57, -18.76, 1.5, -8.21, -3.21, -11.85, -2.72, -10.38, -11.03, -10.85, -7.6, -7.76, -5.99, -10.02, -6.32, -8.35, -19.28, -11.53, -6.04, -0.81, -12.01, -3.22, -9.25, -4.13, -7.22, -11.0, -14.42, 1.07]`\n", 49 | "\n", 50 | "### 2.3\n", 51 | "\n", 52 | "80% Double\n", 53 | "\n", 54 | "`data_23 = [14.62, 10.34, 7.68, 15.81, 14.48]`\n", 55 | "\n", 56 | "### 2.4\n", 57 | "\n", 58 | "Redo part 3 with a known standard deviation of 3.5\n", 59 | "\n", 60 | "\n", 61 | "### 2.5\n", 62 | "\n", 63 | "90% Lower (upper bound)\n", 64 | "\n", 65 | "`data_25 = [2.47, 2.03, 1.82, 6.98, 2.41, 2.32, 7.11, 5.89, 5.77, 3.34, 2.75, 6.51]`" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "# 3. Identifiying Distributions (12 Points)\n", 73 | "\n", 74 | "For each problem state if it is a t or normal distribution and reports the distribution's parameters. Report your answer like: $T(0, 4.3, 4)$ to indicate a $t$-distribution with $\\mu = 0$, $\\sigma = 4.3$ and degrees of freedom of 4. Note that $\\mu, \\sigma$s listed below are the population sigmas, not the parameters of a $t$-distribution. 2 Points each\n", 75 | "\n", 76 | "1. $P(\\mu - \\bar{x})$, $\\sigma = 1$, $N = 5$\n", 77 | "2. $P(\\mu - \\bar{x})$, $\\sigma_x = 1$, $N = 5$\n", 78 | "2. $P(\\bar{x})$, $\\mu = -1$, $\\sigma = 2$, $N = 30$\n", 79 | "2. $P(\\bar{x})$, $\\mu = 1$, $\\sigma_x = 2$, $N = 5$\n", 80 | "4. $P(\\mu)$, $\\bar{x} = 3$, $\\sigma = 1.7$, $N = 4$\n", 81 | "5. $P(\\mu)$, $\\bar{x} = 2$, $\\sigma_x = 2.1$, $N = 9$\n" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [] 90 | } 91 | ], 92 | "metadata": { 93 | "kernelspec": { 94 | "display_name": "Python 3", 95 | "language": "python", 96 | "name": "python3" 97 | }, 98 | "language_info": { 99 | "codemirror_mode": { 100 | "name": "ipython", 101 | "version": 3 102 | }, 103 | "file_extension": ".py", 104 | "mimetype": "text/x-python", 105 | "name": "python", 106 | "nbconvert_exporter": "python", 107 | "pygments_lexer": "ipython3", 108 | "version": "3.7.3" 109 | } 110 | }, 111 | "nbformat": 4, 112 | "nbformat_minor": 2 113 | } 114 | -------------------------------------------------------------------------------- /unit_9/hw_2020/homework_9.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 9\n", 8 | "#### CHE 116: Numerical Methods and Statistics\n", 9 | "\n", 10 | "\n", 11 | "4/2/2020\n", 12 | "\n", 13 | "----" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": {}, 19 | "source": [ 20 | "# 1. Creating Matrices (6 Points)\n", 21 | "\n", 22 | "Create the following matrices using the given constraints. 2 Points each.\n", 23 | "\n", 24 | "1. In 2 lines of python (not including prints/imports), create a 6x6 matrix whose second column (where we count \"first\", \"second\", etc.) is 3's and all other elements in the matrix are 1.\n", 25 | "2. Using a list comprehension, show how to get a compute a list containing the first 10 powers of pi. \n", 26 | "3. Use an f-string to print out `exp(0.5)` to 2 significant figures. Do the computation inside the `{}` in the f-string." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "# 2. Matrix Calculations (10 Points)\n", 34 | "\n", 35 | "\n", 36 | "Use the two matrices given to answer the following problems. Answer in Python.\n", 37 | "\n", 38 | "$$A = \\left[\\begin{array}{lcr}\n", 39 | "4 & -3 & 8\\\\\n", 40 | "-3 & 4 & -4\\\\\n", 41 | "8 & -4 & 10\\\\\n", 42 | "\\end{array}\\right]$$\n", 43 | "\n", 44 | "\n", 45 | "$$B = \\left[\\begin{array}{lcr}\n", 46 | "1 & 5 & -1\\\\\n", 47 | "23 & -1 & -2\\\\\n", 48 | "1 & 2 & 3\\\\\n", 49 | "\\end{array}\\right]$$\n", 50 | "\n", 51 | "\n", 52 | "\n", 53 | "1. [1 points] Report the rank of matrix $\\mathbf{B}$ using Python.\n", 54 | "2. [1 points] Compute $\\mathbf{BAB}$\n", 55 | "3. [2 points] What is the second eigenvalue of $\\mathbf{B}$? \n", 56 | "4. [2 points] Solve $\\mathbf{B}\\vec{x} = \\vec{b}$ where $\\vec{b} = \\left[11, 84, 17\\right]$\n", 57 | "5. [1 points] Demonstrate your answer is correct for 2.4\n", 58 | "6. [2 points] Solve $\\mathbf{A}\\vec{x} = c\\vec{x}$ for $x$ where $c$ is an arbitrary scalar. \n", 59 | "7. [1 points] Demonstrate your answer is correct for 2.6" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "# 3. Hypothesis Testing\n", 67 | "\n", 68 | "\n", 69 | "1. [1 point] If your p-value is 0.075 and $\\alpha = 0.1$, should you reject the null hypothesis?\n", 70 | "2. [1 point] What is your p-value if your $T$-value is -3 in the two-tailed/two-sided $t$-test with a DOF of 5?\n", 71 | "3. [4 points] For a one-sample $zM$ test, what is the minimum number of standard deviations away from the population mean a sample should be to reject the null hypothesis with $\\alpha = 0.05$? Set-up the equation for this (2 points) and compute the answer (2 points). *Hint: your equation should have an integral on one side and you'll need to use ppf to compute*\n", 72 | "4. [3 points]For an N-sample $zM$ test, what is the minimum number of standard deviations away from the population mean a sample should be to reject the null hypothesis with $\\alpha = 0.05$ in terms of $N$? **Report this answer with one digit of precisions**. Modify your equation from 3.3 (2 points) and compute the answer (2 points). *This is an important expression to memorize*\n", 73 | "5. [1 point] In a Poisson hypothesis test (single-sided), what is the p-value if $\\mu = 3$ and the sample value is 20? *Hint: think about what you would expect the p-value to be*\n", 74 | "6. [1 point] What is the p-value for a student t-test with $\\bar{x} = 2$, $\\sigma_x = 0.8$, $\\mu=2.4$, and $N = 11$?" 75 | ] 76 | } 77 | ], 78 | "metadata": { 79 | "kernelspec": { 80 | "display_name": "Python 3", 81 | "language": "python", 82 | "name": "python3" 83 | }, 84 | "language_info": { 85 | "codemirror_mode": { 86 | "name": "ipython", 87 | "version": 3 88 | }, 89 | "file_extension": ".py", 90 | "mimetype": "text/x-python", 91 | "name": "python", 92 | "nbconvert_exporter": "python", 93 | "pygments_lexer": "ipython3", 94 | "version": "3.7.3" 95 | } 96 | }, 97 | "nbformat": 4, 98 | "nbformat_minor": 2 99 | } 100 | --------------------------------------------------------------------------------