\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
% maxwidth is the original width if it is less than linewidth
% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\let\hlipl\hlkwb

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}

\title{\textbf{Final Assessment \\ Module Name:} Statistics and Operational Research \\ \textbf{Module Code:} MTH60904 \\ \textbf{Duration:} 24 Hours \\ \textbf{Date/Time:} 10/12/20 08:00AM \\ - 11/12/20 08:00AM}
\author{\textbf{Student Name:} Richelle Tan Wei Qi \\ \textbf{Student ID:} 0328371}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\maketitle{}

\newpage
\begin{flushleft}
\textbf{Used Libraries for entire RNW}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{library}\hlstd{(datasets)}
\hlkwd{library}\hlstd{(e1071)}
\hlkwd{library}\hlstd{(corrplot)}
\hlkwd{library}\hlstd{(funModeling)}
\hlkwd{library}\hlstd{(tidyverse)}
\hlkwd{library}\hlstd{(Hmisc)}
\hlkwd{library}\hlstd{(ggplot2)}
\end{alltt}
\end{kframe}
\end{knitrout}

\section{Question 1}
\subsection{Adding/Loading ChickWeight Dataset and viewing Data}
\begin{flushleft}
Using the ChickWeight dataset that is made available from adding the 'datasets' library:
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{data}\hlstd{(ChickWeight)}
\hlkwd{head}\hlstd{(ChickWeight)}
\end{alltt}
\begin{verbatim}
##   weight Time Chick Diet
## 1     42    0     1    1
## 2     51    2     1    1
## 3     59    4     1    1
## 4     64    6     1    1
## 5     76    8     1    1
## 6     93   10     1    1
\end{verbatim}
\end{kframe}
\end{knitrout}

\begin{flushleft}
Renaming ChickWeight to cwData for code read-ability:
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{cwData} \hlkwb{<-} \hlstd{ChickWeight}
\end{alltt}
\end{kframe}
\end{knitrout}

\subsection{Specifying variables in Dataset}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{names}\hlstd{(cwData)}
\end{alltt}
\begin{verbatim}
## [1] "weight" "Time"   "Chick"  "Diet"
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
\textbf{Conclusion:} \\ There are 4 variables in the ChickWeight dataset.
\end{flushleft}

\newpage
\subsection{Dimension of the ChickWeight data}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{nrow}\hlstd{(cwData)}
\end{alltt}
\begin{verbatim}
## [1] 578
\end{verbatim}
\begin{alltt}
\hlkwd{ncol}\hlstd{(cwData)}
\end{alltt}
\begin{verbatim}
## [1] 4
\end{verbatim}
\begin{alltt}
\hlkwd{length}\hlstd{(cwData)}
\end{alltt}
\begin{verbatim}
## [1] 4
\end{verbatim}
\begin{alltt}
\hlkwd{dim}\hlstd{(cwData)}
\end{alltt}
\begin{verbatim}
## [1] 578   4
\end{verbatim}
\end{kframe}
\end{knitrout}

\subsection{Identifying type of data variables in columns}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{str}\hlstd{(cwData)}
\end{alltt}
\begin{verbatim}
## Classes 'nfnGroupedData', 'nfGroupedData', 'groupedData' and 'data.frame':	578 obs. of  4 variables:
##  $ weight: num  42 51 59 64 76 93 106 125 149 171 ...
##  $ Time  : num  0 2 4 6 8 10 12 14 16 18 ...
##  $ Chick : Ord.factor w/ 50 levels "18"<"16"<"15"<..: 15 15 15 15 15 15 15 15 15 15 ...
##  $ Diet  : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
##  - attr(*, "formula")=Class 'formula'  language weight ~ Time | Chick
##   .. ..- attr(*, ".Environment")=<environment: R_EmptyEnv>
##  - attr(*, "outer")=Class 'formula'  language ~Diet
##   .. ..- attr(*, ".Environment")=<environment: R_EmptyEnv>
##  - attr(*, "labels")=List of 2
##   ..$ x: chr "Time"
##   ..$ y: chr "Body weight"
##  - attr(*, "units")=List of 2
##   ..$ x: chr "(days)"
##   ..$ y: chr "(gm)"
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
\textbf{Conclusion:} \\
Based on the output, the data type for the Weight column is \textbf{Numeric}. \\
The data type for the Time column is also \textbf{Numeric}. \\
The data type for the Chick column is \textbf{Ordered Factors}. \\
The data type for the Diet column is \textbf{Factors}.
\end{flushleft}

\newpage
\subsection{Frequency Distribution Table}
\begin{flushleft}
\begin{tabular}{|c|c|}
\hline
Weight Class & Number of Chicks in Weight Class\\
\hline
0 to 50 & 103\\
\hline
51 to 100 & 193\\
\hline
101 to 150 & 122 \\
\hline
151 to 200 & 94\\
\hline
201 to 250 & 47\\
\hline
251 to 300 & 23\\
\hline
301 to 350 & 12\\
\hline
351 to 400 & 2\\
\hline
\end{tabular}
\end{flushleft}

\begin{flushleft}
Below is a Histogram created to show the Weight distribution of above table.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(cwData}\hlopt{$}\hlstd{weight,} \hlkwc{xlab}\hlstd{=}\hlstr{"Chick Weight"}\hlstd{,} \hlkwc{main}\hlstd{=}\hlstr{"Distribution of Chick Weight"}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-7-1}

\end{knitrout}

\subsection{Measures of central tendency}
\begin{flushleft}
The measures of central tendency includes the mean, median, and mode.
\end{flushleft}
\begin{flushleft}
Below is the mean calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1] 121.8183
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1] 10.71799
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Chick))}
\end{alltt}
\begin{verbatim}
## [1] 26.25952
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 2.235294
\end{verbatim}
\end{kframe}
\end{knitrout}

\begin{flushleft}
Below is the median calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1] 103
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1] 10
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Chick))}
\end{alltt}
\begin{verbatim}
## [1] 26
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 2
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Since R does not have a built-in Mode() function. I created a function to calculate mode.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{my_mode} \hlkwb{<-} \hlkwa{function}\hlstd{(}\hlkwc{x}\hlstd{) \{}
  \hlstd{unique_x} \hlkwb{<-} \hlkwd{unique}\hlstd{(x)}
  \hlstd{tabulate_x} \hlkwb{<-} \hlkwd{tabulate}\hlstd{(}\hlkwd{match}\hlstd{(x, unique_x))}
  \hlstd{unique_x[tabulate_x} \hlopt{==} \hlkwd{max}\hlstd{(tabulate_x)]}
\hlstd{\}}
\end{alltt}
\end{kframe}
\end{knitrout}
\begin{flushleft}
Below is the mode calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1] 41
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1] 0 2
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 1
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\subsection{Measures of dispersion}
\begin{flushleft}
Measure of Dispersion includes the range, interquartile range, and standard deviation.
\end{flushleft}
\begin{flushleft}
Below is the range calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1]  35 373
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1]  0 21
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Chick))}
\end{alltt}
\begin{verbatim}
## [1]  1 50
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 1 4
\end{verbatim}
\end{kframe}
\end{knitrout}

