\documentclass[11pt]{article} \usepackage{graphics} \usepackage{natbib} \begin{document} \title{ STAT:5400 Midterm 1, 2016} \author{$<$Your Name$>$} \date{$<$date when you took exam$>$} \maketitle \section{ \LaTeX\ } \label{sec:latex} \begin{table}[h] \label{mytab} \begin{center} \begin{tabular}{cc} \hline Name & PDF \\ \hline Gamma & $p(y|\alpha, \beta) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} y ^ {\alpha - 1} exp( - \beta y)$ \\ \hline \end{tabular} \caption{A univariate continuous density} \end{center} \end{table} Table \ref{mytab} is an excerpt from \citet{Cowl13}. \section{R} \begin{enumerate} \item Read the data from the {\tt data.txt} file in the Datasets section of the course web page into a dataframe in R. You may either save the file to disk and read it from there or read it directly from the web site. Then calculate summary statistics of each column and produce the scatterplot. Both outputs are shown below. <>= myobj <- read.table("http://homepage.divms.uiowa.edu/~kcowles/Datasets/data.txt", header = TRUE) summary(myobj) plot( myobj, log = "y") @ \item The volume of a rectangular solid with length $l$, width $w$, and height $h$ is $lwh$. \begin{enumerate} \item Write an R function to calculate the volume of a rectangular solid. It should accept a single argument -- a vector of length 3 containing the length, width, and height. Include the R code that defines your function. <<>>= volume <- function(v) { if(!(is.numeric(v) && is.vector(v) && length(v) ==3)) { print("Invalid input. \n") } else { return( prod(v)) } } @ \item Create a matrix in R with the following entries: \begin{verbatim} 16.5 12.8 4.2 3.1 2.7 8.5 \end{verbatim} Consider the first column as lengths, the second column as widths, and the third column as heights. Write efficient R code to compute the volumes of rectangular solids with dimensions in each row of the matrix. <<>>= m <- matrix( c(16.5, 12.8, 4.2, 3.1, 2.7, 8.5), nrow = 2, byrow = TRUE) apply(m, 1, volume) @ \end{enumerate} \end{enumerate} \bibliographystyle{apalike} \bibliography{mid1} \end{document}