% 302f14Assignment2.tex MGFs and one regression through the origin \documentclass[10pt]{article} %\usepackage{amsbsy} % for \boldsymbol and \pmb \usepackage{graphicx} % To include pdf files! \usepackage{amsmath} \usepackage{amsbsy} \usepackage{amsfonts} \usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=blue, citecolor=blue, urlcolor=blue]{hyperref} % For links \usepackage{fullpage} %\pagestyle{empty} % No page numbers \begin{document} %\enlargethispage*{1000 pt} \begin{center} {\Large \textbf{STA 431s15 Assignment Two}}\footnote{This assignment was prepared by \href{http://www.utstat.toronto.edu/~brunner}{Jerry Brunner}, Department of Statistical Sciences, University of Toronto. It is licensed under a \href{http://creativecommons.org/licenses/by-sa/3.0/deed.en_US} {Creative Commons Attribution - ShareAlike 3.0 Unported License}. Use any part of it as you like and share the result freely. The \LaTeX~source code is available from the course website: \href{http://www.utstat.toronto.edu/~brunner/oldclass/431s15} {\small\texttt{http://www.utstat.toronto.edu/$^\sim$brunner/oldclass/431s15}}} \vspace{1 mm} \end{center} \noindent Question~\ref{SAS} asks you to use SAS. Please bring your log file and your output file to the quiz. There may be questions about them, and you may be asked to hand them in with the quiz. \begin{enumerate} \item For each of the following distributions, derive a general expression for the Maximum Likelihood Estimator (MLE); don't bother with the second derivative test. Then use the data to calculate a numerical estimate; you should bring a calculator to the quiz in case you have to do something like this. \begin{enumerate} \item $p(x)=\theta(1-\theta)^x$ for $x=0,1,\ldots$, where $0<\theta<1$. Data: \texttt{4, 0, 1, 0, 1, 3, 2, 16, 3, 0, 4, 3, 6, 16, 0, 0, 1, 1, 6, 10}. % MLE=MOM= 0.2061856 = 1/(1+xbar) \item $f(x) = \frac{1}{\theta} e^{-x/\theta}$ for $x>0$, where $\theta>0$. Data: \texttt{0.28, 1.72, 0.08, 1.22, 1.86, 0.62, 2.44, 2.48, 2.96} % Exponential, true theta=2, thetahat = xbar MLE=MOM: 1.517778 \item $f(x) = \frac{\alpha}{x^{\alpha+1}}$ for $x>1$, where $\alpha>0$. Data: \texttt{1.37, 2.89, 1.52, 1.77, 1.04, 2.71, 1.19, 1.13, 15.66, 1.43} % % Pareto alpha = 1 (one over uniform) MLE = 1/mean(log(x)) = 1.469102 \item $f(x) = \theta x^{\theta-1}$ for $00$. Data: \texttt{0.04 0.69 0.86 0.24 0.99} % Beta, alpha=theta and beta=1. True theta=1, MLE = -1/mean(log(x)) = 0.965637 \end{enumerate} \item Let $Y_i = \beta x_i + \epsilon_i$ for $i=1, \ldots, n$, where $\epsilon_1, \ldots, \epsilon_n$ are a random sample from a normal distribution with expected value zero and variance $\sigma^2$. The parameters $\beta$ and $\sigma^2$ are unknown constants. The numbers $x_1, \ldots, x_n$ are known, observed constants. \begin{enumerate} \item What is the parameter space $\Theta$? \item Find the Maximum Likelihood Estimator of the pair $(\beta,\sigma^2)$. Show your work. \item Find a Method of Moments estimator of $\beta$ based on $\overline{Y}$. Don't bother estimating $\sigma^2$ by the Method of Moments. Start by calculating $E(\overline{Y})$, which does not equal $E(Y_i)$ for this problem. \item \label{numbers} Based on the small data set below, calculate both your MLE and your Method of Moments estimator for $\beta$. Your answers are numbers. Bring a calculator in case you have to do something like this on the quiz. \begin{verbatim} x 0.0 1.3 3.2 -2.5 -4.6 -1.6 4.5 3.8 y -0.8 -1.3 7.4 -5.2 -6.5 -4.9 9.9 7.2 \end{verbatim} % MLE: 1.8885 and MOM = 1.414634 \end{enumerate} \newpage \item \label{SAS} Before the beginning of the Fall term, students in a first-year Calculus class took a diagnostic test with two parts: Pre-calculus and Calculus. Their High School Calculus marks and their marks in University Calculus were also available. The data are given in the file \href{http://www.utstat.toronto.edu/~brunner/431s15/code_n_data/hw/mathtest.txt}{\texttt{mathtest.txt}}. There is a link on the course web page in case the one in this document does not work. Once you have the raw data file open in a Web browser, you need to save the page to your computer and drag it to the \texttt{myfolders} sub-folder in your shared folder --- that is, to the folder that is shared between your computer and the virtual \texttt{linux} machine on which SAS is installed. Exactly how you save a web page to your computer depends on your Web browser. \begin{itemize} \item In Firefox, choose \texttt{Save Page As} from the \texttt{File} menu. \item In Chrome, click on the wrench icon in the upper right corner, and choose \texttt{Save Page As}. \item In Safari, choose \texttt{Save As \ldots} from the \texttt{File} menu, and then under \texttt{Format}, choose \texttt{Page Source}. \end{itemize} In order, the variables in the data file are: Identification code, Mark in High School Calculus, Score on the Pre-calculus portion of the diagnostic test, Score on the Calculus portion of the diagnostic test, and mark in University Calculus. Using SAS \texttt{proc means}, calculate means and standard deviations for all the variables (except Identification code). That's it. Some other numbers will be generated by default as well; know what they are. Bring your log file and output file to the quiz. You may be asked for numbers from your printouts, and you may be asked to hand them in. For full marks, \textbf{there must be no warnings, error messages or notes about missing data on your log file.} Please follow these guidelines. Marks will be deducted if you do not. \begin{itemize} \item Put your name and student number in a \texttt{title} or \texttt{title2} statement. \item Do not write anything on the printouts except your name and student number. The other questions are just practice for the quiz, and are not to be handed in. \item Bring your log file to the quiz, \emph{not} just a listing of the program file. \item The log file and the output file must be from the same run of SAS. \item Your output file must have a time and date stamp. This is automatically generated if you save a pdf file or print from SAS Studio. \item You must use \emph{your} installation of SAS, not the installation on someone else's computer. \end{itemize} % On Mac using Safari, Under File, Save as and under Format, choose Page Source % using Firefox, Under File, Save File as % using Chrome, Under File, Save File as \end{enumerate} \end{document} Check data with R > rbind(x,y) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] x 0.0 1.3 3.2 -2.5 -4.6 -1.6 4.5 3.8 y -0.8 -1.3 7.4 -5.2 -6.5 -4.9 9.9 7.2 > summary(lm(y ~ -1+x)) Call: lm(formula = y ~ -1 + x) Residuals: Min 1Q Median 3Q Max -3.7550 -1.0696 -0.2275 1.3680 2.1871 Coefficients: Estimate Std. Error t value Pr(>|t|) x 1.8885 0.2248 8.402 6.66e-05 *** /*************** Hw2.sas *********************/ title 'STA431s15 Assignment 2: First SAS assignment'; title2 'Jerry, Student number 0000000000'; data math; infile '/folders/myfolders/431s15/mathtest.data'; input id HS_Calculus Precalculus_Score Calculus_Score University_Calculus; proc means; var HS_Calculus Precalculus_Score Calculus_Score University_Calculus;