\begin{flushleft}
Below is the interquartile range calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1] 100.75
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1] 12
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Chick))}
\end{alltt}
\begin{verbatim}
## [1] 24
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 2
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Below is the standard deviation calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1] 71.07196
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1] 6.7584
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Chick))}
\end{alltt}
\begin{verbatim}
## [1] 13.99685
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 1.162678
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\subsection{Skewness of ChickWeight data features}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(cwData}\hlopt{$}\hlstd{weight)}
\end{alltt}
\begin{verbatim}
## [1] 0.9587845
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
The results from the Weight variable returns the value 0.9, which is between 0.5 and 1, which indicates that the data distribution positively skewed and is right-skewed.
\end{flushleft}

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(cwData}\hlopt{$}\hlstd{Time)}
\end{alltt}
\begin{verbatim}
## [1] -0.01748132
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
The results from the Time variable returns the value -0.02 , which is between -0.5 and 0.5, which indicates that the data distribution is relatively symmetrical.
\end{flushleft}

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Chick))}
\end{alltt}
\begin{verbatim}
## [1] -0.001512881
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
The results from the Chick variable returns the value -0.002, which is between -0.5 and 0.5, which indicates that the data distribution is relatively symmetrical.
\end{flushleft}

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\end{alltt}
\begin{verbatim}
## [1] 0.3146888
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
The results from the Diet variable returns the value 0.3, which is between 0.5 and 1, which indicates that the data distribution positively skewed and is right-skewed.
\end{flushleft}

