\documentclass[12pt]{amsart}
\theoremstyle{plain}    
\newtheorem*{definition}{Definition}
\newtheorem*{example}{Example}
\newtheorem*{exercise}{Exercise}
\newtheorem*{conjecture}{Conjecture}
\newtheorem*{theorem}{Theorem}
\newtheorem*{lemma}{Lemma}
\newtheorem*{remark}{Remark}
\begin{document} 
\title{Written Assignment 6}
\section{Written Assignment 6}  
\subsection{Problem 1}
\par\vspace{0.3 cm}
A random variable defined on $(1,3)$ has the probability density function (PDF)
\[
f(x) = \frac{k}{x}\quad 1<x<3
\]
where $k$ is a constant.  
\par\vspace{0.3 cm}\noindent
a) What is the value of $k$?
\par\vspace{0.3 cm}\noindent
b) What is the cumulative distribution function (CDF) $F(x)$ for this probability distribution?
\par\vspace{0.3 cm}\noindent
c) What is the expected value of this random variable $E(X)$?
\par\vspace{0.3 cm}\noindent
d) What is the variance of this random variable $V(X)$?
\par\vspace{0.3 cm}\noindent
\subsection{Problem 2}
The $p^{th}$ percentile $\phi_p$ of a distribution has the property that
\[
F(\phi_p)=P(X\le\phi_p) = p
\]
so that 
\[
\phi_p = F^{-1}(p)
\]
where $F^{-1}$ is the function inverse of the CDF of $X$ and $0\leq p\leq1$.
\par\vspace{0.3 cm}\noindent
a) For the distribution in problem 1, what is $F^{-1}(x)$?
\par\vspace{0.3 cm}\noindent
b) When $p=.5$, $\phi_p$ is called the \textbf{median} of the distribution.  What is the median of the distribution in problem 1?
\par\vspace{0.3 cm}\noindent
c) When $p=.25$, $\phi_p$ is called the \textbf{first quartile} of the distribution.  What is the first quartile of the distribution in problem 1?
\par\vspace{0.3 cm}\noindent
d) The quantity $\phi_{75}-\phi_{25}$ is called the \textbf{interquartile range} of the distribution.  What is the interquartile range of the distribution in problem 1?
\subsection{Problem 3}
Suppose $X$ is a continuous random variable having density function $f(x)$ with support on the interval $[c,d]$, and $a$ and $b$ are constants. 
\par\vspace{0.3 cm}\noindent
a) Show that 
\[
E(aX+b) = aE(X)+b
\]
\par\vspace{0.3 cm}\noindent
b) Show that
\[
V(X+b) =  V(X)
\] 
\par\vspace{0.3 cm}\noindent
c) Show that
\[
V(aX+b) =  a^2V(X)
\] 
\subsection{Problem 4}
\par\vspace{0.3 cm}
Techniques that use a computer to simulate the behavior of random variables are called \textbf{Monte Carlo} methods.
\par\vspace{0.3 cm}\noindent
Most statistical software packages have routines for generating a vector of values that simulate independent observations from a uniform distribution on $(0,1)$.  In R, the command  \texttt{runif(10000)} generates such an array with 10,000 elements.
\par\vspace{0.3 cm}\noindent
R has routines to generate all of the common probability distributions (\texttt{rbinom} for binomial, \texttt{rnorm} for normal, \texttt{rexp} for exponential).  If you want to produce simulated data for a continuous probability distribution with CDF $F(x)$, you can use
\[
F^{-1}(u)
\]
where $u$ has a uniform (0,1) distribution. 
\par\vspace{0.3 cm}\noindent
It is particularly easy to do this in R because R allows you to supply arrays as arguments to functions the same way you supply scalars, so if you want an array \texttt{x} containing 10,000 values of $\ln(u)$ corresponding to the natural logs of independent uniform random variables, you only need one line of code:
\par\vspace{0.3 cm}\noindent
\texttt{x=log(runif(10000)))}
\par\vspace{0.3 cm}\noindent
Use R to simulate 10,000 observations from the distribution in problem 1 (just replace \texttt{log()} in the previous expression with the appropriate CDF inverse).  You can access the online reference manual for R by entering \texttt{help.start()}.  Most of the functions we will be using in this course are in the \textbf{stats} package, which you can find under the \textbf{packages} link.  For help with a specific function like \texttt{mean}, type \texttt{?mean}.  You can use the command \texttt{hist(x)} to display a histogram of the sample.
\par\vspace{0.3 cm}\noindent 
a) Use the command \texttt{mean(x)} to get the mean of the simulated sample.  What is the difference between this value and your answer to 1c?
\par\vspace{0.3 cm}\noindent
b)  Use the command \texttt{var(x)} to get the variance of the simulated sample.  What is the difference between this value and your answer to 1d?
\par\vspace{0.3 cm}\noindent 
c) Use the command \texttt{median(x)} to get the median of the simulated sample.  What is the difference between this value and your answer to 2b?
\par\vspace{0.3 cm}\noindent
d)  Use the \texttt{quantile} command to get the $25^{th}$ and $75^{th}$ percentiles and the interquartile range for the sample.  What is the difference between this value and your answer to 2d?
\end{document}



