\documentclass[11pt]{article} \usepackage{amsgen,amsmath,amstext,amsbsy,amsopn,amssymb} %\usepackage[dvips]{graphicx,color} \usepackage{graphicx,color,xcolor,listings} \usepackage{listings} \usepackage{epstopdf} \usepackage{wrapfig,color,bm} \usepackage{epsfig} \usepackage{multirow} \usepackage{enumerate} \usepackage[hidelinks]{hyperref} \usepackage{setspace} \usepackage{bbm} \usepackage{makecell} \usepackage{booktabs} \usepackage{setspace} \usepackage{geometry} \usepackage{indentfirst} %Ê׸ö¶ÎÂäËõ½ø \oddsidemargin .15truein \parskip .05in \renewcommand{\baselinestretch}{1.3} % double spaced \geometry{left=2.18cm,right=2.18cm,top=1.54cm,bottom=2.54cm} %\input def.tex \def\npg{\vfill\eject} \def\pg{\hfill\break} \def\pgl{\hfill\break} \def\pgi{\hfill\break \indent} \def\pgii{\hfill\break \indent} \def\sqr#1#2{{\vcenter{\vbox{\hrule height.#2pt \hbox{\vrule width.#2pt height#1pt \kern#1pt \vrule width.#2pt} \hrule height.#2pt}}}} \def\bar{\overline} \def\bfs{{\hbox{\bf s}}} \def\bfS{{\hbox{\bf S}}} \def\bfx{{\hbox{\bf x}}} \def\bfy{{\hbox{\bf y}}} \def\bft{{\hbox{\bf t}}} \def\bfr{{\hbox{\bf r}}} \def\bfh{{\hbox{\bf h}}} \def\bff{{\hbox{\bf f}}} \def\bfg{{\hbox{\bf g}}} \def\bfc{{\hbox{\bf c}}} \def\bfc{{\hbox{\bf c}}} \def\bfc{{\hbox{\bf c}}} \def\bfd{{\hbox{\bf d}}} \def\bfz{{\hbox{\bf z}}} \def\bfv{{\hbox{\bf v}}} \def\bfu{{\hbox{\bf u}}} \def\bfw{{\hbox{\bf w}}} \def\bfm{{\hbox{\bf m}}} \def\bfp{{\hbox{\bf p}}} \def\bfa{{\hbox{\bf a}}} \def\bfb{{\hbox{\bf b}}} \def\bfq{{\hbox{\bf q}}} \def\bfO{{\hbox{\bf O}}} \def\bfQ{{\hbox{\bf Q}}} \def\bfC{{\hbox{\bf C}}} \def\bfw{{\hbox{\bf w}}} \def\bfe{{\hbox{\bf e}}} \def\bfT{{\hbox{\bf T}}} \def\bfW{{\hbox{\bf W}}} \def\bfV{{\hbox{\bf V}}} \def\bfM{{\hbox{\bf M}}} \def\bfL{{\hbox{\bf L}}} \def\bfl{{\hbox{\bf l}}} \def\bfR{{\hbox{\bf R}}} \def\bfU{{\hbox{\bf U}}} \def\bfN{{\hbox{\bf N}}} \def\bfX{{\hbox{\bf X}}} \def\bfK{{\hbox{\bf K}}} \def\bfY{{\hbox{\bf Y}}} \def\bfZ{{\hbox{\bf Z}}} \def\bfB{{\hbox{\bf B}}} \def\bfF{{\hbox{\bf F}}} \def\0{{\hbox{\bf 0}}} \def\cZ{{\cal Z}} \def\A{{{\cal A}}} \def\K{{{\cal K}}} \def\a{{{\alpha}}} \def\b{{{\beta}}} \def\ta{{{\tilde \alpha}}} \def\tb{{{\tilde \beta}}} \def\ka{{{\kappa}}} \def\cR{{\cal R}} \def\am{{\rm argmax}} \def\an{{\rm argmin}} \def\cA{{\cal A}} \def\cP{{\cal P}} \def\cX{{\cal X}} \def\cL{{\cal L}} \def\E{{\cal E}} \def\F{{\cal F}} \def\D{{\cal D}} \def\H{{\cal H}} \def\B{{\cal B}} \def\Q{{\cal Q}} \def\T{{\cal T}} \def\s{{\cal S}} \def\I{{\cal I}} \def\J{{\cal J}} \def\N{{\cal N}} \def\M{{\cal M}} \def\C{{\cal C}} \def\G{{\cal G}} \def\O{{\cal O}} \def\bfo{{\bf o}} \def\cU{{\cal U}} \def\ce{{\cal e}} \def\cE{{\cal E}} \def\V{{\cal V}} \def\W{{\cal W}} \def\TD{{\bigtriangledown}} \def\sign{{\rm sign}} \def\1{\hbox{\bf 1}} \def\2{\hbox{\bf 2}} \def\3{\hbox{\bf 3}} \def\4{\hbox{\bf 4}} \def\5{\hbox{\bf 5}} \def\6{\hbox{\bf 6}} \def\d{{\partial}} \def\lims{\mathop {\vphantom {\underline{}}\overline {\rm lim}} \limits _ {\a \to \infty}} \def\liminf{\mathop{\underline {\rm lim}} \limits _ {n \to \infty}} \def\limsup{\mathop{\overline {\rm lim}} \limits _ {n \to \infty}} \def\limn{\mathop{{\rm lim}} \limits _ {n \to \infty}} \def\limi{\mathop{\underline {\rm lim}} \limits _ {\a \to \infty}} \def\limu{\mathop{\underline {\rm lim}} \limits _ {u \downarrow 0}} \def\P{{\rm P}} \def\ln{{\rm ln}} \def\pg{\hfill\break} \def\square{\mathchoice\sqr34\sqr34\sqr{2.1}3\sqr{1.4}3} \def\pmb#1{\setbox0=\hbox{#1}% \kern-.025em\copy0\kern-\wd0 \kern.05em\copy0\kern-\wd0 \kern-.025em\raise.0433em\box0} \def\refhg{\hangindent=20pt\hangafter=1} \def\refmark{\par\vskip 2mm\noindent\refhg} \def\npg{\vfill\eject} \def\pg{\hfill\break} \def\pgl{\hfill\break} \def\pgi{\hfill\break \indent} \def\pgii{\hfill\break \indent} \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} \definecolor{backcolour}{rgb}{0.95,0.95,0.92} \lstdefinestyle{mystyle}{ backgroundcolor=\color{white}, commentstyle=\color{codegreen}, keywordstyle=\color{blue}, numberstyle=\tiny\color{codegray}, stringstyle=\color{red}, basicstyle=\footnotesize, breakatwhitespace=false, breaklines=true, captionpos=b, keepspaces=true, numbers=left, numbersep=5pt, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2 } \lstdefinestyle{nonum}{ backgroundcolor=\color{backcolour}, basicstyle=\footnotesize, breakatwhitespace=false, breaklines=true, captionpos=b, keepspaces=true, numbers=none, numbersep=5pt, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2, moredelim=**[is][\bf\color{red}]{@}{@}, %http://tex.stackexchange.com/questions/115547/textcolor-within-lstlisting } \definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue \definecolor{mylilas}{RGB}{170,55,241} \lstdefinestyle{matlab}{language=Matlab,% %basicstyle=\color{red}, breaklines=true,% morekeywords={matlab2tikz}, keywordstyle=\color{blue},% morekeywords=[2]{1}, keywordstyle=[2]{\color{black}}, identifierstyle=\color{black},% stringstyle=\color{mylilas}, commentstyle=\color{mygreen},% showstringspaces=false,%without this there will be a symbol in the places where there is a space numbers=left,% numberstyle={\tiny \color{black}},% size of the numbers numbersep=9pt, % this defines how far the numbers are from the text emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise %emph=[2]{word1,word2}, emphstyle=[2]{style}, %http://tex.stackexchange.com/questions/75116/what-can-i-use-to-typeset-matlab-code-in-my-document } \lstset{language=R,style=mystyle,basicstyle=\ttfamily,columns=fullflexible,keepspaces=true,lineskip={-1.5pt},} \begin{document} \begin{spacing}{2.2} \centerline{\Large \textbf{ MATH 534} \qquad \qquad \qquad \Large \textbf{Homework 1} \qquad \qquad \qquad \Large \textbf{Q.Q. Yu} } \end{spacing} \noindent \boxed{\textbf{\textit{Ex.} 1}. } \textbf{ 1. Go over the commands listed in Chapters 1 and 2 of the textbook. % Or pages 1-12 of Prof. Xu's lecture note. } \textbf{ 2. Submit your commands and their outputs in a file, say file1, if some outputs are graphs, create another file, say file2.tex, indicate in your corresponding paragraphs where are those graphs (e.g., see Figure 4 etc.) and submit file2.pdf. } \noindent{\bf Sol.} fisher.test. Fisher's Exact Test for Count Data Performs a Fisher's exact test on a two-dimensional contingency table. Suppose we select $c_1$ and $c_2$ from the population of all individuals having attribute $B$ and $B^c$ (not $B$), respectively, and observe the numbers $N_{11}$ and $N_{12}$ of type $A$ individuals in the 1st and 2nd samples, respectively. The contingency table giving the classification according to types $AB$, $AB^c$, $A^cB$ and $A^cB^c$. $N_{11}$ and $N_{12}$ are independent bin$(c_i,p_i)$. $$\sum_{s \le q_1}{{c_1 \choose s}{c_2\choose r_1-s} \over {n \choose r_1}} \hbox{ and } \sum_{s \ge q_2}{{c_1 \choose s}{c_2\choose r_1-s} \over {n \choose r_1}} \eqno(2) $$ each as close to $\alpha/2$ as possible, but not larger. %\bye \begin{lstlisting}[frame=bt] > ph <- rep(c(-1, 1), 4) > ni <- rep(c(-1, 1), each = 2, length = 8) > ca <- rep(c(-1, 1), each = 4, length = 8) > y1 <- c(0.312, 0.391, 0.412, 0.376, 0.479, 0.481, 0.465, 0.451) > y2 <- c(0.448, 0.242, 0.434, 0.251, 0.639, 0.583, 0.657, 0.768) > y3 <- c(0.576, 0.309, 0.280, 0.201, 0.656, 0.631, 0.736, 0.814) > y4 <- c(0.326, 0.323, 0.481, 0.312, 0.679, 0.648, 0.680, 0.799) > eff <- t(model.matrix(y1 ~ ph * ni * ca)[, -1]) %*% cbind(y1, y2, y3, y4) > (se_eff <- sqrt(0.003821 * (1/4 + 1/4))) [1] 0.04370927 (*1.96=0.086) \end{lstlisting} \begin{table}[h] \centering \caption{Main effect and interaction for responses} \setlength{\abovecaptionskip}{1cm} \setlength{\belowcaptionskip}{1cm} \begin{tabular}{lccccccc} \toprule &$y_1$ & & &$y_2$&$y_3$&$y_4$\\ \midrule ph&0.008& & &$-$0.083&$-$0.073&$-$0.021\\ ni&0.010& & &0.050&$-$0.035&0.074\\ ca&0.096$^{\ast}$& & &0.318$^{\ast}$&0.368$^{\ast}$&0.341$^{\ast}$\\ ph:ni& $-$0.033& & &0.047&0.073&$-$0.004\\ ph:ca&$-$0.014& & &0.111$^{\ast}$&0.100$^{\ast}$&0.065\\ ni:ca&$-$0.032& & &0.052&0.167$^{\ast}$&0.002\\ ph:ni:ca&0.025& & &0.036&$-$0.021&0.079\\ \bottomrule \end{tabular} \end{table} \noindent {\bf Ex. 2.} mantelhaen.test. (Mantel-Haenszel Chi-Square Test for Count Data). % Performs a Mantel-Haenszel chi-square test on a three-dimensional contingency table. Suppose that we have a sequence of $2 \times 2$ tables, say, $ \begin{matrix} & D & A & \\ treatment~1 & a_1 & * & n_{11}\\ treatment~2 & * & * & n_{12}\\ & m_{11} & m_{12} & n_1 \\ \end{matrix}, \cdots, \begin{matrix} & D & A & \\ treatment~1 & a_k & * & n_{k1}\\ treatment~2 & * & * & n_{k2}\\ & m_{k1} & m_{k2} & n_k \\ \end{matrix} $ $H_o$: $p_{11}=p_{12}$, ..., $p_{k1}=p_{k2}$, where $p_{i1}=P(D|$treatment 1, ith term) and $p_{i2}=P(D|$treatment 2, ith term). \begin{align*} MH=&{\sum_{i=1}^k(a_i-E_0(a_i)) \over \sqrt{\sum_{i=1}^k Var_0(a_i)}} & MH^2 \sim & \chi^2(1),& \alpha, \beta, \delta, \gamma, \Gamma, \psi, \phi, \Phi, \xi, \cr \prod_{i=1}^n \cdots =& .... & (3) \end{align*} The following 3 figure are created by the program splus.ch0 included. \vskip 2.9in \begin{figure}[h] \centering \setlength{\abovecaptionskip}{0.5cm} \setlength{\belowcaptionskip}{-0.2cm} \includegraphics[scale = 0.85]{ch1.eps}\\ \caption{\bf . Outputs from R} \end{figure} The figure on the left is a plot of $(X_i,Y_i)$. It suggests that $(X,Y)$ has quite a strong linear relation. The figure in the middle is a plot of residuals verse $X$. It suggests that the variance of the error terms are constant. The figure on the right is the qqplot of the error distribution and the normal distribution. The strong linear form suggests that the error distribution probably is normal. \vskip 1.7in \begin{figure}[h] \centering \setlength{\abovecaptionskip}{0.5cm} \setlength{\belowcaptionskip}{-0.2cm} \includegraphics[scale = 0.5]{ch1.eps}\\ \caption{\bf Small size of Figure 1} \end{figure} \end{document}