% This template was designed by Victor Lin (victorlin@cs.stanford.edu) with edits by Lisa Yan.
% You should compile this with PDFLaTeX (default), not XeLaTeX.

% This is a comment!

% This is the document declaration
\documentclass[12pt]{article}

% these are some useful packages. these add functionality to your document
\usepackage{newtxtext} % sets font
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathdots}
\usepackage{graphicx}
\usepackage{fancyhdr}
%\usepackage[margin=1in]{geometry}
\usepackage{multicol}
\usepackage{bm}
\usepackage{listings}
\PassOptionsToPackage{usenames,dvipsnames}{color}  %% Allow color names
\usepackage{pdfpages}
\usepackage{algpseudocode}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage[T1]{fontenc}
\usepackage{inconsolata}
\usepackage{framed}
\usepackage[thinlines]{easytable}
\usepackage{minted}
\def\code#1{\texttt{#1}} % add some code in-line
\usepackage{mdframed}
\usepackage{colortbl}
\usepackage{makecell}
\usepackage{amsmath}  % math symbols
\usepackage{wrapfig}  % in case you want to use a figure
\usepackage{hyperref} % add hyper links

% This package controls the margins of the page.
\usepackage[top=1in, bottom=1in, left=0.8in, right=1in]{geometry}

\usepackage{multicol} % in case you want to use multiple columns
\setlength{\columnsep}{0.1pc}

