Last active
December 31, 2020 03:22
-
-
Save kar9222/35bb254d1965dd92b87de64a15fc2734 to your computer and use it in GitHub Desktop.
Revisions
-
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,5 +68,5 @@ p_ve = ggplot() + stat_halfeye(aes(ve)) + wrap_plots(p_effect, p_log_odds, p_ve, ncol = 1) ```  -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,7 +62,7 @@ p_ve = ggplot() + stat_halfeye(aes(ve)) + geom_vline(xintercept = q_50/100) + geom_text(aes(q_50/100, .5, label = "Median VE: $q_50%"), hjust = -.1) + labs(title = """Pfizer study protocol defines VE = 1 - Pt/Pc 95% interval of effectiveness between $q_025% and $q_975%, compatible with model & data""", x = "Vaccine effectiveness", y = "Density") wrap_plots(p_effect, p_log_odds, p_ve, ncol = 1) -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,5 +68,5 @@ p_ve = ggplot() + stat_halfeye(aes(ve)) + wrap_plots(p_effect, p_log_odds, p_ve, ncol = 1) ```  -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,13 +56,13 @@ p_log_odds = ggplot() + stat_halfeye(aes(log_odds)) + Negative means less likely to get infected on treatment""", x = "Log odds", y = "Density") q_025, q_50, q_975 = round.(quantile(ve, [.025, .5, .975]) * 100, digits = 1) p_ve = ggplot() + stat_halfeye(aes(ve)) + geom_vline(xintercept = q_50/100) + geom_text(aes(q_50/100, .5, label = "Median VE: $q_50%"), hjust = -.1) + labs(title = """Pfizer study protocol defines VE = 1 - Pt/Pc 95% interval between $q_025% and $q_975%, compatible with model & data""", x = "Vaccine effectiveness", y = "Density") wrap_plots(p_effect, p_log_odds, p_ve, ncol = 1) -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,13 +56,13 @@ p_log_odds = ggplot() + stat_halfeye(aes(log_odds)) + Negative means less likely to get infected on treatment""", x = "Log odds", y = "Density") q_025, q_50, q_95 = round.(quantile(ve, [.025, .5, .95]) * 100, digits = 1) p_ve = ggplot() + stat_halfeye(aes(ve)) + geom_vline(xintercept = q_50/100) + geom_text(aes(q_50/100, .5, label = "Median VE: $q_50%"), hjust = -.1) + labs(title = """Pfizer study protocol defines VE = 1 - Pt/Pc 95% interval between $q_025% and $q_95%, compatible with model & data""", x = "Vaccine effectiveness", y = "Density") wrap_plots(p_effect, p_log_odds, p_ve, ncol = 1) -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Very briefly, from [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovi ```jl using Random, Distributions, Turing using RCall ; @rlibrary ggplot2 ; @rlibrary ggdist ; @rlibrary patchwork Random.seed!(1) -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Pfizer's vaccine effectiveness simulation Just for fun 😄. I saw this post about Pfizer's [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovik/692460). So I simply translate the Bayesian model (implemented in [Stan](https://mc-stan.org/)) into my favorite Julia library [Turing.jl](https://turing.ml/dev/). For details, please read the link. Very briefly, from [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovik/692460) > NYT reports a 44 thousand person trial with half of the people going to treatment and half to control. They further report that 162 people developed COVID in the control group and 8 where in the vaccine group. What is the probability that the vaccine is effective and what is the __uncertainty in that probability__? The Pfizer protocol defines vaccine effectiveness as follows: -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Pfizer's vaccine effectiveness simulation Just for fun. I saw this post about Pfizer's [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovik/692460). So I simply translate the Bayesian model (implemented in [Stan](https://mc-stan.org/)) into my favorite Julia library [Turing.jl](https://turing.ml/dev/). For details, please read the link. -
kar9222 revised this gist
Nov 20, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Pfizer vaccine effectiveness simulation Just for fun. I saw this post about Pfizer's [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovik/692460). So I simply translate the Bayesian model (implemented in [Stan](https://mc-stan.org/)) into my favorite Julia library [Turing.jl](https://turing.ml/dev/). For details, please read the link. -
kar9222 created this gist
Nov 20, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ # Pfizer Vaccine effectiveness simulation Just for fun. I saw this post about Pfizer's [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovik/692460). So I simply translate the Bayesian model (implemented in [Stan](https://mc-stan.org/)) into my favorite Julia library [Turing.jl](https://turing.ml/dev/). For details, please read the link. Very briefly, from [Vaccine Effectiveness Simulation](https://rpubs.com/ericnovik/692460) > NYT reports a 44 thousand person trial with half of the people going to treatment and half to control. They further report that 162 people developed COVID in the control group and 8 where in the vaccine group. What is the probability that the vaccine is effective and what is the __uncertainty in that probability__? The Pfizer protocol defines vaccine effectiveness as follows:  ```jl using Random, Distributions, Turing, DataFrames using RCall ; @rlibrary ggplot2 ; @rlibrary ggdist ; @rlibrary patchwork Random.seed!(1) # Model ------------------------------------------ # Numbers of volunteers, events in control, events in vaccine group, respectively n, r_c, r_t = 4.4*10^4, 162, 8 n_c = n_t = n/2 @model PfizerVaccineEffectiveness(r_c, r_t) = begin # No prior beliefs for effectiveness p_c ~ Beta(1, 1) p_t ~ Beta(1, 1) r_c ~ Binomial(n_c, p_c) r_t ~ Binomial(n_t, p_t) # Generated quantities effect = (p_t-p_c)*10^4 # Treatment effect ve = 1 - p_t/p_c # Vaccine effectiveness log_odds = log(p_t / (1-p_t)) - log(p_c / (1-p_c)) return (effect, ve, log_odds) end N, n_chn, sampler_ = 10^4, 4, NUTS() model = PfizerVaccineEffectiveness(r_c, r_t) c = sample(model, sampler_, N) # Plot ------------------------------------------- vals = generated_quantities(model, c) effect, ve, log_odds = [getfield.(vals, i)[:] for i in 1:length(vals[1])] p_effect = ggplot() + stat_halfeye(aes(effect)) + labs(title = "Reduction in infections on treatment per 10,000 people", x = "Size of effect", y = "Density") p_log_odds = ggplot() + stat_halfeye(aes(log_odds)) + labs(title = """Log odds of treatment effect. Negative means less likely to get infected on treatment""", x = "Log odds", y = "Density") q_5, q_50, q_90 = round.(quantile(ve, [.025, .5, .95]) * 100, digits = 1) p_ve = ggplot() + stat_halfeye(aes(ve)) + geom_vline(xintercept = q_50/100) + geom_text(aes(q_50/100, .5, label = "Median VE: $q_50%"), hjust = -.1) + labs(title = """Pfizer study protocol defines VE = 1 - Pt/Pc 95% interval between $q_5% and $q_90%, compatible with model & data""", x = "Vaccine effectiveness", y = "Density") wrap_plots(p_effect, p_log_odds, p_ve, ncol = 1) ``` 