\documentclass[12pt]{article}
\usepackage{ amssymb, amsmath, bm, graphicx }
\addtolength{\textheight}{1.6in}
\addtolength{\topmargin}{-0.75in}
\addtolength{\textwidth}{1.6in}
\addtolength{\evensidemargin}{-0.8in}
\addtolength{\oddsidemargin}{-0.9in}
\setlength{\parskip}{0.1in}
\setlength{\parindent}{0.0in}
\raggedbottom
\newcommand{\given}{\, | \,}
\begin{document}
\begin{flushleft}
University of California, Santa Cruz \\
Department of Applied Mathematics and Statistics \\
Baskin School of Engineering
\end{flushleft}
\Large
\begin{center}
AMS 206 (\textsf{Applied Bayesian Statistics})
\textbf{Incorporating .pdf Plots Into \texttt{LaTeX}}
\end{center}
\normalsize
In an \texttt{R} tutorial on the course web page, I showed you how to use the \texttt{pdf} function in \texttt{R} to spool a plot into a \texttt{.pdf} file; here's an example of how to incorporate such plots into a \texttt{LaTeX} document.
Table \ref{t:r-code} presents the \texttt{R} code used to make the plot presented below and illustrates the use of the \texttt{table} environment in \texttt{LaTeX}. Let's suppose that you have a directory called \texttt{AMS-206} in which you keep all of your files for this course.
\begin{table}[h!]
\centering
\caption{\textit{\texttt{R} code to create the plot incorporated into this document.}}
\begin{quote}
\begin{verbatim}
# code to illustrate various aspects of plotting functions in R
#
# here you would use a setwd command (or the `Change dir...' option
# from the File pull-down menu in R) to ensure that the .pdf file
# is stored in your directory AMS-206
#
p <- seq( 0.001, 0.999, length = 500 )
plot( p, log( p / ( 1 - p ) ), type = 'l', lwd = 2,
ylab = 'logit( p ) = log( p / ( 1 - p ) )' )
text( 0.4, 4.0, 'this is the logistic or logit transformation;' )
text( 0.4, 3.25, 'it maps probabilities onto the whole real line' )
lines( p, 4 * p - 2, lty = 2, lwd = 2, col = 'red' )
text( 0.6, -4.0, "it's approximately linear for p in ( 0.3, 0.7 )" )
#
# use this code to make a PDF file to incorporate into your Latex document
#
pdf( 'ams-206-logit-plot.pdf' )
plot( p, log( p / ( 1 - p ) ), type = 'l', lwd = 2,
ylab = 'logit( p ) = log( p / ( 1 - p ) )' )
text( 0.4, 4.0, 'this is the logistic or logit transformation;' )
text( 0.4, 3.25, 'it maps probabilities onto the whole real line' )
lines( p, 4 * p - 2, lty = 2, col = 'red' )
text( 0.6, -4.0, "it's approximately linear for p in ( 0.3, 0.7 )" )
dev.off( )
\end{verbatim}
\end{quote}
\label{t:r-code}
\end{table}
Figure \ref{f:logit-transformation} displays the \texttt{.pdf} graph created with the \texttt{R} code in Table \ref{t:r-code}. To use the \texttt{includegraphics} command in \texttt{LaTeX}, you'll need to include the
\texttt{graphicx} package in the \texttt{usepackage} specification in the preamble of your \texttt{LaTeX} document (the second line of \texttt{LaTeX} code in this document).
\begin{figure}[t!]
\centering
\caption{\textit{A plot of logit$( p )$ against $p$, to examine its nonlinearity.}}
\vspace*{-0.1in}
\includegraphics[ scale = 0.7 ]{ams-206-logit-plot.pdf}
\vspace*{-0.1in}
\label{f:logit-transformation}
\end{figure}
\begin{table}[t!]
\centering
\caption{\textit{\texttt{Maple} code to work out the Taylor expansion of logit$( p )$ around $p = 0.5$ to third order.}}
\begin{quote}
\begin{verbatim}
help( taylor );
taylor( log( p / ( 1 - p ) ), p = 0.5, 3 );
4.000000000 ( p - 0.5 ) + O[ ( p - 0.5 )^3 ]
\end{verbatim}
\end{quote}
\label{t:maple-code}
\end{table}
Table \ref{t:maple-code} gives \texttt{Maple} code that computes the linear Taylor expansion used to plot the dotted line in Figure \ref{f:logit-transformation}. You can see that there is no quadratic term in this expansion; this explains why the linear approximation is so good over such a wide range of values of $p$.
\end{document}