\newpage
\subsection{Correlations for each pair of attributes}
\begin{flushleft}
\textbf{Correlation between Weight and Time.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(cwData}\hlopt{$}\hlstd{weight,cwData}\hlopt{$}\hlstd{Time,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.8371017
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(cwData}\hlopt{$}\hlstd{weight,cwData}\hlopt{$}\hlstd{Time,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.902218
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(cwData}\hlopt{$}\hlstd{weight,cwData}\hlopt{$}\hlstd{Time,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.7741044
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above tests, we can see that the values from all 3 tests is between 0.7 and 0.9, which indicates that the weight of a chick has a strong postive linear relationship with the time of growth. \\
\end{flushleft}

\begin{flushleft}
\textbf{Correlation between Weight and Diet.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{Diet} \hlkwb{<-} \hlstd{(}\hlkwd{as.numeric}\hlstd{(cwData}\hlopt{$}\hlstd{Diet))}
\hlkwd{cor}\hlstd{(cwData}\hlopt{$}\hlstd{weight,Diet,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.2081957
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(cwData}\hlopt{$}\hlstd{weight,Diet,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.2002885
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(cwData}\hlopt{$}\hlstd{weight,Diet,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.1500202
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above tests, we can see that the values from all 3 tests is between 0.1 and 0.2, which indicates that the weight of a chick has a very weak positive linear relationship with the diet.
\end{flushleft}

\newpage
\subsection{Visualize the ChickWeight data variables}
\begin{flushleft}
A box plot is created to show the relationship between the chicks' diets and corresponding weights. \\
\end{flushleft}
\begin{flushleft}
From the below Box Plot, we can tell that the most chicks with a higher number for weight is fed diet number3.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{boxplot}\hlstd{(cwData}\hlopt{$}\hlstd{weight} \hlopt{~} \hlstd{cwData}\hlopt{$}\hlstd{Diet,} \hlkwc{xlab} \hlstd{=} \hlstr{"Chick Diet"}\hlstd{,} \hlkwc{ylab}\hlstd{=}\hlstr{"Chick Weight"}\hlstd{,} \hlkwc{main} \hlstd{=} \hlstr{"Boxplots of Chick Weight by Diet"}\hlstd{,}\hlkwc{col}\hlstd{=}\hlkwd{c}\hlstd{(}\hlnum{5}\hlstd{,}\hlnum{4}\hlstd{,}\hlnum{3}\hlstd{,}\hlnum{2}\hlstd{))}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-42-1}

\end{knitrout}

\newpage
\begin{flushleft}
To visualize the relationship between Time and Weight.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{plot}\hlstd{(cwData}\hlopt{$}\hlstd{Time,cwData}\hlopt{$}\hlstd{weight,}\hlkwc{xlab} \hlstd{=} \hlstr{'time'}\hlstd{,}\hlkwc{ylab} \hlstd{=} \hlstr{'weight'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-43-1}

\end{knitrout}

\newpage
\begin{flushleft}
To visualize the relationship between Age (in terms of Days) and Weight.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{plot} \hlstd{(cwData}\hlopt{$}\hlstd{Time , cwData}\hlopt{$}\hlstd{weight ,}
\hlkwc{ylab} \hlstd{=}\hlstr{"Weight (g)"}\hlstd{,} \hlkwc{xlab} \hlstd{=}\hlstr{"Age ( days )"}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-44-1}

\end{knitrout}

\newpage
\begin{flushleft}
To visualize the relationship between Weight and the weight of chicks in the same diet class.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{plot}\hlstd{(cwData}\hlopt{$}\hlstd{weight}\hlopt{~}\hlstd{cwData}\hlopt{$}\hlstd{Chick,}\hlkwc{xlab} \hlstd{=} \hlstr{'ordered label by weight within the same diet'}\hlstd{,}\hlkwc{ylab} \hlstd{=} \hlstr{'weight'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-45-1}

\end{knitrout}

\newpage
\begin{flushleft}
To visualize the relationship between Weight and the weight of chicks in diet number1.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(cwData}\hlopt{$}\hlstd{weight[cwData}\hlopt{$}\hlstd{Diet}\hlopt{==}\hlstr{'1'}\hlstd{],}\hlkwc{breaks} \hlstd{=} \hlnum{30}\hlstd{,}\hlkwc{main} \hlstd{=} \hlstr{'Histogram: Weight for Diet 1'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-46-1}

\end{knitrout}
\newpage
\begin{flushleft}
To visualize the relationship between Weight and the weight of chicks in diet number2.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(cwData}\hlopt{$}\hlstd{weight[cwData}\hlopt{$}\hlstd{Diet}\hlopt{==}\hlstr{'2'}\hlstd{],}\hlkwc{breaks} \hlstd{=} \hlnum{30}\hlstd{,}\hlkwc{main} \hlstd{=} \hlstr{'Histogram: Weight for Diet 2'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-47-1}

\end{knitrout}
\newpage
\begin{flushleft}
To visualize the relationship between Weight and the weight of chicks in diet number3.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(cwData}\hlopt{$}\hlstd{weight[cwData}\hlopt{$}\hlstd{Diet}\hlopt{==}\hlstr{'3'}\hlstd{],}\hlkwc{breaks} \hlstd{=} \hlnum{30}\hlstd{,}\hlkwc{main} \hlstd{=} \hlstr{'Histogram: Weight for Diet 3'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-48-1}

\end{knitrout}
\newpage
\begin{flushleft}
To visualize the relationship between Weight and the weight of chicks in diet number4.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(cwData}\hlopt{$}\hlstd{weight[cwData}\hlopt{$}\hlstd{Diet}\hlopt{==}\hlstr{'4'}\hlstd{],}\hlkwc{breaks} \hlstd{=} \hlnum{30}\hlstd{,}\hlkwc{main} \hlstd{=} \hlstr{'Histogram: Weight for Diet 4'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-49-1}

\end{knitrout}

\newpage
\subsection{Prediction Model}
\begin{flushleft}
The prediction model chosen is linear regression model. In this model, all variables are included.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{model1} \hlkwb{<-} \hlkwd{lm}\hlstd{(weight} \hlopt{~} \hlstd{.,}\hlkwc{data} \hlstd{= ChickWeight)}
\hlkwd{summary}\hlstd{(model1)}
\end{alltt}
\begin{verbatim}
##
## Call:
## lm(formula = weight ~ ., data = ChickWeight)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -80.128 -15.976  -2.476  13.844  91.955
##
## Coefficients: (3 not defined because of singularities)
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  27.8983     2.2157  12.591  < 2e-16 ***
## Time          8.7152     0.1759  49.538  < 2e-16 ***
## Chick.L     130.2672     9.5424  13.651  < 2e-16 ***
## Chick.Q     -24.9790    10.1028  -2.472 0.013732 *
## Chick.C     -16.2937    10.4180  -1.564 0.118422
## Chick^4      16.8300    10.5032   1.602 0.109674
## Chick^5     -11.8874    10.4181  -1.141 0.254373
## Chick^6      62.0273    10.2441   6.055 2.67e-09 ***
## Chick^7      -5.7763    10.0555  -0.574 0.565913
## Chick^8      -2.1871     9.8366  -0.222 0.824137
## Chick^9      -2.5741     9.5743  -0.269 0.788145
## Chick^10    -15.8198     9.3250  -1.696 0.090382 .
## Chick^11    -29.2864     9.0988  -3.219 0.001367 **
## Chick^12     12.6115     8.8899   1.419 0.156599
## Chick^13     45.5732     8.7345   5.218 2.61e-07 ***
## Chick^14      8.4847     8.6499   0.981 0.327089
## Chick^15    -36.7921     8.5910  -4.283 2.19e-05 ***
## Chick^16    -18.5430     8.5389  -2.172 0.030332 *
## Chick^17     13.8154     8.5068   1.624 0.104966
## Chick^18     19.2098     8.4673   2.269 0.023690 *
## Chick^19    -15.1139     8.3971  -1.800 0.072450 .
## Chick^20     19.1073     8.3290   2.294 0.022178 *
## Chick^21     10.3924     8.3016   1.252 0.211177
## Chick^22    -13.8848     8.2768  -1.678 0.094028 .
## Chick^23     -2.6091     8.2224  -0.317 0.751133
## Chick^24      3.7279     8.1876   0.455 0.649070
## Chick^25    -30.7405     8.2072  -3.746 0.000200 ***
## Chick^26     22.9762     8.2255   2.793 0.005407 **
## Chick^27     37.2504     8.1981   4.544 6.86e-06 ***
## Chick^28     11.6756     8.1679   1.429 0.153467
## Chick^29    -15.8480     8.1893  -1.935 0.053501 .
## Chick^30     -9.6065     8.2243  -1.168 0.243311
## Chick^31      2.6487     8.2253   0.322 0.747567
## Chick^32     15.8318     8.1691   1.938 0.053157 .
## Chick^33     -4.2143     8.1816  -0.515 0.606700
## Chick^34     -8.3473     8.1762  -1.021 0.307759
## Chick^35      0.6771     8.1644   0.083 0.933933
## Chick^36    -17.3660     8.1675  -2.126 0.033948 *
## Chick^37     -2.6001     8.1705  -0.318 0.750435
## Chick^38    -15.5406     8.1727  -1.902 0.057778 .
## Chick^39     -2.8088     8.2396  -0.341 0.733324
## Chick^40     39.4063     8.2667   4.767 2.42e-06 ***
## Chick^41    -15.4934     8.2493  -1.878 0.060914 .
## Chick^42    -27.7127     8.1962  -3.381 0.000775 ***
## Chick^43    -32.3320     8.1715  -3.957 8.64e-05 ***
## Chick^44      9.6068     8.1724   1.176 0.240319
## Chick^45    -12.8100     8.1665  -1.569 0.117338
## Chick^46     21.7381     8.1646   2.662 0.007994 **
## Chick^47     -6.3382     8.1950  -0.773 0.439623
## Chick^48    -16.3989     8.1667  -2.008 0.045152 *
## Chick^49    -25.3853     8.1647  -3.109 0.001978 **
## Diet2             NA         NA      NA       NA
## Diet3             NA         NA      NA       NA
## Diet4             NA         NA      NA       NA
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 28.28 on 527 degrees of freedom
## Multiple R-squared:  0.8554,	Adjusted R-squared:  0.8416
## F-statistic: 62.33 on 50 and 527 DF,  p-value: < 2.2e-16
\end{verbatim}
\end{kframe}
\end{knitrout}
\newpage
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(model1}\hlopt{$}\hlstd{residuals,}\hlkwc{main} \hlstd{=} \hlstr{'Histogram: Residual of Model 0'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-51-1}

\end{knitrout}
\newpage
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{qqnorm}\hlstd{(model1}\hlopt{$}\hlstd{residuals)}
\hlkwd{qqline}\hlstd{(model1}\hlopt{$}\hlstd{residuals)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-52-1}

\end{knitrout}
\newpage
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{par}\hlstd{(}\hlkwc{mfrow}\hlstd{=}\hlkwd{c}\hlstd{(}\hlnum{2}\hlstd{,}\hlnum{2}\hlstd{))}
\hlkwd{plot}\hlstd{(model1)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-53-1}

\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{t.test}\hlstd{(cwData}\hlopt{$}\hlstd{weight, Diet)}
\end{alltt}
\begin{verbatim}
##
## 	Welch Two Sample t-test
##
## data:  cwData$weight and Diet
## t = 40.446, df = 577.31, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  113.776 125.390
## sample estimates:
##  mean of x  mean of y
## 121.818339   2.235294
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\subsection{Conclusion}
\begin{flushleft}
Based on the summaries, and various graphs,
\end{flushleft}
\begin{flushleft}
we can ascertain that diet number 1 has the highest mortality rate
\end{flushleft}
\begin{flushleft}
we can be sure that Diet number 3 contains the highest mean and median weight.
\end{flushleft}
\begin{flushleft}
We can also be sure that diet number 4 is the most consistent due to having the lowest standard deviation out of the four diets.
\end{flushleft}
\begin{flushleft}
As a conclusion, diet 4 is the best choice to go with as it is the most consistent diet.
\end{flushleft}

\newpage
\section{Question 2}
\subsection{Adding/Loading mtcars Dataset and viewing Data}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{data}\hlstd{(mtcars)}
\hlkwd{head}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
\end{verbatim}
\end{kframe}
\end{knitrout}

\subsection{Specifying variables in Dataset}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{names}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
##  [1] "mpg"  "cyl"  "disp" "hp"   "drat" "wt"   "qsec" "vs"   "am"   "gear"
## [11] "carb"
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
\begin{tabular}{|c|c|}
\hline
Variable & Description\\
\hline
mpg & Miles per Gallon\\
\hline
cyl & Number of cylinders	\\
\hline
disp & Displacement\\
\hline
hp & Gross horsepower\\
\hline
drat & Rear axle ratio\\
\hline
wt & Weight\\
\hline
qsec & acceleration speed/time\\
\hline
vs & Binary variable signaling the engine cylinder configuration\\
\hline
am & Transmission Type\\
\hline
gear & Number of forward gears\\
\hline
carb & Number of carburetors\\
\hline
\end{tabular}
\end{flushleft}

\newpage
\subsection{Type of variables in Dataset in column}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{str}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
## 'data.frame':	32 obs. of  11 variables:
##  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
##  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
##  $ disp: num  160 160 108 258 360 ...
##  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
##  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
##  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
##  $ qsec: num  16.5 17 18.6 19.4 17 ...
##  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
##  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
##  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
##  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\subsection{Dimensions of mtcars Data}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{nrow}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
## [1] 32
\end{verbatim}
\begin{alltt}
\hlkwd{ncol}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
## [1] 11
\end{verbatim}
\begin{alltt}
\hlkwd{length}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
## [1] 11
\end{verbatim}
\begin{alltt}
\hlkwd{dim}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
## [1] 32 11
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\subsection{Exploratory data analysis}
\begin{flushleft}
Shows the number of observations (rows) and variables, and a head of the first cases.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{glimpse}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
## Rows: 32
## Columns: 11
## $ mpg  <dbl> 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17...
## $ cyl  <dbl> 6, 6, 4, 6, 8, 6, 8, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4,...
## $ disp <dbl> 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8,...
## $ hp   <dbl> 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, ...
## $ drat <dbl> 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3....
## $ wt   <dbl> 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150,...
## $ qsec <dbl> 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90,...
## $ vs   <dbl> 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,...
## $ am   <dbl> 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0,...
## $ gear <dbl> 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3,...
## $ carb <dbl> 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1,...
\end{verbatim}
\end{kframe}
\end{knitrout}
\newpage
\begin{flushleft}
Gets data types, zeros, infinite numbers, and missing values from variables in the dataset.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{status}\hlstd{(mtcars)}
\end{alltt}
\begin{verbatim}
##    variable q_zeros p_zeros q_na p_na q_inf p_inf    type unique
## 1       mpg       0 0.00000    0    0     0     0 numeric     25
## 2       cyl       0 0.00000    0    0     0     0 numeric      3
## 3      disp       0 0.00000    0    0     0     0 numeric     27
## 4        hp       0 0.00000    0    0     0     0 numeric     22
## 5      drat       0 0.00000    0    0     0     0 numeric     22
## 6        wt       0 0.00000    0    0     0     0 numeric     29
## 7      qsec       0 0.00000    0    0     0     0 numeric     30
## 8        vs      18 0.56250    0    0     0     0 numeric      2
## 9        am      19 0.59375    0    0     0     0 numeric      2
## 10     gear       0 0.00000    0    0     0     0 numeric      3
## 11     carb       0 0.00000    0    0     0     0 numeric      6
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Get frequency of each variable/column in the dataset.
\end{flushleft}

\begin{flushleft}
\textbf{Gets the frequency of mile Per Gallon}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-61-1}

\end{knitrout}
\newpage
\begin{flushleft}
\textbf{Gets the frequency of number of cylinders}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-62-1}

\end{knitrout}
\newpage
\begin{flushleft}
\textbf{Gets the frequency of displacement}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-63-1}

\end{knitrout}
\newpage
\begin{flushleft}
\textbf{Gets the frequency of gross horsepower}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-64-1}

\end{knitrout}
\newpage
\begin{flushleft}
\textbf{Gets the frequency of rear axle ratio}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-65-1}

\end{knitrout}
\newpage
\begin{flushleft}
\textbf{Gets the frequency of weight}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-66-1}

\end{knitrout}
\newpage
\begin{flushleft}
\textbf{Gets the frequency of acceleration time}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{freq}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-67-1}

\end{knitrout}

\newpage
\begin{flushleft}
Gets all numerical/integer variables.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{print}\hlstd{(}\hlkwd{profiling_num}\hlstd{(mtcars))}
\end{alltt}
\begin{verbatim}
##    variable       mean     std_dev variation_coef     p_01    p_05      p_25
## 1       mpg  20.090625   6.0269481      0.2999881 10.40000 11.9950  15.42500
## 2       cyl   6.187500   1.7859216      0.2886338  4.00000  4.0000   4.00000
## 3      disp 230.721875 123.9386938      0.5371779 72.52600 77.3500 120.82500
## 4        hp 146.687500  68.5628685      0.4674077 55.10000 63.6500  96.50000
## 5      drat   3.596563   0.5346787      0.1486638  2.76000  2.8535   3.08000
## 6        wt   3.217250   0.9784574      0.3041285  1.54462  1.7360   2.58125
## 7      qsec  17.848750   1.7869432      0.1001159 14.53100 15.0455  16.89250
## 8        vs   0.437500   0.5040161      1.1520369  0.00000  0.0000   0.00000
## 9        am   0.406250   0.4989909      1.2282853  0.00000  0.0000   0.00000
## 10     gear   3.687500   0.7378041      0.2000825  3.00000  3.0000   3.00000
## 11     carb   2.812500   1.6152000      0.5742933  1.00000  1.0000   2.00000
##       p_50   p_75      p_95      p_99   skewness kurtosis       iqr
## 1   19.200  22.80  31.30000  33.43500  0.6404399 2.799467   7.37500
## 2    6.000   8.00   8.00000   8.00000 -0.1831287 1.319032   4.00000
## 3  196.300 326.00 449.00000 468.28000  0.4002724 1.910317 205.17500
## 4  123.000 180.00 253.55000 312.99000  0.7614356 3.052233  83.50000
## 5    3.695   3.92   4.31450   4.77500  0.2788734 2.435116   0.84000
## 6    3.325   3.61   5.29275   5.39951  0.4437855 3.172471   1.02875
## 7   17.710  18.90  20.10450  22.06920  0.3870456 3.553753   2.00750
## 8    0.000   1.00   1.00000   1.00000  0.2519763 1.063492   1.00000
## 9    0.000   1.00   1.00000   1.00000  0.3817709 1.145749   1.00000
## 10   4.000   4.00   5.00000   5.00000  0.5546495 2.056790   1.00000
## 11   2.000   4.00   4.90000   7.38000  1.1021304 4.536121   2.00000
##              range_98         range_80
## 1      [10.4, 33.435]   [14.34, 30.09]
## 2              [4, 8]           [4, 8]
## 3    [72.526, 468.28]     [80.61, 396]
## 4      [55.1, 312.99]      [66, 243.5]
## 5       [2.76, 4.775]   [3.007, 4.209]
## 6  [1.54462, 5.39951] [1.9555, 4.0475]
## 7   [14.531, 22.0692]  [15.534, 19.99]
## 8              [0, 1]           [0, 1]
## 9              [0, 1]           [0, 1]
## 10             [3, 5]           [3, 5]
## 11          [1, 7.38]           [1, 4]
\end{verbatim}
\end{kframe}
\end{knitrout}
\newpage
\begin{flushleft}
Gets all numerical/integer variables.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{plot_num}\hlstd{(mtcars)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-69-1}

\end{knitrout}

\newpage
\subsection{Descriptive statistics}
\begin{flushleft}
Descriptive statistics methods consists of measures of central tendency, measures of dispersion and measures of association.
\end{flushleft}
\begin{flushleft}
The measures of central tendency includes the mean, median, mode, and skewness.
\end{flushleft}
\begin{flushleft}
Below is the mean calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 20.09062
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] 6.1875
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1] 230.7219
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1] 146.6875
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 3.596563
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 3.21725
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{mean}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 17.84875
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Below is the median calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 19.2
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] 6
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1] 196.3
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1] 123
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 3.695
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 3.325
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{median}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 17.71
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Below is the mode calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 21.0 22.8 21.4 19.2 15.2 10.4 30.4
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] 8
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1] 275.8
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1] 110 175 180
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 3.92 3.07
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 3.44
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{my_mode}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 17.02 18.90
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Below is the skewness calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 0.610655
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] -0.1746119
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1] 0.381657
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1] 0.7260237
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 0.2659039
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 0.4231465
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{skewness}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 0.3690453
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Measure of Dispersion includes the range, interquartile range, and standard deviation.
\end{flushleft}
\begin{flushleft}
Below is the range calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 10.4 33.9
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] 4 8
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1]  71.1 472.0
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1]  52 335
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 2.76 4.93
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 1.513 5.424
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{range}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 14.5 22.9
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Below is the interquartile range calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 7.375
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] 4
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1] 205.175
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1] 83.5
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 0.84
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 1.02875
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{IQR}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 2.0075
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Below is the standard deviation calculation for all variables/columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg)}
\end{alltt}
\begin{verbatim}
## [1] 6.026948
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl)}
\end{alltt}
\begin{verbatim}
## [1] 1.785922
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{disp)}
\end{alltt}
\begin{verbatim}
## [1] 123.9387
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{hp)}
\end{alltt}
\begin{verbatim}
## [1] 68.56287
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{drat)}
\end{alltt}
\begin{verbatim}
## [1] 0.5346787
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{wt)}
\end{alltt}
\begin{verbatim}
## [1] 0.9784574
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{sd}\hlstd{(mtcars}\hlopt{$}\hlstd{qsec)}
\end{alltt}
\begin{verbatim}
## [1] 1.786943
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
Measure of association includes the correlation, which measures the association between two variables. and covariance, which measures how much two variables change together.
\end{flushleft}

