\documentclass{amsart}

\newcommand{\thisCourse}{STAT 225: Linear Models}
\usepackage{fHomework}




%%%%%%
% Change these as needed:

\author{Ole J. Forsberg}
\title{Assignment 0}
\date{April 1, 2021}









\begin{document}
\maketitle


%%%
% Start your assignment work here










\problem{1}
We would like to calculate the mean and variance of a $\GAMMA(\alpha,\beta)$ distribution.


\subproblem{a}
\begin{align*}
\E{X} &= \int_{\Omega} x\ f(x) \dx \\
    &= \int_0^{\infty} x\ \frac{1}{\Gamma(\alpha) \beta^{\alpha}} x^{\alpha - 1} \e^{-x/\beta} \dx \\
    &= \int_0^{\infty} \frac{1}{\Gamma(\alpha) \beta^{\alpha}} x^{(\alpha +1) - 1} \e^{-x/\beta} \dx \\
    &= \int_0^{\infty} \frac{\alpha \beta}{\Gamma(\alpha+1) \beta^{(\alpha+1)}} x^{(\alpha +1) - 1} \e^{-x/\beta} \dx \\
    &= \alpha \beta \int_0^{\infty} \frac{1}{\Gamma(\alpha+1) \beta^{(\alpha+1)}} x^{(\alpha +1) - 1} \e^{-x/\beta} \dx \\
    &= \alpha \beta
\end{align*}
Thus, we have shown that $\E{X} = \alpha \beta$.




\clearpage
\problem{2}
Please refer to Figure~\ref{fig:lnd} for the results. Note that the vote proportion fits the logit-Normal distribution quite well. The Kolmogorov-Smirnov test indicates a very slight deviation (K=0.96).




\clearpage

\section*{Appendix: Tables and Figures}

\vspace{3em}


\begin{figure}[h]\centering
\includegraphics[width=0.8\textwidth]{mccainBYlogitnormal.png}
 \caption{A plot of voter support in the 2008 US presidential election, as fit using a logit-Normal distribution.}
 \label{fig:lnd}
\end{figure}

\clearpage


% Note: One figure per page



\clearpage

\section*{Appendix: Code}
\noindent
The following is the code used in this assignment.


\begin{codein}
#####  Script for 2004 Austrian Election

##### Preamble

# Load functionality
source("http://rur.kvasaheim.com/rur.R") #runs that source
library(lawstat)
library(lmtest)

# Load data
dt = read.csv("Austria2004.csv")
attach(dt)

# Define variables
dt$Valid       = Votes-Invalid
invalidrate    = Invalid/Votes
supportFischer = CandVotes/dt$Valid
invalidation   = cbind(Invalid,dt$Valid)


##### Model the invalidation rate
mod = glm(invalidation ~ supportFischer^2, family=quasibinomial(link=logit))


##### Check results
summary(mod)

\end{codein}








% Keep this last line
\end{document}
%%%