% document headers!
\title{CS 109: Probability for Computer Scientists\\Problem Set \#5}
\author{author} % Change this to your name!
\date{\today} % today does the right thing

\makeatletter
\let\runauthor\@author
\lhead{\runauthor}
\chead{Problem Set \#5}
\rhead{\today}

\newcommand{\abs}[1]{\lvert #1 \rvert}
\newcommand{\absfit}[1]{\left\lvert #1 \right\rvert}
\newcommand{\norm}[1]{\left\lVert #1 \right\rVert}
\newcommand{\eval}[3]{\left[#1\right]_{#2}^{#3}}
\renewcommand{\(}{\left(}
\renewcommand{\)}{\right)}
\newcommand{\floor}[1]{\left\lfloor#1\right\rfloor}
\newcommand{\ceil}[1]{\left\lceil#1\right\rceil}
\newcommand{\pd}[1]{\frac{\partial}{\partial #1}}
\newcommand{\inner}[1]{\langle#1\rangle}
\newcommand{\cond}{\bigg|}
\newcommand{\rank}[1]{\mathbf{rank}(#1)}
\newcommand{\range}[1]{\mathbf{range}(#1)}
\newcommand{\nullsp}[1]{\mathbf{null}(#1)}
\newcommand{\repr}[1]{\left\langle#1\right\rangle}

\DeclareMathOperator{\Var}{Var}
\newcommand{\SD}{\operatorname{SD}}
\newcommand{\Cov}{\operatorname{Cov}}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Tr}{\mathbf{Tr}}
\DeclareMathOperator{\diag}{\mathbf{diag}}
\DeclareMathOperator{\dist}{\mathbf{dist}}
\DeclareMathOperator{\prob}{\mathbf{prob}}
\DeclareMathOperator{\dom}{\mathbf{dom}}
\DeclareMathOperator{\E}{\mathbf{E}}
\DeclareMathOperator{\R}{\mathbb{R}}
\DeclareMathOperator{\var}{\mathbf{var}}
\DeclareMathOperator{\quartile}{\mathbf{quartile}}
\DeclareMathOperator{\conv}{\mathbf{conv}}
\DeclareMathOperator{\VC}{VC}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\newcommand{\Uni}{\operatorname{Uni}}
\newcommand{\Ber}{\operatorname{Ber}}
\newcommand{\Bin}{\operatorname{Bin}}
\newcommand{\Geo}{\operatorname{Geo}}
\newcommand{\NegBin}{\operatorname{NegBin}}
\newcommand{\Zipf}{\operatorname{Zipf}}
\newcommand{\HypG}{\operatorname{HypG}}
\newcommand{\Poi}{\operatorname{Poi}}
\newcommand{\Beta}{\operatorname{Beta}}
\newcommand{\Normal}{\operatorname{\mathcal{N}}}
\newcommand{\N}{\operatorname{\mathcal{N}}}
\newcommand{\Exp}{\operatorname{Exp}}
\DeclareMathOperator{\NP}{\mathbf{NP}}
\DeclareMathOperator{\coNP}{\mathbf{coNP}}
\DeclareMathOperator{\TIME}{\mathsf{TIME}}
\DeclareMathOperator{\polytime}{\mathbf{P}}
\DeclareMathOperator{\PH}{\mathbf{PH}}
\DeclareMathOperator{\SIZE}{\mathbf{SIZE}}
\DeclareMathOperator{\ATIME}{\mathbf{ATIME}}
\DeclareMathOperator{\SPACE}{\mathbf{SPACE}}
\DeclareMathOperator{\ASPACE}{\mathbf{ASPACE}}
\DeclareMathOperator{\NSPACE}{\mathbf{NSPACE}}
\DeclareMathOperator{\Z}{\mathbb{Z}}
\DeclareMathOperator{\EXP}{\mathbf{EXP}}
\DeclareMathOperator{\NEXP}{\mathbf{NEXP}}
\DeclareMathOperator{\NTIME}{\mathbf{NTIME}}
\DeclareMathOperator{\DTIME}{\mathbf{DTIME}}
\DeclareMathOperator{\poly}{poly}
\DeclareMathOperator{\BPP}{\mathbf{BPP}}
\DeclareMathOperator{\ZPP}{\mathbf{ZPP}}
\DeclareMathOperator{\RP}{\mathbf{RP}}
\DeclareMathOperator{\coRP}{\mathbf{coRP}}
\DeclareMathOperator{\BPL}{\mathbf{BPL}}
\DeclareMathOperator{\IP}{\mathbf{IP}}
\DeclareMathOperator{\PSPACE}{\mathbf{PSPACE}}
\DeclareMathOperator{\NPSPACE}{\mathbf{NPSPACE}}
\DeclareMathOperator{\SAT}{\mathsf{SAT}}
\DeclareMathOperator{\NL}{\mathbf{NL}}
\DeclareMathOperator{\PCP}{\mathbf{PCP}}
\DeclareMathOperator{\PP}{\mathbf{PP}}
\DeclareMathOperator{\cost}{cost}
\let\Pr\relax
\DeclareMathOperator*{\Pr}{\mathbf{Pr}}

\usepackage{booktabs}
\usepackage{diagbox}
  % configure display of tables
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\newcommand\tab[1][1cm]{\hspace*{#1}}
\newcommand\tabhead[1]{\small\textbf{#1}}

\theoremstyle{definition}
\newtheorem*{answer}{Answer}

\definecolor{shadecolor}{gray}{0.95}

\setlength{\parindent}{0pt}

\pagestyle{fancy}
\setlength{\headheight}{15pt}

\renewcommand{\thefootnote}{\fnsymbol{footnote}}

% begin the document
\begin{document}

% actually insert the title.
\maketitle

%%%% Cite any collaboration here %%%
Cited collaboration: N/A
  
\begin{enumerate}
% 1
\item The joint probability density function of continuous random variables X and Y is given by: \[f_{X,Y}(x,y) = c \frac{y}{x} \qquad\text{where $0 < y < x < 1$}\]
    \begin{enumerate}[label=\alph*.]

    \item What is the value of $c$ in order for $f_{X,Y}(x,y)$ to be a valid probability density function?

    \item Are $X$ and $Y$ independent?  Explain why or why not.

    \item What is the marginal density function of $X$?

    \item What is the marginal density function of $Y$?

    \item What is $E[X]$?

    \end{enumerate}

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 2
\item A robot is located at the \emph{center} of a square world that is 10 kilometers on each side.  A package is dropped off in the robot's world at a point $(x, y)$ that is uniformly (continuously) distributed in the square.  If the robot's starting location is designated to be $(0, 0)$ and the robot can only move up/down/left/right parallel to the sides of the square, the distance the robot must travel to get to the package at point $(x, y)$ is $|x| + |y|$.  Let $D = {}$the distance the robot travels to get to the package.  Compute $E[D]$.

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 3
\item  Let $X$, $Y$, and $Z$ be independent random variables, where $X \sim \N(\mu_1, {\sigma_1}^2)$, $Y \sim \N(\mu_2, {\sigma_2}^2)$, and $Z \sim \N(\mu_3, {\sigma_3}^2)$.  
    \begin{enumerate}[label=\alph*.]

    \item Let $A = X + Y$. What is the distribution (along with parameter values) of A?
    \item Let $B = 4X+3$. What is the \textit{joint} distribution (along with parameter values) of $B$ and $Z$? (Hint: Bivariate Normal)
    \item Let $C = aX - b^2Y + cZ$, where $a$, $b$, and $c$ are real-valued constants.  What is the distribution (along with parameter values) of $C$?  Show how you derived your answer.

    \end{enumerate}

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 4
\item A fair 6-sided die is repeatedly rolled until the total sum of all the rolls exceeds 300.  Approximate (using the Central Limit Theorem) the probability that \emph{at least} 80 rolls are necessary to reach a sum that exceeds 300.

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 5
\item Program A will run 20 algorithms in sequence, with the running time for each algorithm being independent random variables with mean = 46 seconds and variance = 100 seconds${}^2$.  Program B will run 20 algorithms in sequence, with the running time for each algorithm being independent random variables with mean = 48 seconds and variance = 200 seconds${}^2$.

    \begin{enumerate}[label=\alph*.]

    \item What is the approximate probability that Program A completes in less than 900 seconds?

    \item What is the approximate probability that Program B completes in less than 900 seconds?

    \item What is the approximate probability that Program A completes in less time than Program B?

    \end{enumerate}

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 6
\item Did you know that computers can identify you not only by what you write, but also by how you write? Coursera uses Biometric Keystroke signatures for plagiarism detection. If you cannot write a sentence with the same statistical distribution of key press timings as in your previous work, they assume that you are not the person sitting behind the computer. 

Please refer to the handout for full instructions for the coding parts, (a) and (b).


    \begin{enumerate}[label=\alph*., start=3]
	\item \textbf{[Written]} Use your answers to part (a) and (b) and approximate $X$ and $Y$ as Normal random variables with mean and variance that match their biometric data. Report both distributions.
	\item \textbf{[Written]} Calculate the ratio of the probability that user A wrote the email over the probability that user B wrote the email. You do not need to submit code, but you should include the formula that you attempted to calculate and a short description (a few sentences) of how your code works.

	\end{enumerate}

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 7
\item \textbf{[Coding + Written]} Stanford's HCI class runs a massive online class that was taken by ten thousand students. The class used peer assessment to evaluate students' work. We are going to use their data to learn more about peer graders. In the class, each student has their work evaluated by 5 peers and every student is asked to evaluate 6 assignments: five peers and the ``control assignment'' (the graders were unaware of which assignment was the control). All 10,000 students evaluated the same control assignment, and the scores they gave are in the file \texttt{peerGrades.csv}. You may use simulations to solve any part of this question.

Please refer to the handout for full instructions for the coding parts, (a), (b), and (c).

    \begin{enumerate}[label=\alph*., start=4]
    \item \textbf{[Written]} Would you use the mean or the median of 5 peer grades to assign scores in the online version of Stanford's HCI class? Hint: it might help to visualize the scores. Feel free to write code to help you answer this question, but for this question we'll solely evaluate your written answer in the PDF that you upload to Gradescope.

    \end{enumerate}

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage


% 8
\item \textbf{[Coding + Written] }  In this problem you are going to learn how to use and misuse $p$-values for experiments that are called \emph{A/B tests}. These experiments are ubiquitous. They are a staple of both scientific experiments and user interaction design.

Suppose you are working at Coursera on new ways of teaching a concept in probability. You have two different learning activities \texttt{activity1} and \texttt{activity2} and you want to figure out which activity leads to better learning outcomes. Over a two-week period, you randomly assign each student to be given either \texttt{activity1} or \texttt{activity2}. You then evaluate each student's learning outcomes by asking them to solve a set of problems. 

Please refer to the handout for full instructions for the coding parts, (a) and (b).

Scientific journals have traditionally accepted an experiment's result as ``statistically significant'' if the $p$-value is below 0.05. By definition, this standard means that 5\% of findings published in these journals are in fact not true, but just false positives. The scientific community is beginning to move away from using arbitrary $p$-value thresholds to determine whether a result is publishable. For example, see this 2019 editorial in the journal \emph{Nature}:  \url{https://www.nature.com/articles/d41586-019-00874-8}.

You are now troubled by the $p$-value you obtained in part (b), so you decide to delve deeper. You investigate whether learning outcomes differed based on the background experience of students. The file \texttt{background.csv} stores the background of each student as one of three labels: more experience, average experience, less experience.

    \begin{enumerate}[label=\alph*., start=3]

    \item \textbf{[Written] } For each of the three backgrounds, calculate a difference in means in learning outcome between \texttt{activity1} and \texttt{activity2}, and the $p$-value of that difference.
    
    You'll almost certainly need to write code in this question, and we've provided an \texttt{optional\_function} that you can use, which gets called by our provided main method. However, we won't grade any code for this part. We'll only grade what you include in your PDF.

    \item \textbf{[Written] }Your manager at Coursera is concerned that you have been ``$p$-hacking,'' which is also known as data dredging: \url{https://en.wikipedia.org/wiki/Data_dredging}. In one sentence, explain why your results in part (c) are not the result of $p$-hacking.

    \end{enumerate}

    \begin{shaded}
    \begin{answer}

    \end{answer}
    \end{shaded}
    \newpage



\end{enumerate}


\end{document}
  