\begin{flushleft}
\textbf{Correlation between mile per gallon and number of cylinders.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{cyl,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.852162
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{cyl,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.9108013
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{cyl,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.7953134
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above tests, we can see that the values from all 3 tests is between -0.7 and -0.9, which indicates a strong negative linear relationship between the miles per gallon and number of cylinders. \\
\end{flushleft}

\begin{flushleft}
\textbf{Correlation between mile per gallon and displacement.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.8475514
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.9088824
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.7681311
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above tests, we can see that the values from all 3 tests is between -0.7 and -0.9, which indicates a strong negative linear relationship between the miles per gallon and displacement. \\
\end{flushleft}

\newpage
\begin{flushleft}
\textbf{Correlation between number of cylinders and displacement.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.9020329
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.9276516
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 0.8144263
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above tests, we can see that the values from all 3 tests is between 0.8 and 0.9, which indicates a near perfect positive linear relationship between number of cylinders and displacement. \\
\end{flushleft}

\begin{flushleft}
\textbf{Correlation between the gross horsepower(hp) and rear axle ratio(drat).}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{hp, mtcars}\hlopt{$}\hlstd{drat,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.4487591
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{hp, mtcars}\hlopt{$}\hlstd{drat,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.520125
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cor}\hlstd{(mtcars}\hlopt{$}\hlstd{hp, mtcars}\hlopt{$}\hlstd{drat,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -0.3826269
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above tests, we can see that the values from all 3 tests is between -0.3 and -0.5, which indicates a moderate negative relationship between the gross horsepower(hp) and rear axle ratio(drat). \\
\end{flushleft}

\newpage
\begin{flushleft}
\textbf{Covariance between mile per gallon and number of cylinders.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{cyl,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -9.172379
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{cyl,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -74.54032
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{cyl,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -638
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
Results indicate that the two are negatively related and has a very strongly negative relationship between mile per gallon and number of cylinders.
\end{flushleft}

\begin{flushleft}
\textbf{Covariance between mile per gallon and displacement.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -633.0972
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -79.87903
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -752
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
Results indicate that the two are negatively related and has a very strongly negative relationship between mile per gallon and displacement.
\end{flushleft}

\newpage
\begin{flushleft}
\textbf{Covariance between number of cylinders and displacement.}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 199.6603
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 75.91935
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{cyl, mtcars}\hlopt{$}\hlstd{disp,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] 654
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
Results indicate that the two are positively related and has a very strongly positive relationship between number of cylinders and displacement.
\end{flushleft}

\begin{flushleft}
\textbf{Covariance between the gross horsepower(hp) and rear axle ratio(drat).}
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{hp, mtcars}\hlopt{$}\hlstd{drat,} \hlkwc{method} \hlstd{=} \hlstr{"pearson"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -16.45111
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{hp, mtcars}\hlopt{$}\hlstd{drat,} \hlkwc{method} \hlstd{=} \hlstr{"spearman"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -45.64516
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{cov}\hlstd{(mtcars}\hlopt{$}\hlstd{hp, mtcars}\hlopt{$}\hlstd{drat,} \hlkwc{method} \hlstd{=} \hlstr{"kendall"}\hlstd{)}
\end{alltt}
\begin{verbatim}
## [1] -370
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
Results indicate that the two are negatively related and has a very strongly negative relationship between the gross horsepower(hp) and rear axle ratio(drat).
\end{flushleft}

\newpage
\subsection{Visualizing cars data}
\begin{flushleft}
The below Histogram checks for the distribution of miles per gallon (mpg) variable in the dataset. \\
\end{flushleft}
\begin{flushleft}
As a result from the histogram below, the distribution is normal.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{hist}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg,} \hlkwc{breaks}\hlstd{=}\hlnum{10}\hlstd{,} \hlkwc{xlab} \hlstd{=} \hlstr{"Miles per gallon"}\hlstd{,} \hlkwc{main} \hlstd{=} \hlstr{"Histogram of Miles per gallon of cars"}\hlstd{,} \hlkwc{xlim} \hlstd{=} \hlkwd{range}\hlstd{(}\hlnum{10}\hlopt{:}\hlnum{35}\hlstd{))}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-143-1}

\end{knitrout}

\newpage
\begin{flushleft}
The below Histogram checks for the mpg with respect to transmission type to determine which transmission type is/has better mpg rate. \\
\end{flushleft}
\begin{flushleft}
As a result from the histogram below, the transmission type 1 which is the Manual type, has/gives better mpg.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{plot}\hlstd{(mtcars}\hlopt{$}\hlstd{mpg} \hlopt{~} \hlkwd{as.factor}\hlstd{(mtcars}\hlopt{$}\hlstd{am), mtcars,} \hlkwc{xlab} \hlstd{=} \hlstr{"Transmission type"}\hlstd{,} \hlkwc{ylab}\hlstd{=}\hlstr{"Miles per gallon"}\hlstd{,} \hlkwc{main}\hlstd{=}\hlstr{"Histogram of MPG by transmission type"}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-144-1}

\end{knitrout}

\newpage
\begin{flushleft}
To show the distribution of number of cars against miles per gallon.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(mtcars,} \hlkwd{aes}\hlstd{(mpg))} \hlopt{+}
  \hlkwd{geom_histogram}\hlstd{(}\hlkwc{binwidth} \hlstd{=} \hlnum{4}\hlstd{)} \hlopt{+} \hlkwd{xlab}\hlstd{(}\hlstr{'Miles per Gallon'}\hlstd{)} \hlopt{+} \hlkwd{ylab}\hlstd{(}\hlstr{'Number of Cars'}\hlstd{)} \hlopt{+}
   \hlkwd{ggtitle}\hlstd{(}\hlstr{'Distribution of Cars by Mileage'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-145-1}

\end{knitrout}

\newpage
\begin{flushleft}
To show the distribution of number of cars against number of cylinders.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(mtcars,} \hlkwd{aes}\hlstd{(cyl))} \hlopt{+}
  \hlkwd{geom_histogram}\hlstd{(}\hlkwc{binwidth}\hlstd{=}\hlnum{1}\hlstd{)} \hlopt{+} \hlkwd{xlab}\hlstd{(}\hlstr{'Cylinders'}\hlstd{)} \hlopt{+} \hlkwd{ylab}\hlstd{(}\hlstr{'Number of Cars'}\hlstd{)} \hlopt{+}
   \hlkwd{ggtitle}\hlstd{(}\hlstr{'Distribution of Cars by Cylinders'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-146-1}

\end{knitrout}

\newpage
\begin{flushleft}
To show the distribution of number of cars against the cars' horsepower.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{ggplot}\hlstd{(mtcars,} \hlkwd{aes}\hlstd{(hp))} \hlopt{+}
  \hlkwd{geom_histogram}\hlstd{(}\hlkwc{binwidth}\hlstd{=}\hlnum{20}\hlstd{)} \hlopt{+} \hlkwd{xlab}\hlstd{(}\hlstr{'horsepower'}\hlstd{)} \hlopt{+} \hlkwd{ylab}\hlstd{(}\hlstr{'Number of Cars'}\hlstd{)} \hlopt{+}
  \hlkwd{ggtitle}\hlstd{(}\hlstr{'Distribution of Cars by Horsepower'}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-147-1}

\end{knitrout}

\newpage
\subsection{Prediction Model}
\begin{flushleft}
For the prediction model, the linear regression model will be used with only the variable or column 'am' as the prediction value/variable.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{linmodFit} \hlkwb{<-} \hlkwd{lm}\hlstd{( mpg} \hlopt{~} \hlkwd{as.factor}\hlstd{(am),} \hlkwc{data}\hlstd{=mtcars)}
\hlkwd{summary}\hlstd{(linmodFit)}
\end{alltt}
\begin{verbatim}
##
## Call:
## lm(formula = mpg ~ as.factor(am), data = mtcars)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -9.3923 -3.0923 -0.2974  3.2439  9.5077
##
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)
## (Intercept)      17.147      1.125  15.247 1.13e-15 ***
## as.factor(am)1    7.245      1.764   4.106 0.000285 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.902 on 30 degrees of freedom
## Multiple R-squared:  0.3598,	Adjusted R-squared:  0.3385
## F-statistic: 16.86 on 1 and 30 DF,  p-value: 0.000285
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above summary for the first fit, we can see that the manual transmission cars get 7.245 miles per gallon more than automatic transmission cars.
\end{flushleft}

\newpage
\begin{flushleft}
Here we will verify or check the correlations between the different variables or columns.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{corr_mt} \hlkwb{=} \hlkwd{cor}\hlstd{(mtcars)}
\hlkwd{corrplot}\hlstd{(corr_mt,} \hlkwc{method}\hlstd{=}\hlstr{"color"}\hlstd{,} \hlkwc{addCoef.col}\hlstd{=}\hlstr{"black"}\hlstd{,} \hlkwc{number.cex}\hlstd{=}\hlnum{0.5}\hlstd{,} \hlkwc{type}\hlstd{=}\hlstr{"lower"}\hlstd{)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-149-1}

\end{knitrout}
\begin{flushleft}
Here we can see that mpg has a very strong correlation with cyl , disp, hp and wt and drat as the results those variables or columns gave is more than 0.5. \\
\end{flushleft}

\newpage
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{linmodFit1} \hlkwb{<-} \hlkwd{lm}\hlstd{( mtcars}\hlopt{$}\hlstd{mpg} \hlopt{~} \hlstd{hp} \hlopt{+} \hlstd{wt} \hlopt{+} \hlkwd{as.factor}\hlstd{(am),} \hlkwc{data}\hlstd{=mtcars)}
\hlkwd{summary}\hlstd{(linmodFit1)}
\end{alltt}
\begin{verbatim}
##
## Call:
## lm(formula = mtcars$mpg ~ hp + wt + as.factor(am), data = mtcars)
##
## Residuals:
##     Min      1Q  Median      3Q     Max
## -3.4221 -1.7924 -0.3788  1.2249  5.5317
##
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)
## (Intercept)    34.002875   2.642659  12.867 2.82e-13 ***
## hp             -0.037479   0.009605  -3.902 0.000546 ***
## wt             -2.878575   0.904971  -3.181 0.003574 **
## as.factor(am)1  2.083710   1.376420   1.514 0.141268
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.538 on 28 degrees of freedom
## Multiple R-squared:  0.8399,	Adjusted R-squared:  0.8227
## F-statistic: 48.96 on 3 and 28 DF,  p-value: 2.908e-11
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{flushleft}
From the above summary for the second fit, we can see that because the R-squared values show that 84\% of predicted variables can be explained by this model which was better than the first fit.
\end{flushleft}
\begin{flushleft}
For the above summary, we can also see that the manual transmission cars have 2.084 MPGs more than automatic
transmission cars.
\end{flushleft}

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{anova}\hlstd{(linmodFit, linmodFit1)}
\end{alltt}
\begin{verbatim}
## Analysis of Variance Table
##
## Response: mpg
##               Df Sum Sq Mean Sq F value   Pr(>F)
## as.factor(am)  1 405.15  405.15   16.86 0.000285 ***
## Residuals     30 720.90   24.03
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\begin{flushleft}
This plots is to show if there is a trend to the residuals.
\end{flushleft}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{par}\hlstd{(}\hlkwc{mfrow} \hlstd{=} \hlkwd{c}\hlstd{(}\hlnum{2}\hlstd{,}\hlnum{2}\hlstd{))}
\hlkwd{plot}\hlstd{(linmodFit1)}
\end{alltt}
\end{kframe}
\includegraphics[width=\maxwidth]{figure/unnamed-chunk-152-1}

\end{knitrout}
\begin{flushleft}
From the Normal Q-Q plot, it is determined that the residuals are normally distributed.
\end{flushleft}
\begin{flushleft}
In the Scale Location plot it is determined that the residuals are not completely randomly spreading.
\end{flushleft}

\newpage
\subsection{Question 2: Conclusion}
\begin{flushleft}
Based on the summaries, and various graphs, we can come to the conclusion that cars with Manual transmissions has more miles per gallon, so it is better than cars with Auto transmission. \\
\end{flushleft}
\begin{flushleft}
Based on the summary for the prediction model made, the difference between automatic and manual transmission is 7.24. \\
\end{flushleft}
\begin{flushleft}
As a conclusion, we cannot conclude if whether car with manual transmission or cars with automatic transmission is better, as it varies between the variables used in the prediction model.
\end{flushleft}

\end{document}


\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
% maxwidth is the original width if it is less than linewidth
% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
  \ifdim\Gin@nat@width>\linewidth
    \linewidth
  \else
    \Gin@nat@width
  \fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\let\hlipl\hlkwb

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
 \def\at@end@of@kframe{}%
 \ifinner\ifhmode%
  \def\at@end@of@kframe{\end{minipage}}%
  \begin{minipage}{\columnwidth}%
 \fi\fi%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \\@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@totalleftmargin\z@ \linewidth\hsize
   \@setminipage}}%
 {\par\unskip\endMakeFramed%
 \at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}
\usepackage{amsmath}
\usepackage{mathtools}
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}

\title{Lab 2}
\author{Richelle Tan Wei Qi - 0328371}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\maketitle{}
\tableofcontents

\newpage
\section{Question 1}
The following data give the results of a sample survey. The letters A, B, and C represent the three categories.

\begin{center}
\begin{tabular}{cccccccccc}
A	&B&	B&	A&	C&	B&	C&	C&	C&	A\\
C&	B&	C&	A&	C&	C&	B&	C&	C&	A\\
A&	B&	C&	C&	B&	C&	B&	A&	C&	A\\
\end{tabular}
\end{center}

\subsection{}
Prepare a frequency table.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## xq1
##  A  B  C
##  8  8 14
\end{verbatim}
\end{kframe}
\end{knitrout}

\subsection{}
Calculate the relative frequencies and percentages for all categories.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## xq1
##         A         B         C
## 0.2666667 0.2666667 0.4666667
## xq1
##        A        B        C
## 26.66667 26.66667 46.66667
\end{verbatim}
\end{kframe}
\end{knitrout}

\subsection{}

What percentage of the elements in this sample belong to category B? \\ \newline
The percentage of the elements in this sample belonging to category B is 26.6666667\%.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
##   xq1     Freq
## 1   A 26.66667
## 2   B 26.66667
## 3   C 46.66667
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\subsection{}

What percentage of the elements in this sample belong to category A and C? \\ \newline
The percentage of the elements in the sample belonging to category A and C is 73.3333333\%.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 73.33333
\end{verbatim}
\end{kframe}
\end{knitrout}

\subsection{}
Draw a bar graph for the frequency distribution. \newline
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=\maxwidth]{figure/unnamed-chunk-7-1}

}

\end{knitrout}

\newpage
\section{Question 2}
The following table gives the frequency distribution of the number of credit cards possessed by 80
adults.
\begin{center}
\begin{tabular}{|c|c|}
\hline
Number of credit cards & Number of Adults\\
\hline
0 to 3 & 18 \\
\hline
4 to 7 & 26 \\
\hline
8 to 11 & 22 \\
\hline
12 to 15 & 11 \\
\hline
16 to 19 & 3\\
\hline
\end{tabular}
\end{center}

\subsection{}
Prepare a cumulative frequency distribution.
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
Number of credit cards & Number of Adults & Cumulative Frequency\\
\hline
0 to 3 & 18 & 18\\
\hline
4 to 7 & 26 & 44\\
\hline
8 to 11 & 22 & 66\\
\hline
12 to 15 & 11 & 77\\
\hline
16 to 19 & 3 & 80\\
\hline
\end{tabular}
\end{center}

\subsection{}
Calculate the cumulative relative frequencies and cumulative percentages for all
classes.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1]  22.50  55.00  82.50  96.25 100.00
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
Number of credit cards & Number of Adults & Cumulative Frequency& Percentage of CF\\
\hline
0 to 3 & 18 & 18&22.5\\
\hline
4 to 7 & 26 & 44&55\\
\hline
8 to 11 & 22 & 66&82.5\\
\hline
12 to 15 & 11 & 77&96.25\\
\hline
16 to 19 & 3 & 80&100\\
\hline
\end{tabular}
\end{center}

\subsection{}
Find the percentage of these adults who possess 7 or fewer credit cards. \\ \newline
The percentage of adults who possess 7 or fewer credit cards is 55\%.

\subsection{}
Draw an ogive for the cumulative percentage distribution.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=\maxwidth]{figure/unnamed-chunk-9-1}

}

\end{knitrout}

\subsection{}
Using the ogive, find the percentage of adults who possess 10 or fewer credit cards.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 82.5
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\section{Question 3}
Calculate the mean, median, variance, standard deviation, first quartile, second quartile, third
quartile and mode for the Iris data in R dataset. Is the distribution symmetric or skewed?
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
##   Sepal.Length    Sepal.Width     Petal.Length    Petal.Width
##  Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100
##  1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300
##  Median :5.800   Median :3.000   Median :4.350   Median :1.300
##  Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199
##  3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800
##  Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500
##        Species
##  setosa    :50
##  versicolor:50
##  virginica :50
##
##
##
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
##              vars   n mean   sd median trimmed  mad min max range  skew
## Sepal.Length    1 150 5.84 0.83   5.80    5.81 1.04 4.3 7.9   3.6  0.31
## Sepal.Width     2 150 3.06 0.44   3.00    3.04 0.44 2.0 4.4   2.4  0.31
## Petal.Length    3 150 3.76 1.77   4.35    3.76 1.85 1.0 6.9   5.9 -0.27
## Petal.Width     4 150 1.20 0.76   1.30    1.18 1.04 0.1 2.5   2.4 -0.10
## Species*        5 150 2.00 0.82   2.00    2.00 1.48 1.0 3.0   2.0  0.00
##              kurtosis   se
## Sepal.Length    -0.61 0.07
## Sepal.Width      0.14 0.04
## Petal.Length    -1.42 0.14
## Petal.Width     -1.36 0.06
## Species*        -1.52 0.07
\end{verbatim}
\end{kframe}
\end{knitrout}
The mode is:
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 1.4 1.5
\end{verbatim}
\end{kframe}
\end{knitrout}

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=\maxwidth]{figure/unnamed-chunk-14-1}

}

{\centering \includegraphics[width=\maxwidth]{figure/unnamed-chunk-14-2}

}

\end{knitrout}

\textbf{Conclusion:} \\ \newline The Sepal Length for virginica and Sepal Width of Setosa both have outliers (They are the dots that out run the whiskers). While all the other boxplots looked perfectly balanced, we can see that that petal width for both setosa and versicolor are positively skewed as the median lie at the lower end of the boxplot.

\newpage
\section{Question 4}
An office supply company conducted a survey before marketing a new paper shredder designed for
home use. In the survey, 80\% of the people who used the shredder were satisfied with it. Because
of this high acceptance rate, the company decided to market the new shredder. Assume that 80\% of
all people who will use it will be satisfied. On a certain day, seven customers bought this shredder.

\subsection{}
Let x denote the number of customers in this sample of seven who will be satisfied with this
shredder. Using the binomial probabilities (R software), obtain the probability distribution of
x and draw a graph of the probability distribution. Find the mean and standard deviation of
x. \\ \newline
\textbf{Answer:} \\ \newline
Let x denote the number of customers in this sample of 7 who will be \\ satisfied with this shredder. \\ \newline Using the binomial probabilities table, obtain the probability distribution of x and fill in the table, \\ \newline
\begin{center}
\begin{tabular}{ccccccccc}
x & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
p(x)(for each number)\\ \newline
\end{tabular}
\end{center}
There are n trials and x successes in a binomial distribution. The probability of success in each trial is denoted by p. \\ \newline The p.m.f of a binomial distribution is given by, \\ \newline
P(X = $\chi$) = $\eta$C$\chi$ \textbf{\textperiodcentered} $\rho$\textsuperscript{$\chi$} \textbf{\textperiodcentered} (1 - $\rho$)\textsuperscript{$\eta$ - $\chi$} \\ \newline
Given that, n = 7, p = 0.8. Let x denote the number of customers in this sample of 7 who will be satisfied with this shredder. The random variable X follows a binomial distribution with parameters n=7 and p=0.8. \\ \newline
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}

