Commit 04a9d98b authored by Mathilde Grimée's avatar Mathilde Grimée
Browse files

initial commit

parents
File added
#b. Check linearity
m_rcs <- glm(survived~rcs(age, 5)+sex+sibsp+pclass+parch, family = "binomial", data = t3)
anova(m_rcs)
#b. Check linearity
m_rcs <- lrm(survived~rcs(age, 5)+sex+sibsp+pclass+parch, data = t3)
anova(m_rcs)
m_rcs
#Ex4 Location of knots
quantiles(t3$age, c(0.05, 0.275, 0.5, 0.725, 0.95))
library(stats)
library(stats)
#Ex4 Location of knots
quantiles(t3$age, c(0.05, 0.275, 0.5, 0.725, 0.95))
#Ex4 Location of knots
quantile(t3$age, c(0.05, 0.275, 0.5, 0.725, 0.95))
#Ex4 Location of knots
quantile(t3$age, c(0.05, 0.275, 0.5, 0.725, 0.95), na.rm = TRUE)
Function(m_rcs)
#Ex5 compare linear model and model with rcs
lrtest(mod, m_rcs)
#Ex6 interpret model 3
pred <- Predict(m_rcs, age, fun = exp)
#Ex6 interpret model 3
pred <- Predict(m_rcs, age)
?Predict
#Ex6 interpret model 3
anova(m_rcs)
summary(m_rcs)
summary(m_rcs)
pred <- Predict(m_rcs, age)
pred <- Predict(m_rcs, age, fun = exp)
#Ex7 interaction age and sex
m_int <-lrm(survived~rcs(age, 5)+sex+sibsp+pclass+parch+age*sex, data = t3)
#Ex7 interaction age and sex
m_int <-lrm(survived~rcs(age, 5)+sex+sibsp+pclass+parch+age*sex, data = t3, na.rm=TRUE)
remotes::install_gitlab(repo = "SUSPend/Suspendr",
host = "gitlab.switch.ch",
auth_token = "e9ESWydxgJfv_-5za3hz",
force = TRUE)
remotes::install_gitlab(repo = "SUSPend/Suspendr",
host = "gitlab.switch.ch",
auth_token = "e9ESWydxgJfv_-5za3hz",
force = TRUE)
remotes::install_gitlab(repo = "SUSPend/Suspendr",
host = "gitlab.switch.ch",
auth_token = "e9ESWydxgJfv_-5za3hz",
force = TRUE)
remotes::install_gitlab(repo = "SUSPend/Suspendr",
host = "gitlab.switch.ch",
auth_token = "e9ESWydxgJfv_-5za3hz",
force = TRUE)
1library(suspendr)
library(suspendr)
?suspendInterrupts
?get_iom_dates
?get_iom_matrix
get_iom_matrix(by = "country", units = c("de", "ch", "at"), start = as.Date("2020-01-01"), end = as.Date("2021-03-01"), recycle = T)
get_iom_matrix(by = "country", units = c("de", "ch", "at"), start = as.Date("2020-01-01"), end = as.Date("2021-03-01"), recycle = F)
IOM <- get_iom_matrix(by = "country", units = c("de", "ch", "at"), start = as.Date("2020-01-01"), end = as.Date("2020-03-01"), recycle = F)
IOM <- get_iom_matrix(by = "country", units = c("de", "ch", "at"), start = as.Date("2020-04-01"), end = as.Date("2020-05-01"), recycle = F)
View(IOM)
plot(c(1, 2, 3), c(2, 3,4 ), main = "Umläute")
load("../Data_preparation/covariates.Rdata")
temp <- readRDS("/Users/mathildegrimee/OneDrive/a_LMU/Semester 4/Master thesis/suspend/border-closure/Swiss_Italian_project/Data_preparation/temp.rds")
temp <- load("/Users/mathildegrimee/OneDrive/a_LMU/Semester 4/Master thesis/suspend/border-closure/Swiss_Italian_project/Data_preparation/temp.rds")
temp
load("/Users/mathildegrimee/OneDrive/a_LMU/Semester 4/Master thesis/suspend/border-closure/Swiss_Italian_project/Data_preparation/temp.rds")
temp
which(temp == -9999)
which(temp == -999)
which(temp == 3.3)
####################
## Plot adjacency ##
## matrices ##
####################
setwd("/Users/mathildegrimee/OneDrive/a_LMU/Semester 4/Master thesis/suspend/border-closure/Swiss_Italian_project/Data_preparation")
load("adjacencies_BASE.rds")
load("adjacencies_FB.rds")
load("adjacencies_IOM.rds")
plotmatrix <- function(d2, title = NULL, leg.pos = "none"){
d2.df <- data.frame(x=rep(dimnames(d2)[[1]],each=ncol(d2)),y=rep(dimnames(d2)[[2]],times=nrow(d2)),z=as.vector(d2))
plot <- ggplot(data=d2.df,aes(x=x,y=y,fill=z))+
geom_tile() +
ggtitle(title) +
scale_fill_gradient(low = "#000000",
high = "#ffffff",
guide = "colourbar",
limits = c(0, 1))+
labs(y = NULL, x= NULL)+
theme(legend.position = leg.pos, axis.text.x = element_text(angle=-45))+
coord_fixed(ratio = 1)
return(plot)
}
plotmatrix(adjacencies_BASE, "Adjacencies at baseline", "bottom")
library(ggplot2)
plotmatrix <- function(d2, title = NULL, leg.pos = "none"){
d2.df <- data.frame(x=rep(dimnames(d2)[[1]],each=ncol(d2)),y=rep(dimnames(d2)[[2]],times=nrow(d2)),z=as.vector(d2))
plot <- ggplot(data=d2.df,aes(x=x,y=y,fill=z))+
geom_tile() +
ggtitle(title) +
scale_fill_gradient(low = "#000000",
high = "#ffffff",
guide = "colourbar",
limits = c(0, 1))+
labs(y = NULL, x= NULL)+
theme(legend.position = leg.pos, axis.text.x = element_text(angle=-45))+
coord_fixed(ratio = 1)
return(plot)
}
plotmatrix(adjacencies_BASE, "Adjacencies at baseline", "bottom")
p_fb_3 <- plotmatrix(adjacencies_FB[,,"2020-03-01"])
p_fb_4<- plotmatrix(adjacencies_FB[,,"2020-04-01"])
p_fb_5 <- plotmatrix(adjacencies_FB[,,"2020-05-01"])
p_fb_6 <- plotmatrix(adjacencies_FB[,,"2020-06-01"])
p_fb_7 <- plotmatrix(adjacencies_FB[,,"2020-07-01"])
p_fb_8 <- plotmatrix(adjacencies_FB[,,"2020-08-01"])
p_iom_3 <- plotmatrix(adjacencies_IOM[,,"2020-03-01"])
p_iom_4 <- plotmatrix(adjacencies_IOM[,,"2020-04-01"])
p_iom_5 <- plotmatrix(adjacencies_IOM[,,"2020-05-01"])
p_iom_6 <- plotmatrix(adjacencies_IOM[,,"2020-06-01"])
p_iom_7 <- plotmatrix(adjacencies_IOM[,,"2020-07-01"])
p_iom_8 <- plotmatrix(adjacencies_IOM[,,"2020-08-01"])
grid.arrange(p_fb_3, p_fb_4, p_fb_5, p_fb_6, p_fb_7, p_fb_8,
p_iom_3, p_iom_4, p_iom_5, p_iom_6, p_iom_7, p_iom_8,
ncol = 2)
library(gridExtra)
grid.arrange(p_fb_3, p_fb_4, p_fb_5, p_fb_6, p_fb_7, p_fb_8,
p_iom_3, p_iom_4, p_iom_5, p_iom_6, p_iom_7, p_iom_8,
ncol = 2)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2)
pdf("../Report/figures/Adjacencies.pdf", width = 12, height = 8)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 50, height = 80)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 40, height = 80)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 30, height = 80)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2)
dev.off()
p <- plotmatrix(adjacencies_BASE, "Adjacencies at baseline", "bottom")
p
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend)}
mylegend<-g_legend(p)
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2,
mylegend)
dev.off()
p <- plotmatrix(adjacencies_BASE, "Adjacencies at baseline", "top")
mylegend<-g_legend(p)
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p_fb_3, p_iom_3, p_fb_4, p_iom_4, p_fb_5, p_iom_5,
p_fb_6, p_iom_6, p_fb_7, p_iom_7, p_fb_8, p_iom_8,
ncol = 2,
mylegend)
dev.off()
p <- plotmatrix(adjacencies_BASE, "Adjacencies at baseline", "none")
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p, p_fb_3, p_iom_3, p, p_fb_4, p_iom_4, p, p_fb_5, p_iom_5,
p, p_fb_6, p_iom_6, p, p_fb_7, p_iom_7, p, p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
p2 <- plotmatrix(adjacencies_BASE, "none", "At baseline")
p_fb_3_2 <- plotmatrix(adjacencies_FB[,,"2020-03-01"], "Facebook adjustment")
p_iom_3_2 <- plotmatrix(adjacencies_IOM[,,"2020-03-01"], "IOM adjustment")
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p2, p_fb_3_2, p_iom_3_2, p, p_fb_4, p_iom_4, p, p_fb_5, p_iom_5,
p, p_fb_6, p_iom_6, p, p_fb_7, p_iom_7, p, p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
p <- plotmatrix(adjacencies_BASE, "none")
p2 <- plotmatrix(adjacencies_BASE, "none", "At baseline")
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p2, p_fb_3_2, p_iom_3_2, p, p_fb_4, p_iom_4, p, p_fb_5, p_iom_5,
p, p_fb_6, p_iom_6, p, p_fb_7, p_iom_7, p, p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
p <- plotmatrix(adjacencies_BASE)
p2 <- plotmatrix(adjacencies_BASE, "At baseline")
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p2, p_fb_3_2, p_iom_3_2, p, p_fb_4, p_iom_4, p, p_fb_5, p_iom_5,
p, p_fb_6, p_iom_6, p, p_fb_7, p_iom_7, p, p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
plotmatrix <- function(d2, title = NULL, leg.pos = "none", ylab= NULL){
d2.df <- data.frame(x=rep(dimnames(d2)[[1]],each=ncol(d2)),y=rep(dimnames(d2)[[2]],times=nrow(d2)),z=as.vector(d2))
plot <- ggplot(data=d2.df,aes(x=x,y=y,fill=z))+
geom_tile() +
ggtitle(title) +
scale_fill_gradient(low = "#000000",
high = "#ffffff",
guide = "colourbar",
limits = c(0, 1))+
labs(y = NULL, x= NULL)+
theme(legend.position = leg.pos, axis.text.x = element_text(angle=-45))+
coord_fixed(ratio = 1) +
labs(y = ylab)+
return(plot)
}
plotmatrix <- function(d2, title = NULL, leg.pos = "none"){
d2.df <- data.frame(x=rep(dimnames(d2)[[1]],each=ncol(d2)),y=rep(dimnames(d2)[[2]],times=nrow(d2)),z=as.vector(d2))
plot <- ggplot(data=d2.df,aes(x=x,y=y,fill=z))+
geom_tile() +
ggtitle(title) +
scale_fill_gradient(low = "#000000",
high = "#ffffff",
guide = "colourbar",
limits = c(0, 1))+
labs(y = NULL, x= NULL)+
theme(legend.position = leg.pos, axis.text.x = element_text(angle=-45))+
coord_fixed(ratio = 1)
return(plot)
}
pdf("../Report/figures/Adjacencies.pdf", width = 15, height = 40)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 7.5, height = 20)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 10, height = 25)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3,
mylegend)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 10, height = 25)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 10, height = 20)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3)
dev.off()
plotmatrix <- function(d2, title = NULL, leg.pos = "none"){
d2.df <- data.frame(x=rep(dimnames(d2)[[1]],each=ncol(d2)),y=rep(dimnames(d2)[[2]],times=nrow(d2)),z=as.vector(d2))
plot <- ggplot(data=d2.df,aes(x=x,y=y,fill=z))+
geom_tile() +
ggtitle(title) +
scale_fill_gradient(low = "#000000",
high = "#ffffff",
guide = "colourbar",
limits = c(0, 1))+
labs(y = " ", x= " ")+
theme(legend.position = leg.pos, axis.text.x = element_text(angle=-45))+
coord_fixed(ratio = 1)
return(plot)
}
p <- plotmatrix(adjacencies_BASE)
p2 <- plotmatrix(adjacencies_BASE, "At baseline")
p_fb_3 <- plotmatrix(adjacencies_FB[,,"2020-03-01"])
p_fb_3_2 <- plotmatrix(adjacencies_FB[,,"2020-03-01"], "Facebook adjustment")
p_fb_4<- plotmatrix(adjacencies_FB[,,"2020-04-01"])
p_fb_5 <- plotmatrix(adjacencies_FB[,,"2020-05-01"])
p_fb_6 <- plotmatrix(adjacencies_FB[,,"2020-06-01"])
p_fb_7 <- plotmatrix(adjacencies_FB[,,"2020-07-01"])
p_fb_8 <- plotmatrix(adjacencies_FB[,,"2020-08-01"])
p_iom_3 <- plotmatrix(adjacencies_IOM[,,"2020-03-01"])
p_iom_3_2 <- plotmatrix(adjacencies_IOM[,,"2020-03-01"], "IOM adjustment")
p_iom_4 <- plotmatrix(adjacencies_IOM[,,"2020-04-01"])
p_iom_5 <- plotmatrix(adjacencies_IOM[,,"2020-05-01"])
p_iom_6 <- plotmatrix(adjacencies_IOM[,,"2020-06-01"])
p_iom_7 <- plotmatrix(adjacencies_IOM[,,"2020-07-01"])
p_iom_8 <- plotmatrix(adjacencies_IOM[,,"2020-08-01"])
pdf("../Report/figures/Adjacencies.pdf", width = 10, height = 20)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3)
dev.off()
pdf("../Report/figures/Adjacencies.pdf", width = 8, height = 18)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3)
dev.off()
#####################
## Create map of ##
## studied regions ##
#####################
#no dependencies
library(dplyr)
library(tmap)
library(eurostat) # Zum einfachen laden der Daten
library(tidyverse) # dplyr vereinfachte die Datenaufbereitung
library("tmaptools")
shp_CH <- plyr::rbind.fill(get_eurostat_geospatial(nuts_level = "2") %>%
filter(str_detect(CNTR_CODE, "CH")))
shp_CH_state <- plyr::rbind.fill(get_eurostat_geospatial(nuts_level = "1") %>%
filter(str_detect(CNTR_CODE, "CH")))
shp_IT <- plyr::rbind.fill(get_eurostat_geospatial(nuts_level = "2") %>%
filter(str_detect(CNTR_CODE, "IT")))
shp <- rbind(shp_CH, shp_IT)
shp$CNTR_CODE <- as.factor(shp$CNTR_CODE)
colnames(shp)[which(colnames(shp) == "COUNTRY")] <- "CNTR_CODE"
shp$COUNTRY <- NA
shp$COUNTRY[which(shp$CNTR_CODE == "CH")] <- "#3a527c"
shp$COUNTRY[which(shp$CNTR_CODE == "IT")] <- "#93b2e7"
shp$NAME <- NA
shp$NAME[which(shp$CNTR_CODE == "CH")] <- "Switzerland"
shp$NAME[which(shp$CNTR_CODE == "IT")] <- "Italy"
shp$NUTS_NAME[which(shp$NUTS_NAME == "Provincia Autonoma di Bolzano/Bozen")] <-
"Provincia Autonoma\ndi Bolzano/Bozen"
shp$NUTS_NAME[which(shp$NUTS_NAME == "Valle d'Aosta/Vallée d'Aoste")] <-
"Valle d'Aosta/\nVallée d'Aoste"
shp$ymod <- 0
shp$ymod[which(shp$id == "CH01")] <- -1
shp$ymod[which(shp$id == "CH03")] <- 0.5
shp$xmod <- 0
shp$xmod[which(shp$id == "CH01")] <- 1
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#87a7ca", "#83b695"), title = "Country") +
tm_text("id", size = 0.7, col = "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#3a527c", "#93b2e7"), title = "Country") +
tm_text("id", size = 0.7, col = "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
shp <- rbind(shp_CH, shp_IT[which(shp_IT$id %in% rorder)])
rorder <- c("CH01", "CH02", "CH03", "CH04", "CH05","CH06", "CH07",
"ITC1", "ITC2", "ITC4", "ITH1")
shp <- rbind(shp_CH, shp_IT[which(shp_IT$id %in% rorder)])
shp <- rbind(shp_CH, shp_IT[which(shp_IT$id %in% rorder),])
shp$CNTR_CODE <- as.factor(shp$CNTR_CODE)
colnames(shp)[which(colnames(shp) == "COUNTRY")] <- "CNTR_CODE"
shp$COUNTRY <- NA
shp$COUNTRY[which(shp$CNTR_CODE == "CH")] <- "#3a527c"
shp$COUNTRY[which(shp$CNTR_CODE == "IT")] <- "#93b2e7"
shp$NAME <- NA
shp$NAME[which(shp$CNTR_CODE == "CH")] <- "Switzerland"
shp$NAME[which(shp$CNTR_CODE == "IT")] <- "Italy"
shp$ymod <- 0
shp$ymod[which(shp$id == "CH01")] <- -1
shp$ymod[which(shp$id == "CH03")] <- 0.5
shp$xmod <- 0
shp$xmod[which(shp$id == "CH01")] <- 1
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#3a527c", "#93b2e7"), title = "Country") +
tm_text("id", size = 0.7, col = "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#3a527c", "#93b2e7"), title = "Country") +
tm_text("id", size = 0.7, col = c("black", "white"), ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#3a527c", "#93b2e7"), title = "Country") +
tm_text("id", size = 0.7, col = c= "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#3a527c", "#93b2e7"), title = "Country") +
tm_text("id", size = 0.7, col = "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#93b2e7", "#3a527c"), title = "Country") +
tm_text("id", size = 0.7, col = "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
?tm_text
shp$txtcol <- NA
shp$txtcol[which(shp$CNTR_CODE == "CH")] <- "white"
shp$txtcol[which(shp$CNTR_CODE == "IT")] <- "black"
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#93b2e7", "#3a527c"), title = "Country") +
tm_text("id", size = 0.7, col = txtcol, ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#93b2e7", "#3a527c"), title = "Country") +
tm_text("id", size = 0.7, col = shp$txtcol, ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
?tm_text
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#93b2e7", "#3a527c"), title = "Country") +
tm_text("id", size = 0.7, col = black, ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP <- tm_shape(shp) +
tm_polygons("NAME", palette = c("#93b2e7", "#3a527c"), title = "Country") +
tm_text("id", size = 0.7, col = "black", ymod = "ymod", xmod = "xmod") +
tm_legend(legend.position = c("right", "bottom"),
outer.margins = c(0.06, 0.10, 0.10, 0.08)) +
tm_layout(outer.margins = c(0.00, 0.00, 0.00, 0.00))
MAP
pdf("../Report/figures/map.pdf", width = 8, height = 18)
MAP
dev.off()
pdf("../Report/figures/map.pdf", width = 8, height = 5)
MAP
dev.off()
pdf("../Report/figures/map.pdf", width = 6, height = 5)
MAP
dev.off()
pdf("../Report/figures/map.pdf", width = 6.2, height = 5)
MAP
dev.off()
pdf("../Report/figures/map.pdf", width = 6.1, height = 5)
MAP
dev.off()
####################
## Plot adjacency ##
## matrices ##
####################
load("../Data_preparation/adjacencies_BASE.rds")
getwd
getwd()
setwd("/Users/mathildegrimee/OneDrive/a_LMU/Semester 4/Master thesis/COVID-19-border-CH/Analysis")
####################
## Plot adjacency ##
## matrices ##
####################
load("../Data_preparation/adjacencies_BASE.rds")
load("../Data_preparation/adjacencies_FB.rds")
load("../Data_preparation/adjacencies_IOM.rds")
library(ggplot2)
library(gridExtra)
plotmatrix <- function(d2, title = NULL, leg.pos = "none"){
d2.df <- data.frame(x=rep(dimnames(d2)[[1]],each=ncol(d2)),y=rep(dimnames(d2)[[2]],times=nrow(d2)),z=as.vector(d2))
plot <- ggplot(data=d2.df,aes(x=x,y=y,fill=z))+
geom_tile() +
ggtitle(title) +
scale_fill_gradient(low = "#000000",
high = "#ffffff",
guide = "colourbar",
limits = c(0, 1))+
labs(y = " ", x= " ")+
theme(legend.position = leg.pos, axis.text.x = element_text(angle=-45))+
coord_fixed(ratio = 1)
return(plot)
}
p <- plotmatrix(adjacencies_BASE, "Adjacencies at baseline")
pdf("../Figures/Adjacencies_BASE.pdf")
p
dev.off()
p_fb_3 <- plotmatrix(adjacencies_FB[,,"2020-03-01"])
p_fb_3_2 <- plotmatrix(adjacencies_FB[,,"2020-03-01"], "Facebook adjustment")
p_fb_4<- plotmatrix(adjacencies_FB[,,"2020-04-01"])
p_fb_5 <- plotmatrix(adjacencies_FB[,,"2020-05-01"])
p_fb_6 <- plotmatrix(adjacencies_FB[,,"2020-06-01"])
p_fb_7 <- plotmatrix(adjacencies_FB[,,"2020-07-01"])
p_fb_8 <- plotmatrix(adjacencies_FB[,,"2020-08-01"])
p_iom_3 <- plotmatrix(adjacencies_IOM[,,"2020-03-01"])
p_iom_3_2 <- plotmatrix(adjacencies_IOM[,,"2020-03-01"], "IOM adjustment")
p_iom_4 <- plotmatrix(adjacencies_IOM[,,"2020-04-01"])
p_iom_5 <- plotmatrix(adjacencies_IOM[,,"2020-05-01"])
p_iom_6 <- plotmatrix(adjacencies_IOM[,,"2020-06-01"])
p_iom_7 <- plotmatrix(adjacencies_IOM[,,"2020-07-01"])
p_iom_8 <- plotmatrix(adjacencies_IOM[,,"2020-08-01"])
p2 <- plotmatrix(adjacencies_BASE, "At baseline")
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3)
pdf("../Figures/Adjacencies.pdf", width = 8, height = 18)
grid.arrange(p2+labs(y = "March"), p_fb_3_2, p_iom_3_2, p+labs(y = "April"), p_fb_4, p_iom_4, p+labs(y = "May"), p_fb_5, p_iom_5,
p+labs(y = "June"), p_fb_6, p_iom_6, p+labs(y = "July"), p_fb_7, p_iom_7, p+labs(y = "August"), p_fb_8, p_iom_8,
ncol = 3)
dev.off()
#################
## Analyses ##
## Switzerland ##
## Italy ##
#################
#In this script, we fit different models with different model specifications,
#different covariates, etc. We create a table summarizing each model, their specification,
#the resulting BIC, and the number of df. For the three best performing models (lowest BIC),
#we also create a table of the parameter estimates.
#dependencies
load("../Data_preparation/parameters.Rdata")
load("../Data_preparation/covariates.Rdata")
load("../Data_preparation/cases.rds")
load("../Data_preparation/pop.rds")
load("../Data_preparation/adjacencies_BASE.rds")
load("../Data_preparation/adjacencies_FB.rds")
load("../Data_preparation/adjacencies_IOM.rds")
adjmat <- adjacencies_IOM
#packages
library(surveillance)
library(hhh4addon)
library(kableExtra)
#function to extract values from model
get_vals <- function(input, description = ""){
mod <- profile_par_lag(cases_sts,