\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{ps.fit.i}\hlkwb{<-}\hlkwd{fitted}\hlstd{(}\hlkwd{glm}\hlstd{(Z}\hlopt{~}\hlstd{X1,}\hlkwc{family}\hlstd{=binomial))}
\hlstd{ps.quint.fit.i}\hlkwb{<-}\hlkwd{quantile}\hlstd{(ps.fit.i,}\hlkwc{probs}\hlstd{=}\hlkwd{seq}\hlstd{(}\hlnum{0}\hlstd{,}\hlnum{1}\hlstd{,}\hlkwc{by}\hlstd{=}\hlnum{1}\hlopt{/}\hlstd{nstrata))}
\hlstd{ps.quint.fit.i}
\end{alltt}
\begin{verbatim}
+        0%       20%       40%       60%       80%      100% 
+ 0.5576018 0.6141654 0.6313289 0.6432823 0.6594991 0.7163560
\end{verbatim}
\begin{alltt}
\hlstd{ps.strat.fit.i}\hlkwb{<-}\hlkwd{as.numeric}\hlstd{(}\hlkwd{cut}\hlstd{(ps.fit.i,ps.quint.fit.i,}\hlkwc{include.lowest}\hlstd{=}\hlnum{TRUE}\hlstd{))}
\hlkwd{table}\hlstd{(Z,ps.strat.fit.i)}
\end{alltt}
\begin{verbatim}
+    ps.strat.fit.i
+ Z     1   2   3   4   5
+   0  70  83  85  75  50
+   1 130 117 115 125 150
\end{verbatim}
\begin{alltt}
\hlstd{mu.strat.fit.i}\hlkwb{<-}\hlkwd{matrix}\hlstd{(}\hlnum{0}\hlstd{,}\hlkwc{ncol}\hlstd{=nstrata,}\hlkwc{nrow}\hlstd{=}\hlnum{3}\hlstd{)}
\hlkwa{for}\hlstd{(j} \hlkwa{in} \hlnum{1}\hlopt{:}\hlstd{nstrata)\{}
    \hlstd{mu.strat.fit.i[}\hlnum{1}\hlstd{,j]}\hlkwb{<-}\hlkwd{mean}\hlstd{(Y[Z}\hlopt{==}\hlnum{0} \hlopt{&} \hlstd{ps.strat.fit.i} \hlopt{==} \hlstd{j])}
    \hlstd{mu.strat.fit.i[}\hlnum{2}\hlstd{,j]}\hlkwb{<-}\hlkwd{mean}\hlstd{(Y[Z}\hlopt{==}\hlnum{1} \hlopt{&} \hlstd{ps.strat.fit.i} \hlopt{==} \hlstd{j])}
    \hlstd{mu.strat.fit.i[}\hlnum{3}\hlstd{,j]}\hlkwb{<-}\hlstd{mu.strat.fit.i[}\hlnum{2}\hlstd{,j]}\hlopt{-}\hlstd{mu.strat.fit.i[}\hlnum{1}\hlstd{,j]}
\hlstd{\}}
\hlstd{mu.strat.fit.i}
\end{alltt}
\begin{verbatim}
+           [,1]      [,2]      [,3]     [,4]       [,5]
+ [1,]  4.337441  4.285596  4.278122  4.27935  4.2557960
+ [2,]  1.986344  2.266358  2.478530  3.02608  3.8558912
+ [3,] -2.351097 -2.019238 -1.799591 -1.25327 -0.3999048
\end{verbatim}
\begin{alltt}
\hlkwd{apply}\hlstd{(mu.strat.fit.i,}\hlnum{1}\hlstd{,mean)}
\end{alltt}
\begin{verbatim}
+ [1]  4.287261  2.722641 -1.564620
\end{verbatim}
\end{kframe}
\end{knitrout}