{\centering \includegraphics[width=\maxwidth]{figure/unnamed-chunk-15-1}

}

\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 0.0000128 0.0003584 0.0043008 0.0286720 0.1146880 0.2752512 0.3670016
## [8] 0.2097152
\end{verbatim}
\end{kframe}
\end{knitrout}
Rounded to 5th decimal places.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 0.00001 0.00036 0.00430 0.02867 0.11469 0.27525 0.36700 0.20972
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
P & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7\\
\hline
P(X) & 0.00001 & 0.0004	& 0.004 & 0.03 & 0.115 & 0.28	& 0.37 & 0.21 \\
\hline
\end{tabular}
\end{center}
\newpage
The mean is:
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 0.125
\end{verbatim}
\end{kframe}
\end{knitrout}
The standard deviation is:
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 0.1431422
\end{verbatim}
\end{kframe}
\end{knitrout}

\subsection{}
Using the probability distribution of part a, find the probability that exactly four of the seven
customers will be satisfied.
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 0.114688
\end{verbatim}
\end{kframe}
\end{knitrout}
Rounded off to 3 decimal places:
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
## [1] 0.115
\end{verbatim}
\end{kframe}
\end{knitrout}

\newpage
\section{Question 5}
Let X be a continuous random variable with the following PDF
$$f(x) =\begin{cases} 3/x^4, &  $x $\geq$ 1$ \\
                     0, &   otherwise
       \end{cases}$$

