% From kass@stat.cmu.edu Wed Aug 21 16:28:00 2002
% Date: Fri, 16 Aug 2002 16:50:17 -0400
% From: Rob Kass <kass@stat.cmu.edu>
% To: brian@stat.cmu.edu
% Subject: depression HW
% 
\documentclass[12pt]{article}
\usepackage{times}
\oddsidemargin 0in 
\evensidemargin 0in 
\textwidth 6.7in 
\topmargin -0.5in 
\headsep 0in 
\textheight 9.2in 
\parindent 0in 
\begin{document}
\begin{center}
\Large\bf 
36-711 HW01: Due Friday September 6, 2002\\
Treating Depression: A Randomized Clinical Trial
\end{center}

The data set {\tt depression.dat}, available in the data area of the
711 website, contains data from a multicenter clinical trial to study
treatment of depression by various drugs.  We will use this data set
to explore working with Splus/R.  


\vspace*{.2in}\noindent
The study design was as
follows:
\begin{itemize}
\item There were 5 medical clinics across the country that participated in
this trial. Using many clinics enables the investigators to enroll
many more patients into the study and allows for a diversity of
patients to participate. 

\item There were 3 treatment groups.  Patients
received either Imipramine (Imip), Lithium (Li), or a Placebo (Pl).
Imip and Li are active drugs. Patients were randomized to one of the 3
treatment groups, using a random device (like rolling a 3 sided die).

\item Patients were followed from 2-4 years to see whether or not they had a
recurrence of depression. If they did not have a recurrence within
this time frame, then their treatment was considered a Success. If
they did have a recurrence, it was considered a Failure. The study was
double-blinded. 

\item A number of additional background variables were
measured for each patient. 

\end{itemize}

\underline{\bf The variables in the data set are}:

\vspace{.2in}
\begin{tabular}{ll}
{\sc hospt} & Which hospital: 1, 2, 3, 5 or 6.\vspace{.1in} \\

{\sc treat} & 0={\em Lithium}; 1={\em Imipramine}; 2={\em Placebo}.
\vspace{.1in}\\


{\sc outcome}& 0={\em Success}\\  
 &1={\em Failure} (recurrence of depression) \vspace{.1in}\\


{\sc time} & number of weeks until a recurrence\\ 
 & (if {\sc outcome=1}) or until study ended\\
 & (if {\sc outcome=0})\vspace{.1in}\\


{\sc AcuteT} & How many days the patient was depressed\\
 &  before the start of the study \vspace{.1in}\\

{\sc age} & Age in years \vspace{.1in}\\

{\sc gender} & 1={\em Female}  2={\em Male}.


\end{tabular}\\[.25in]

Read the data into Splus using a command like 
\begin{verbatim}
> depr <- read.table("depression.dat",header=T)
\end{verbatim}
and then do the exercises starting on the next page of this hw.
(Remember to use {\tt help()} and {\tt help.start()} often.  Also,
remember that your data and functions are saved from one session to
the next in Splus.)

\clearpage

{\em 

{\bf Note:} For this assignment, please turn in a paper copy of
  your Splus work, annotated to indicate what problem you are working
  on, answer any questions in text that need answering, etc.  Attach
  paper copies of graphs at the end of your hw.  Example of
  ``Annotated Splus output'':
\begin{center}
\begin{tabular}{|p{6.2in}|}
\hline\small
\begin{verbatim}
Brian Junker
36-711 Statistical Computing
HW 1 -- Due Sep 6 2002

READING IN THE DATA

> depr <- read.table("depression.dat",header=T)

PROBLEM #1:

> names(depr)
[1] "Hospt"  "Treat"  "Outcome"  "Time"  "AcuteT"  "Age"  "Gender"
> dim(depr)
[1] 109   7
The result of the ``dim'' function shows that my ``depr'' data frame
has 109 rows (observations) and 7 columns (variables), as expected.
The ``names'' command shows the names of the columns (variables) and
they are what I expected.

PROBLEM #2:

...
\end{verbatim}\\
\hline
\end{tabular}
\end{center}
You can prepare this file by cutting and pasting from your Splus
window into emacs, and adding annotations in emacs.  Use ``enscript''
to print it out.

}

