\documentclass[notitlepage]{article}
\usepackage{../../Math598}
\usepackage{listings}
\usepackage{numprint}
\usepackage{bbm}
\usepackage{amsfonts,amsmath}
\usepackage{fancyhdr}

\usepackage{lastpage}
\usepackage{enumitem}
\usepackage{bbold}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=blue,
    pdftitle={P2}    }

\usepackage{tikz}
\usetikzlibrary{shapes,decorations,arrows,calc,arrows.meta,fit,positioning}

\def\E{\Expect}


\lstloadlanguages{R}

\definecolor{keywordcolor}{rgb}{0,0.6,0.6}
\definecolor{delimcolor}{rgb}{0.461,0.039,0.102}
\definecolor{Rcommentcolor}{rgb}{0.101,0.043,0.432}

\lstdefinestyle{Rsettings}{
  basicstyle=\ttfamily,
  breaklines=true,
  showstringspaces=false,
  keywords={if, else, function, theFunction, tmp}, % Write as many keywords
  otherkeywords={},
  commentstyle=\itshape\color{Rcommentcolor},
  keywordstyle=\color{keywordcolor},
  moredelim=[s][\color{delimcolor}]{"}{"},
}

\lstset{basicstyle=\ttfamily, numbers=none, literate={~} {$\sim$}{2}}


\lfoot{MATH 598/782 Project \ExNumber} \cfoot{ } \rfoot{{\small{\em
Page \thepage \ of \pageref{LastPage}}}}


\pagestyle{empty}

\def\ExNumber{4}
\parindent 0in

\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}

\def\bU{\mathbf{U}}


\begin{document}
\pagestyle{fancy}

\begin{center}
{\textsclarge{MATH 598/782 -- Project \ExNumber }}

\bigskip

\textit{\textbf{Please submit your solutions by 11.59 pm (EDT) on Friday 12th April by uploading a single pdf to myCourses.}}

\end{center}

\bigskip


\tikzset{
    -Latex,auto,node distance =1 cm and 1 cm,semithick,
    state/.style ={circle, draw, minimum width = 0.7 cm},
    box/.style ={rectangle, draw, minimum width = 0.7 cm, fill=lightgray},
    point/.style = {circle, draw, inner sep=0.08cm,fill,node contents={}},
    bidirected/.style={Latex-Latex,dashed},
    el/.style = {inner sep=3pt, align=left, sloped}

}

The First Steps data
\begin{center}
\url{https://www.math.mcgill.ca/dstephens/598-Causal-2024/Exercises/Project4/FirstSteps_data.csv}
\end{center}
records the effect of a program aimed (amongst other things) at increasing the birthweight of a newborn in a low income household (variable \texttt{bwt}).  The treatment (exposure) is household participation in the program (binary variable \texttt{firststep}.  The data are observational, that is, allocation to the program is not performed using an experimental intervention. The data are studied in the in the following two papers

\begin{itemize}
  \item Alam S, Moodie EEM, Stephens DA. Should a propensity score model be super? The utility of ensemble procedures for causal adjustment. \textit{Statistics in Medicine}. 2019; 38: 1690–1702.

      \medskip

      A full description of the data is given in this paper.

      \bigskip

  \item Moodie EEM, Saarela O, Stephens DA. A doubly robust weighting estimator of the average treatment effect on the treated. \textit{Stat.} 2018;7:e205.
  
      \medskip
      \textbf{Update: my apologies, the analysis of the First Step program is not in the published version of the paper, but is in a technical report version.  In any case, the paper only investigates the ATT.}    
\end{itemize}


\begin{enumerate}[label=(\alph*)]

  \item The Alam et al. (2019) paper uses ``\textit{plasmode}'' simulation method to compare various ensemble and other machine learning approaches.  The plasmode approach takes an existing data set and simulates outcome data using the same covariate distribution as the real data set and a specified model.  One simple simulation is given below

<<p1a,comment='+', fig.width=4.8, fig.height=4.8, fig.align='center'>>=
fn<-"https://www.math.mcgill.ca/dstephens/598-Causal-2024/Exercises/Project4/FirstSteps_data.csv"
FS.data<-read.csv(fn)
n<-nrow(FS.data)

#Make a copy of data set
Copy.dat<-FS.data

#Code the discrete covariates
Copy.dat$sex_coded[Copy.dat$sex=="F"]<- 0
Copy.dat$sex_coded[Copy.dat$sex=="M"]<- 1

Copy.dat$race_coded[Copy.dat$race=="white"]<- 0
Copy.dat$race_coded[Copy.dat$race=="asian"]<- 1
Copy.dat$race_coded[Copy.dat$race=="hispanic" | Copy.dat$race=="other"
                  | Copy.dat$race=="black"]<- 3

Copy.dat$smoker_coded[Copy.dat$smoker=="N"]<- 0
Copy.dat$smoker_coded[Copy.dat$smoker=="Y"]<- 1

Copy.dat$drinker_coded[Copy.dat$drinker=="N"]<- 0
Copy.dat$drinker_coded[Copy.dat$drinker=="Y"]<- 1

Copy.dat$parity_coded[Copy.dat$parity==0]<- 0
Copy.dat$parity_coded[Copy.dat$parity==1]<- 1
Copy.dat$parity_coded[Copy.dat$parity>=2]<- 2

#Carry out a fit to the original data to get some realistic parameters.
fit.orig<-lm(bwt~firstep+sex+smoker,data=Copy.dat)
summary(fit.orig)$coef

be<-coef(fit.orig)
be[2]<-50          #Fix the treatment effect in an additive model at 50

set.seed(23)
Y<-be[1]+be[2]*Copy.dat$firstep+be[3]*Copy.dat$sex_coded+
         be[4]*Copy.dat$smoker_coded+rnorm(n)*summary(fit.orig)$sigma

Synth.data<- data.frame(sex=as.factor(Copy.dat$sex_coded),
                      age=Copy.dat$age,
                      race=as.factor(Copy.dat$race_coded),
                      parity=as.factor(Copy.dat$parity_coded),
                      married=Copy.dat$married, welfare=Copy.dat$welfare,
                      smoker=as.factor(Copy.dat$smoker_coded),
                      drinker=as.factor(Copy.dat$drinker_coded),
                      wpre=Copy.dat$wpre, edu=Copy.dat$edu,
                      firstep=Copy.dat$firstep, bwt=Y)

#Carry out a fit to the synthetic data
fit.synth<-lm(bwt~firstep+sex+smoker,data=Synth.data)
summary(fit.synth)$coef
@
Data sets can also be resampled (with replacement) from the original data to make a replicated analysis more realistic.

\medskip

Using a plasmode approach, carry out a replicated (Monte Carlo) simulation study that compares the performance of propensity score regression and inverse probability weighting approaches when, in the synthetic data generating model, \textbf{five} of the variables appear in the synthetic outcome model, and the treatment effect is presumed additive.  Assess whether these models can recover the true ATE from the synthetic data sets, and assess the variability of the resulting estimates.
\hfill{10 Marks}

\bigskip

\item For the \textbf{original} data, use the causal methods described through the course to estimate the ATE associated with the \texttt{firstep} treatment intervention.  Report the sampling variability (standard errors) of the estimates that you compute using the different causal adjustment methods.
\hfill{10 Marks}


\end{enumerate}


\end{document}