\subsection{}
Find $P(0 \leq x \leq 0.5)$ \\ \newline
\textbf{Answer:} \\
$P(0 \leq x \leq 0.5) = $
\[ \int_0^{0.5} 3/x^4\;\mathrm{d}x=  x^2 \Big|_0^{0.5} \]\\
\[ = [0.5^2]-0^2\]\\
\[=0.25\]

\subsection{}
Find $P(0.5 \leq x \leq 0.75)$ \\ \newline
\textbf{Answer:} \\

\subsection{}
Find $P(x \geq 0.75)$ \\ \newline
\textbf{Answer:} \\

\subsection{}
Find the CDF of X, F(x) \\ \newline
\textbf{Answer:} \\

\subsection{}
Find the expected value of X \\ \newline
\textbf{Answer:} \\

\subsection{}
Find the Var(X) \\ \newline
\textbf{Answer:} \\

\end{document}


\section*{Module Information}

\subsection*{Lecturer}
David McConnell, McConnellD@Cardiff.ac.uk, Office M/0.25, Ground Floor, Mathematics Building

\subsection*{Lecture Notes}
Printed outline lecture notes will be handed out during lectures, in several parts.  There are six chapters in total.  These will contain definitions, statements of main results etc., with gaps to be filled in during class (with examples, comments and so on).  I have not left blank spaces for proofs (except in one or two cases), as many of them are quite long.

To get the most out of the lectures in this module, you are advised to read ahead in the notes and attempt to `fill in the blanks' before coming to lectures.

Complete lecture notes will be posted online, after each section has been completed.

\subsection*{Texbook}

The recommended textbook for this module is
\begin{itemize}
\item \emph{Basic Complex Analysis}, J.E. Marsden and M.J. Hoffman, (Freeman).
\end{itemize}
It is not necessary to buy this textbook; there are numerous copies available in the library.  There are a number of excellent alternatives, such as
\begin{itemize}
\item \emph{Complex Analysis}, J.M. Howie, (Springer),
\item \emph{Introduction to Complex Analysis}, H.A. Priestley (Oxford),
\item \emph{Complex Analysis}, I. Stewart and D. Tall (Cambridge),
\item \emph{Lecture Notes on Complex Analysis}, I.F. Wilde (Imperial College Press),
\end{itemize}
and many others.

\subsection*{Office Hours}
\begin{itemize}
\item Monday: 15.00-16.00,
\item Tuesday: 16.00-17.00.
\end{itemize}
I am happy to answer any questions you might have about the material covered in lectures or on the problem sheets during office hours.  You do not have to let me know in advance if you plan on coming at these times.\\~\\
Outside of these times, it is probably best to email first to arrange a convenient time to meet.

\subsection*{Exercise Sheets}

There will be 6 problem sheets over the course of this module. The first of these consists of revision exercises, on topics that have seen in Year 1.  You are advised to attempt these as soon as possible.

I will discuss the content of the problem sheets during the one of Wednesday lectures each fortnight.  I will let you know in advance which problems I intend to cover during these classes.

You do not have to hand in you attempts at the problem sheets, though you are welcome to do so if you would like me to mark them, and to provide feedback.  Outline solutions will be posted on Learning Central.

\subsection*{Assessment}
This module will be assessed with a 2 hour exam.

\subsection*{Discussion Forum}
I have created a discussion forum for this module, to access it please follow the link on Learning Central.  You can post any questions about the course content here, and anyone can answer them (including me).  As a general rule, this is preferable to asking questions by email, particularly mathematical questions, as the discussion board supports \LaTeX.

\subsection*{Course Content}
\begin{itemize}
\item Revision of complex numbers, functions of a complex variable.
\item Continuity, differentiability and holomorphic functions.
\item Path Integrals.  When we integrate `between' two complex numbers $z_1$ and $z_2$, we must take into account the fact that there are many different paths between $z_1$ and $z_2$.
\item Cauchy's Theorem, Cauchy's Integral Formula and the Residue Theorem.  These results concern integrals along paths that have the same start- and end-points.
\item Applications: Taylor's Theorem, Evaluating Real Integrals using Residues.  For example, we will show how many useful real integrals can be evaluated using techniques from complex analysis, e.g., integrals of the form
\[
\int_{-\infty}^{+\infty} \frac{1}{x^4+1}\ dx \quad\text{or}\quad \int_0^{2\pi} \frac{\sin(t)}{5+2\sin(t)}\ dt.
\]
Note that these cannot be evaluated using methods from calculus.
\end{itemize}


