r-causal / causal-inference-in-R

Causal Inference in R: A book!
https://www.r-causal.org/
165 stars 42 forks source link

Update 03-counterfactuals.qmd #245

Closed jakobschumacher closed 2 weeks ago

jakobschumacher commented 2 weeks ago

Changed "rbinom(10" to "rbinom(n()" to improve the code and make sure that it doesnt break when you use a different dataset.

People reading the book might to try your code on their dataset. They might get stuck at this part. With "n()" there is a good alternative to hardcoding "10". I am not completely sure that it does not have sideeffects - so better do a thorough check before you adopt the pull request.

malcolmbarrett commented 2 weeks ago

Agreed, this is better. It has the benefit you mention, but the bigger thing is that it's more maintainable for us (I wouldn't say we're trying to maximize the copy-pastability of the code)