\begin{enumerate}

\item {\bf [Not to be graded.]} Use the {\tt names()}. {\tt
    dimnames()} and {\tt dim()} functions in Splus to verify the
  following:
\begin{itemize}
\item There are 109 observations and 7 variables.
\item The variable names are ``Hospt'', ``Treat'',   ``Outcome'', ``Time'',
   ``AcuteT'', ``Age'', and ``Gender''.
\end{itemize}

\item Use {\tt summary()}  to produce a summary of each variable in the
  data set.  
\begin{itemize}
\item You can also use {\tt sqrt(var())} to produce standard
  deviations if you wish.  
\item You can do each summary by hand, e.g. {\tt summary(depr\$Hospt)}, or\\
  {\tt summary(depr\$Treat)}, etc., or you can experiment with a
  ``for'' loop:
\begin{verbatim}
for (i in names(depr)) {
   print(summary(depr[,i]))
}
\end{verbatim}
\end{itemize}

\item For ``Time'', ``AcuteT'', and ``Age'' the summaries you just produced
  make sense.  For the other variables they do not, really.
\begin{enumerate}
\item Why not?
\item For the other five variables try {\tt table()} or {\tt
    summary(as.factor())}.  What do you learn from these summaries?
\end{enumerate}

\item Use {\tt search()} to find out what databases you have access to
  in your Splus session.  Use {\tt attach()} to attach the depression
  data.frame as a data base.  Use {\tt search()} again to see where
  the depression data is now.

\item Produce stem and leaf plots of the three continuous variables,
  using {\tt stem()}.  Since you have attached the depression data,
  you won't have to type so much.

\item Use {\tt motif()} (or in R use {\tt x11()}) to open a graphics
  window.  Use {\tt par(mfrow=c(2,2))} to divide the window into four
  subgraphs.  Make histograms of each of the continuous variables,
  using {\tt hist()} and {\tt title()} once for each graph (use the
  title to give a short description of each variable, e.g. ``Time'' is
  ``Time to recurrence or study end'', etc.).  Print the result (three
  histograms on one page) out, to be turned in [use the Graph...Print
  menu in the graphics window; you may have to set print options with
  the Options menu there first].

\item How are treatments distributed across hospitals?  use {\tt
  table(Hospt, Treat)} to find out.  Now try {\tt
  table(Hospt,Outcome,Treat)}.  Do some treatments work better at some
  hospitals?  

  {\em This may require some side calculation.  A quick way to do the side
  calculation is 
\begin{verbatim}
> bozo _ table(Hospt,Outcome,Treat)
> for (i in 1:3) bozo[,,i] _ bozo[,,i]/apply(bozo[,,i],1,sum)
> round(bozo,2)
\end{verbatim}
  Play around with the pieces of this (and consult {\tt help()}, etc.)
  and describe what each piece of this calculation does.}

\item Are the times to recurrence of depression the same across the
  hospitals?  Use {\tt par(mfrow=c(1,1))} to use the whole graphics
  window for a single plot, and then make parallel boxplots of {\tt
    Time} using either
\begin{itemize}
\item {\tt plot(as.factor(Hospt),Time,xlab="Hospital",ylab="Time")}
  ~~~~ or
\item {\tt boxplot(split(Time,Hospt),xlab="Hospital",ylab="Time")}
\end{itemize}
Print the graph and turn it in. {\em 
What other relations would be interesting to explore this way?}

\item It might be interesting to explore the relationship between {\tt
    AcuteT} and {\tt Time} at each hospital.  For example, {\tt
    plot(AcuteT[Hospt==1],Time[Hospt==1])} would show this for Hospital
    1.  Make a single plot with six subplots showing this relationship
    for each of the (five!) hospitals in the data set, print it out,
    and turn it in.   {\em 
What other relations would be interesting to explore this way?}


\end{enumerate}

\end{document}





