Skip to content

Commit

Permalink
rmarkdown::render_site(output_format = 'bookdown::pdf_book', encoding…
Browse files Browse the repository at this point in the history
… = 'UTF-8')
  • Loading branch information
remlapmot committed Nov 13, 2024
1 parent 88ba534 commit f72866d
Show file tree
Hide file tree
Showing 25 changed files with 105 additions and 142 deletions.
Binary file modified data/fig1.dta
Binary file not shown.
Binary file modified data/fig2.dta
Binary file not shown.
Binary file modified data/fig3.dta
Binary file not shown.
Binary file modified data/nhefs-formatted.dta
Binary file not shown.
Binary file modified data/nhefs-highprice.dta
Binary file not shown.
Binary file modified data/nhefs-ps.dta
Binary file not shown.
Binary file modified data/nhefs-wcens.dta
Binary file not shown.
Binary file modified data/nhefs_std.dta
Binary file not shown.
Binary file modified data/nhefs_std1.dta
Binary file not shown.
Binary file modified data/nhefs_std2.dta
Binary file not shown.
Binary file modified data/nhefs_surv.dta
Binary file not shown.
Binary file modified data/observe.mmat
Binary file not shown.
12 changes: 9 additions & 3 deletions docs/11-why-model-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Y <- c(200, 150, 220, 110, 50, 180, 90, 170, 170, 30,
plot(A, Y)
```

<img src="11-why-model-r_files/figure-epub3/unnamed-chunk-1-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{11-why-model-r_files/figure-latex/unnamed-chunk-1-1} \end{center}

``` r
summary(Y[A == 0])
Expand All @@ -35,7 +37,9 @@ Y2 <- c(110, 80, 50, 40, 170, 30, 70, 50, 110, 50, 180,
plot(A2, Y2)
```

<img src="11-why-model-r_files/figure-epub3/unnamed-chunk-1-2.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{11-why-model-r_files/figure-latex/unnamed-chunk-1-2} \end{center}

``` r
summary(Y2[A2 == 1])
Expand Down Expand Up @@ -69,7 +73,9 @@ Y3 <-
plot(Y3 ~ A3)
```

<img src="11-why-model-r_files/figure-epub3/unnamed-chunk-2-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{11-why-model-r_files/figure-latex/unnamed-chunk-2-1} \end{center}

``` r

Expand Down
15 changes: 10 additions & 5 deletions docs/11-why-model-stata.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ bysort A: sum Y
Y | 8 146.25 58.2942 50 220
```

<img src="figs/stata-fig-11-1.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{figs/stata-fig-11-1} \end{center}


``` stata
Expand Down Expand Up @@ -197,7 +198,8 @@ bysort A: sum Y
Y | 4 195 31.09126 150 220
```

<img src="figs/stata-fig-11-2.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{figs/stata-fig-11-2} \end{center}


``` stata
Expand Down Expand Up @@ -250,7 +252,8 @@ qui gr export figs/stata-fig-11-3.png, replace
17. end
```

<img src="figs/stata-fig-11-3.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{figs/stata-fig-11-3} \end{center}

## Program 11.2

Expand Down Expand Up @@ -294,7 +297,8 @@ qui gr export figs/stata-fig-11-4.png, replace
------------------------------------------------------------------------------
```

<img src="figs/stata-fig-11-4.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{figs/stata-fig-11-4} \end{center}


``` stata
Expand Down Expand Up @@ -361,4 +365,5 @@ qui gr export figs/stata-fig-11-5.png, replace
------------------------------------------------------------------------------
```

<img src="figs/stata-fig-11-5.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{figs/stata-fig-11-5} \end{center}
22 changes: 11 additions & 11 deletions docs/13-stand-gformula-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ nhefs[which(nhefs$seqn == 24770), c(
"active",
"wt71"
)]
#> # A tibble: 1 × 11
#> # A tibble: 1 x 11
#> predicted.meanY qsmk sex race age education smokeintensity smokeyrs
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.342 0 0 0 26 4 15 12
#> # 3 more variables: exercise <dbl>, active <dbl>, wt71 <dbl>
#> # i 3 more variables: exercise <dbl>, active <dbl>, wt71 <dbl>

summary(nhefs$predicted.meanY[nhefs$cens == 0])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
Expand Down Expand Up @@ -344,14 +344,14 @@ bootstrap <-
ul
))
bootstrap
#> V1 mean se ll
#> 1 Observed 2.56188497106099 0.0549704676078034 2.45414483433637
#> 2 No Treatment 1.65212306626744 0.143266399330196 1.37132608338552
#> 3 Treatment 5.11474489549336 0.38239206319866 4.36527022365002
#> 4 Treatment - No Treatment 3.46262182922592 0.508889999498158 2.46521575811692
#> V1 mean se ll
#> 1 Observed 2.56188497106099 0.120597104489459 2.32551898962183
#> 2 No Treatment 1.65212306626744 0.106947069654509 1.4425106614925
#> 3 Treatment 5.11474489549336 0.358814454471498 4.41148148759683
#> 4 Treatment - No Treatment 3.46262182922592 0.392348048118945 2.6936337855082
#> ul
#> 1 2.66962510778561
#> 2 1.93292004914935
#> 3 5.86421956733669
#> 4 4.46002790033492
#> 1 2.79825095250014
#> 2 1.86173547104237
#> 3 5.81800830338988
#> 4 4.23160987294364
```
26 changes: 15 additions & 11 deletions docs/15-prop-scores-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ ggplot(nhefs, aes(x = ps, fill = qsmklabel, color = qsmklabel)) +
legend.title = element_blank())
```

<img src="15-prop-scores-r_files/figure-epub3/unnamed-chunk-3-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{15-prop-scores-r_files/figure-latex/unnamed-chunk-3-1} \end{center}

``` r

Expand All @@ -345,7 +347,9 @@ ggplot(nhefs, aes(x = ps, fill = as.factor(qsmk), color = as.factor(qsmk))) +
theme(legend.position = 'bottom', legend.direction = 'vertical')
```

<img src="15-prop-scores-r_files/figure-epub3/unnamed-chunk-3-2.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{15-prop-scores-r_files/figure-latex/unnamed-chunk-3-2} \end{center}


``` r
Expand Down Expand Up @@ -732,15 +736,15 @@ bootstrap <- data.frame(cbind(c("Observed", "No Treatment", "Treatment",
"Treatment - No Treatment"), mean, se, ll, ul))
bootstrap
#> V1 mean se ll
#> 1 Observed 2.63384609228479 0.238861089903915 2.16568695876514
#> 2 No Treatment 1.71983636149845 0.197112530909323 1.33350290001464
#> 3 Treatment 5.35072300362985 0.587017349690794 4.20019013993574
#> 4 Treatment - No Treatment 3.6308866421314 0.592573338393775 2.46946424068094
#> 1 Observed 2.63384609228479 0.279890742231742 2.0852703179044
#> 2 No Treatment 1.71983636149845 0.275568960869064 1.17973112293796
#> 3 Treatment 5.35072300362985 0.314161588160568 4.73497760550923
#> 4 Treatment - No Treatment 3.6308866421314 0.451854865413406 2.74526737968193
#> ul
#> 1 3.10200522580445
#> 2 2.10616982298226
#> 3 6.50125586732396
#> 4 4.79230904358186
#> 1 3.18242186666519
#> 2 2.25994160005895
#> 3 5.96646840175047
#> 4 4.51650590458087
```


Expand Down Expand Up @@ -833,7 +837,7 @@ for(i in 1:nboot) {
}
}
#> 95% CI for the causal mean difference
#> 2.679491 , 4.442331
#> 2.714556 , 4.383686
```

A more flexible and elegant way to do this is to write a function to perform the model fitting, prediction, bootstrapping, and reporting all at once.
3 changes: 2 additions & 1 deletion docs/15-prop-scores-stata.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ Log likelihood = -838.44842 Pseudo R2 = 0.0611
file ./data/nhefs-ps.dta saved
```

<img src="./figs/stata-fig-15-2.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{./figs/stata-fig-15-2} \end{center}

## Program 15.3

Expand Down
16 changes: 12 additions & 4 deletions docs/17-causal-surv-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ ggsurvplot(fit, data = nhefs, xlab="Months of follow-up",
fontsize = 3)
```

<img src="17-causal-surv-r_files/figure-epub3/unnamed-chunk-2-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{17-causal-surv-r_files/figure-latex/unnamed-chunk-2-1} \end{center}

## Program 17.2

Expand Down Expand Up @@ -137,7 +139,9 @@ ggplot(hazards.graph, aes(x=time, y=surv)) +
theme(legend.position="bottom")
```

<img src="17-causal-surv-r_files/figure-epub3/unnamed-chunk-3-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{17-causal-surv-r_files/figure-latex/unnamed-chunk-3-1} \end{center}

## Program 17.3

Expand Down Expand Up @@ -234,7 +238,9 @@ ggplot(ipw.graph, aes(x=time, y=surv)) +
theme(legend.position="bottom")
```

<img src="17-causal-surv-r_files/figure-epub3/unnamed-chunk-4-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{17-causal-surv-r_files/figure-latex/unnamed-chunk-4-1} \end{center}

## Program 17.4

Expand Down Expand Up @@ -350,7 +356,9 @@ ggplot(gf.graph, aes(x=time, y=surv)) +
theme(legend.position="bottom")
```

<img src="17-causal-surv-r_files/figure-epub3/unnamed-chunk-5-1.png" width="85%" style="display: block; margin: auto;" />


\begin{center}\includegraphics[width=0.85\linewidth]{17-causal-surv-r_files/figure-latex/unnamed-chunk-5-1} \end{center}

## Program 17.5

Expand Down
20 changes: 12 additions & 8 deletions docs/17-causal-surv-stata.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Observed time interval: (0, survtime]
Analysis time _t: survtime
```

<img src="./figs/stata-fig-17-1.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{./figs/stata-fig-17-1} \end{center}

## Program 17.2

Expand Down Expand Up @@ -278,7 +279,8 @@ psurv0 float %9.0g psurv, interv == Original observat
psurv1 float %9.0g psurv, interv == Duplicated observation
```

<img src="./figs/stata-fig-17-2.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{./figs/stata-fig-17-2} \end{center}

## Program 17.3

Expand Down Expand Up @@ -620,15 +622,15 @@ psurv1 float %9.0g psurv, interv == Duplicated observ
26. drop if newseqn != 1 /* only need one pair */
27.
r; t=0.00 6:43:12
r; t=0.00 8:25:46
Command: bootipw_surv
PrY_a0: r(boot_0)
PrY_a1: r(boot_1)
difference: r(boot_diff)
Simulations (10): .........10 done
r; t=19.98 6:43:32
r; t=20.55 8:26:06
Expand All @@ -646,7 +648,8 @@ Bootstrap results Number of obs = 1,629
------------------------------------------------------------------------------
```

<img src="./figs/stata-fig-17-3.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{./figs/stata-fig-17-3} \end{center}

## Program 17.4

Expand Down Expand Up @@ -866,15 +869,15 @@ file /Users/tom/Documents/GitHub/cibookex-r/figs/stata-fig-17-4.png saved as PNG
5. drop if time != 0
6. /*only predict on new version of data */
r; t=0.00 6:43:39
r; t=0.00 8:26:13
Command: bootstdz_surv
PrY_a0: r(boot_0)
PrY_a1: r(boot_1)
difference: r(boot_diff)
Simulations (10): .........10 done
r; t=23.62 6:44:03
r; t=25.24 8:26:39
Expand All @@ -892,4 +895,5 @@ Bootstrap results Number of obs = 1,629
------------------------------------------------------------------------------
```

<img src="./figs/stata-fig-17-4.png" width="85%" style="display: block; margin: auto;" />

\begin{center}\includegraphics[width=0.85\linewidth]{./figs/stata-fig-17-4} \end{center}
6 changes: 3 additions & 3 deletions docs/18-session-info-r.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For reproducibility.
``` r
# install.packages("sessioninfo")
sessioninfo::session_info()
#> Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> - Session info -------------------------------------------------------------------------------------------------------------------------------------------
#> setting value
#> version R version 4.4.2 (2024-10-31)
#> os macOS Sequoia 15.1
Expand All @@ -20,7 +20,7 @@ sessioninfo::session_info()
#> date 2024-11-13
#> pandoc 3.5 @ /opt/homebrew/bin/ (via rmarkdown)
#>
#> Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> - Packages -----------------------------------------------------------------------------------------------------------------------------------------------
#> package * version date (UTC) lib source
#> bookdown 0.41 2024-10-16 [1] CRAN (R 4.4.1)
#> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.0)
Expand All @@ -38,5 +38,5 @@ sessioninfo::session_info()
#> [1] /Users/tom/Library/R/arm64/4.4/library
#> [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> ----------------------------------------------------------------------------------------------------------------------------------------------------------
```
6 changes: 3 additions & 3 deletions docs/18-session-info-stata.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Serial number: 501809305331
``` r
# install.packages("sessioninfo")
sessioninfo::session_info()
#> Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> - Session info -------------------------------------------------------------------------------------------------------------------------------------------
#> setting value
#> version R version 4.4.2 (2024-10-31)
#> os macOS Sequoia 15.1
Expand All @@ -42,7 +42,7 @@ sessioninfo::session_info()
#> date 2024-11-13
#> pandoc 3.5 @ /opt/homebrew/bin/ (via rmarkdown)
#>
#> Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> - Packages -----------------------------------------------------------------------------------------------------------------------------------------------
#> package * version date (UTC) lib source
#> bookdown 0.41 2024-10-16 [1] CRAN (R 4.4.1)
#> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.0)
Expand All @@ -61,5 +61,5 @@ sessioninfo::session_info()
#> [1] /Users/tom/Library/R/arm64/4.4/library
#> [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> ----------------------------------------------------------------------------------------------------------------------------------------------------------
```
Binary file modified docs/cibookex-r.pdf
Binary file not shown.
Loading

0 comments on commit f72866d

Please sign in to comment.