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 characters
| rm(list = ls()) | |
| library(tidyverse) | |
| library(readr) | |
| library(ggthemes) | |
| library(lubridate) | |
| library(zoo) | |
| library(gganimate) | |
| getwd() | |
| data_folder <- file.path("C:/Users/marcj/Nutreco/StatisticsPlatform/Website/ELearning/Workshops/CausalAnalysis/Covid/") | |
| url <- "https://covid.ourworldindata.org/data/owid-covid-data.csv" |
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 characters
| rm(list = ls()) | |
| library(tidyverse) | |
| library(readr) | |
| library(ggthemes) | |
| library(lubridate) | |
| library(zoo) | |
| getwd() | |
| data_folder <- file.path("") | |
| url <- "https://covid.ourworldindata.org/data/owid-covid-data.csv" | |
| name <- "owid-covid-data.csv" |
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 characters
| library(readxl) | |
| library(ggplot2) | |
| library(viridis) | |
| library(tidyverse) | |
| UK <- read_excel("referencetable.xlsx", sheet = "Table 7", skip = 4, n_max = 350) | |
| UK$Mortality.age.std=as.numeric(UK$Mortality.age.std) | |
| UK$Lower.limit=as.numeric(UK$Lower.limit) | |
| UK$Upper.limit=as.numeric(UK$Upper.limit) | |
| mynamestheme=theme(plot.title=element_text(face="bold",size=(15))) | |
| UK.covid <- read_excel("referencetable.xlsx", sheet = "Table 5", skip = 4, n_max = 350) |
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 characters
| proc sort data=try2 out=Work.preProcessedData;by date;run; | |
| proc varmax data=Work.preProcessedData plots(only)=(forecasts impulse model residual) | |
| outest=work.outest covout outstat=work.outstat; | |
| id date interval=day; | |
| where '22MAR2020'd <= date <= '9DEC2021'd; | |
| model | |
| grocery_and_pharmacy | |
| parks | |
| residential | |
| retail_and_recreation |
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 characters
| /* LETS LOOK AT THE WORLD DATA */ | |
| FILENAME REFFILE '/Data/owid-covid-data.xlsx'; | |
| PROC IMPORT DATAFILE=REFFILE DBMS=XLSX OUT=WORK.IMPORT;GETNAMES=YES;RUN; | |
| proc freq data=import nlevels;table date;run; | |
| proc freq data=import nlevels;table location;run; | |
| data import; set import; | |
| new = input(date,yymmdd10.); | |
| drop date; | |
| rename new=date; | |
| run; |
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 characters
| options(mc.cores=parallel::detectCores()) | |
| model4<- stan_glmer( | |
| ADG~ADF + | |
| Challenge + | |
| Included2017 + | |
| BW_start+Country+ | |
| n_start+ | |
| (ADF|Studycode), | |
| data = d, family = gaussian, |
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 characters
| predictions_complete <- posterior_predict(model3,newdata = d) | |
| ppc_intervals(d$ADG, | |
| yrep = predictions_complete, | |
| prob_outer = 0.80) + | |
| ggplot2::facet_grid(~d$Studycode, scales="free")+ | |
| xaxis_text(angle = 90, hjust = 1) |
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 characters
| Book<- read_excel("X:/StatisticsPlatform/Website/ELearning/Workshops/Bayesian Analysis/Data/Book1.xlsx") | |
| d<-Book%>%dplyr::select(ADG,ADF,Country,Days,BW_start,n_start,Challenge,Studycode,Included2017) | |
| d<-d[complete.cases(d), ] | |
| d$Studycode<-as.factor(d$Studycode) | |
| d$Challenge<-as.factor(d$Challenge) | |
| d$Country<-as.factor(d$Country) | |
| model3<- stan_glmer( | |
| ADG~ADF + |
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 characters
| posterior_interval(model2, prob = 0.80) | |
| d %>% | |
| add_fitted_draws(model2, n = 20) %>% | |
| ggplot(aes(x = ADF, y = ADG)) + | |
| geom_line(aes(y = .value, group = paste(Studycode, .draw))) + | |
| facet_wrap(~ .draw) +theme_bw() | |
| d %>% | |
| add_predicted_draws(model2, n = 100) %>% | |
| ggplot(aes(x = ADF)) + | |
| geom_density(aes(x = .prediction, group = .draw)) + |
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 characters
| predictions <- posterior_predict(model2, newdata = d) | |
| ppc_intervals(d$ADG, | |
| yrep = predictions, | |
| x = d$ADF, | |
| prob = 0.5, prob_outer = 0.95) | |
| prediction_summary(model2, data = d) | |
| cv_procedure <- prediction_summary_cv(model = model2, | |
| group = "Studycode", | |
| data = d, | |
| k = 10) |