d=ˉxtreatment−ˉxcontrol√s2treatment+s2control2
1
library(survey)svy_des <- svydesign( ids = ~ 1, data = df, weights = ~ wts)
2
library(tableone)library(tidyverse)smd_table_unweighted <- CreateTableOne( vars = c("confounder_1", "confounder_1", ...), strata = "exposure", data = df, test = FALSE)
3
smd_table <- svyCreateTableOne( vars = c("confounder_1", "confounder_1", ...), strata = "exposure", data = svy_des, test = FALSE)
3
smd_table <- svyCreateTableOne( vars = c("confounder_1", "confounder_1", ...), strata = "exposure", data = svy_des, test = FALSE)
4
plot_df <- data.frame( var = rownames(ExtractSmd(smd_table)), Unadjusted = as.numeric(ExtractSmd(smd_table_unweighted)), Weighted = as.numeric(ExtractSmd(smd_table))) %>% pivot_longer(-var, names_to = "Method", values_to = "SMD")
4
plot_df <- data.frame( var = rownames(ExtractSmd(smd_table)), Unadjusted = as.numeric(ExtractSmd(smd_table_unweighted)), Weighted = as.numeric(ExtractSmd(smd_table))) %>% pivot_longer(-var, names_to = "Method", values_to = "SMD")rownames(EXtractSMD(smd_table))#> [1] "confounder_1" "confounder_2"
4
plot_df <- data.frame( var = rownames(ExtractSmd(smd_table)), Unadjusted = as.numeric(ExtractSmd(smd_table_unweighted)), Weighted = as.numeric(ExtractSmd(smd_table))) %>% pivot_longer(-var, names_to = "Method", values_to = "SMD")as.numeric(ExtractSmd(smd_table_unweighted))#> [1] 0.160 0.177
4
plot_df <- data.frame( var = rownames(ExtractSmd(smd_table)), Unadjusted = as.numeric(ExtractSmd(smd_table_unweighted)), Weighted = as.numeric(ExtractSmd(smd_table))) %>% pivot_longer(-var, names_to = "Method", values_to = "SMD")as.numeric(ExtractSmd(smd_table))#> [1] 0.002 0.007
4
plot_df <- data.frame( var = rownames(ExtractSmd(smd_table)), Unadjusted = as.numeric(ExtractSmd(smd_table_unweighted)), Weighted = as.numeric(ExtractSmd(smd_table))) %>% pivot_longer(-var, names_to = "Method", values_to = "SMD")
5
ggplot(data = plot_df, mapping = aes(x = var, y = SMD, group = Method, color = Method)) + geom_line() + geom_point() + geom_hline(yintercept = 0.1, color = "black", size = 0.1) + coord_flip()
5
ggplot(data = plot_df, mapping = aes(x = var, y = SMD, group = Method, color = Method)) + geom_line() + geom_point() + geom_hline(yintercept = 0.1, color = "black", size = 0.1) + coord_flip()
5
ggplot(data = plot_df, mapping = aes(x = var, y = SMD, group = Method, color = Method)) + geom_line() + geom_point() + geom_hline(yintercept = 0.1, color = "black", size = 0.1) + coord_flip()
5
ggplot(data = plot_df, mapping = aes(x = var, y = SMD, group = Method, color = Method)) + geom_line() + geom_point() + geom_hline(yintercept = 0.1, color = "black", size = 0.1) + coord_flip()
5
ggplot(data = plot_df, mapping = aes(x = var, y = SMD, group = Method, color = Method)) + geom_line() + geom_point() + geom_hline(yintercept = 0.1, color = "black", size = 0.1) + coord_flip()
5
ggplot(data = plot_df, mapping = aes(x = var, y = SMD, group = Method, color = Method)) + geom_line() + geom_point() + geom_hline(yintercept = 0.1, color = "black", size = 0.1) + coord_flip()
07:00
For continuous variables, it can be helpful to look at the whole distribution pre and post-weighting rather than a single summary measure
ggplot(df, aes(x = wt71, group = qsmk, color = factor(qsmk))) + stat_ecdf() + scale_color_manual("Quit smoking", values = c("#5154B8", "#5DB854"), labels = c("Yes", "No")) + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ggplot(df, aes(x = wt71, group = qsmk, color = factor(qsmk))) + stat_ecdf() + scale_color_manual("Quit smoking", values = c("#5154B8", "#5DB854"), labels = c("Yes", "No")) + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ggplot(df, aes(x = wt71, group = qsmk, color = factor(qsmk))) + stat_ecdf() + scale_color_manual("Quit smoking", values = c("#5154B8", "#5DB854"), labels = c("Yes", "No")) + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
ecdf_1 <- df %>% filter(qsmk == 1) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ecdf_0 <- df %>% filter(qsmk == 0) %>% arrange(wt71) %>% mutate(cum_pct = cumsum(w_ate) / sum(w_ate))ggplot(ecdf_1, aes(x = wt71, y = cum_pct)) + geom_line( color = "#5DB854") + geom_line(data = ecdf_0, aes(x = wt71, y = cum_pct), color = "#5154B8") + xlab("Weight in Kg in 1971") + ylab("Proportion <= x")
07:00
smokeyrs
confounder for those that quit smoking and those that did notsmokeyrs
confounderKeyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |