Open vincentarelbundock opened 1 month ago
@malcolmbarrett requested an issue instead of a PR, so here is a copy of examples from the G-computation chapter I posted here: https://github.com/r-causal/causal-inference-in-R/pull/239
# A linear model for wait_minutes_posted_avg fit_wait_minutes <- lm( wait_minutes_posted_avg ~ park_extra_magic_morning + park_ticket_season + park_close + park_temperature_high, data = seven_dwarfs_9 ) avg_predictions( fit_wait_minutes, variables = "park_extra_magic_morning") park_extra_magic_morning Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 % 0 68.1 0.915 74.4 <0.001 Inf 66.3 69.9 1 74.2 2.052 36.2 <0.001 949.9 70.2 78.3 avg_predictions( fit_wait_minutes, hypothesis = "b2 - b1 = 0", variables = "park_extra_magic_morning") Term Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 % b2-b1=0 6.16 2.26 2.73 0.00636 7.3 1.74 10.6 fit_wait_minutes_actual <- lm( wait_minutes_actual_avg ~ ns(wait_minutes_posted_avg, df = 3) + park_extra_magic_morning + park_ticket_season + park_close + park_temperature_high, data = wait_times ) avg_predictions(fit_wait_minutes_actual, variables = list(wait_minutes_posted_avg = c(60, 30)) ) wait_minutes_posted_avg Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 % 60 29.8 7.05 4.23 <0.001 15.4 16.0 43.7 30 40.7 3.84 10.60 <0.001 84.8 33.2 48.2 avg_comparisons(fit_wait_minutes_actual, variables = list(wait_minutes_posted_avg = c(60, 30)) ) Term Contrast Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 % wait_minutes_posted_avg mean(60) - mean(30) -10.8 8.13 -1.33 0.182 2.5 -26.8 5.09
@malcolmbarrett requested an issue instead of a PR, so here is a copy of examples from the G-computation chapter I posted here: https://github.com/r-causal/causal-inference-in-R/pull/239