\include{../common/start}
\title[Intro to CP]{Introduction to Competitive Programming}
\subtitle[Get started with CP]{Get started with competitive programming}

\include{../common/init}

\section{What is competitive programming?}

\subsection{Definition}
\begin{frame}
    \frametitle{Competitive programming - Definition}
    \begin{alertblock}{Definition}
        Competitive programming is a mind sport usually held over the Internet [...], involving participants trying to program according to provided specifications. \\
        A programming competition generally involves the host presenting a set of logical or mathematical problems to the contestants [...], and contestants are required to write computer programs capable of solving each problem. \\
    \end{alertblock}
\end{frame}

\subsection{Advantages}
\begin{frame}
    \frametitle{Competitive programming - Advantages}
    \begin{itemize}
        \item Develops \alert{computational thinking} \pause
        \item Helps in job interviews \pause
        \item Helps in software jobs \pause
        \item Is addictive and fun!
    \end{itemize}
\end{frame}

\section{Solving your first problem}
\subsection{Prerequisite}
\begin{frame}
    \frametitle{Prerequisite}
    \begin{itemize}
        \item Know how to compile and run C++ program
    \end{itemize}
\end{frame}

\subsection{Codechef}
\begin{frame}
    \frametitle{Codechef}
    \href{https://www.codechef.com}{https://www.codechef.com} \\
    \\
    \screenshot{screenshots/codechef.png}
\end{frame}
\begin{frame}
    \frametitle{First problem - Add two numbers}
    \href{https://www.codechef.com/problems/FLOW001}{https://www.codechef.com/problems/FLOW001} \\
    \\
    \screenshot{screenshots/flow001_statement.png}
\end{frame}
\begin{frame}
    \frametitle{First problem - Examples}
    \screenshot{screenshots/flow001_examples.png}
\end{frame}

\begin{frame}[fragile]
\frametitle{First problem - Code}
\begin{cppcode}
#include<iostream>

using namespace std;

int main() {
    int T;
    cin >> T;

    for(int i = 0; i < T; i++) {
        int a, b;
        cin >> a >> b;
        int ans = a + b;
        cout << ans << endl;
    }

    return 0;
}
\end{cppcode}
\end{frame}

\subsection{Coding and submitting}

\begin{frame}
    \frametitle{First problem - Submit}
    \href{https://www.codechef.com/submit/FLOW001}{https://www.codechef.com/submit/FLOW001}
    \screenshot{screenshots/flow001_submit.png}
\end{frame}

\begin{frame}
    \frametitle{First problem - Verdict}
    \screenshot{screenshots/flow001_ac.png}
\end{frame}

\section{More sites}
\begin{frame}
    \frametitle{More sites - spoj}
    \href{http://www.spoj.com/}{http://www.spoj.com/}
    \screenshot{screenshots/spoj.png}
\end{frame}

\begin{frame}
    \frametitle{More sites - codeforces}
    \href{http://codeforces.com/}{http://codeforces.com/}
    \screenshot{screenshots/codeforces.png}
\end{frame}

\begin{frame}
    \frametitle{More sites - topcoder}
    \href{https://arena.topcoder.com/\#/u/dashboard}{https://arena.topcoder.com/\#/u/dashboard}
    \screenshot{screenshots/topcoder.png}
\end{frame}

\section{Contests}
\begin{frame}
    \frametitle{Regular short contests}
    \begin{itemize}
        \item Topcoder SRM (Single Round Match) \\
        \item Codeforces Rounds \\
        \item Codechef cook off and lunchtime \\
    \end{itemize}
\end{frame}

\begin{frame}
    \frametitle{Regular long contests}
    \begin{itemize}
        \item Topcoder marathon \\
        \item Codechef long contests \\
        \item Codeforces educational rounds and marathon \\
    \end{itemize}
\end{frame}

\begin{frame}
    \frametitle{Annual contests}
    \begin{itemize}
        \item \href{http://www.ioinformatics.org/index.shtml}{IOI} \\
        \item \href{https://icpc.baylor.edu/}{ICPC} \\
        \item \href{https://tco17.topcoder.com/}{Topcoder Open} \\
        \item \href{https://code.google.com/codejam/}{Google Codejam} \\
        \item \href{https://www.facebook.com/hackercup/}{Facebook Hackercup} \\
        \item \href{https://www.codechef.com/snackdown/}{Codechef Snackdown} \\
    \end{itemize}
\end{frame}

\section{Conclusion}
\begin{frame}
    \frametitle{Thank you}
\end{frame}

\end{document}