This document contains the summaries of the regression analyses with smoking status as the outcome and all covariates included. We provide the code used to generate this table, which calls upon our analysis summary objects (also provided).
Code
Preparation
The following packages were used to generate this table:
library(papaja)
library(tidyverse)
library(tools)
library(psych)
library(knitr)
library(kableExtra)
library(here)
The files needed for this table are available at osf.io/mzfu9 in the Individual Study Output folder.
First we load the individual study analysis objects.
study.names = c("BASEII", "EAS","ELSA", "HRS", "ILSE", "LBC",
"LBLS", "MAP", "MAS","MIDUS","NAS", "OATS",
"ROS","SLS","WLS")
lapply(here(paste0("behavior/", study.names, "_behavior.Rdata")), load, .GlobalEnv)
Then we identify which studies have smoking as an outcome.
#identify which studies have active outcome
smoker.names = lapply(paste0(study.names,"_behavior"),
FUN = function(x) rownames(get(x)$descriptives))
smoker.names = sapply(smoker.names, FUN = function(x) "smoker" %in% x)
smoker.names = study.names[smoker.names]
columns = unite(
expand.grid(stat = c("estimate", "std.error", "OR", "statistic", "p.value"),
study = smoker.names),
columns, study, stat, sep="_")$columns
header = c(" " = 1, "BASEII" = 5, "EAS" = 5, "ELSA" = 5, "HRS" = 5, "ILSE" = 5,
"LBLS" = 5, "LBC" = 5, "MAP" = 5, "MAS" = 5, "MIDUS" = 5, "NAS" = 5, "OATS" = 5,
"ROS" = 5, "SLS" = 5, "WLS" = 5)
Main Effects
#sample size
smoker.n = data.frame(study = smoker.names,
term = "N", estimate =
sapply(X = smoker.names, FUN = function(x)
get(paste0(x,"_behavior"))$regression$main$smoker$n)) %>%
mutate(study = paste0(study, "_estimate")) %>%
spread(key = "study", value = "estimate")
lapply(X = smoker.names, FUN = function(x) get(paste0(x,"_behavior"))$regression$main$smoker$coef) %>%
map2_df(., smoker.names, ~ mutate(.x, study = .y)) %>%
mutate(OR = exp(estimate)) %>%
gather(key = "key", value = "value", -study, -term) %>%
unite(study_stat, study, key, sep="_") %>%
filter(!is.infinite(value)) %>%
spread(key = "study_stat", value = "value") %>%
gather(key = "key", value = "value", which(grepl("p", names(.)))) %>%
filter(!is.na(value)) %>%
mutate(sig = value,
value = printp(value),
value = cell_spec(value, "html",
color = ifelse(sig >= .05 | is.na(sig),
"black", "red"))) %>%
filter(!grepl("NA", value))%>%
dplyr::select(-sig) %>%
spread(key = "key", value = "value") %>%
full_join(smoker.n) %>%
mutate(term = gsub("\\(", "", term),
term = gsub("\\)", "", term),
term = toTitleCase(term),
term = gsub("\\:", " x ", term),
term = factor(term,
levels = c("Intercept", "Age", "Gender", "Edu", "Agree", "Extra", "Open",
"Neur", "Con", "Neur x con", "N"))) %>%
arrange(term) %>%
dplyr::select(term, columns) %>%
kable(., booktabs = T, escape = F, digits = 2, format = "html",
align=c(rep('c',times=ncol(.))),
col.names = c("Term", rep(c("Est","SE","OR", "t value", "p"), length(smoker.names)))) %>%
kable_styling("bordered", full_width = TRUE) %>%
add_header_above(header = header)
Interaction, no covariates
#sample size
smoker.n = data.frame(study = smoker.names,
term = "N", estimate =
sapply(X = smoker.names, FUN = function(x)
get(paste0(x,"_behavior"))$regression$intr$smoker$n)) %>%
mutate(study = paste0(study, "_estimate")) %>%
spread(key = "study", value = "estimate")
lapply(X = smoker.names, FUN = function(x) get(paste0(x,"_behavior"))$regression$intr$smoker$coef) %>%
map2_df(., smoker.names, ~ mutate(.x, study = .y)) %>%
mutate(OR = exp(estimate)) %>%
gather(key = "key", value = "value", -study, -term) %>%
unite(study_stat, study, key, sep="_") %>%
filter(!is.infinite(value)) %>%
spread(key = "study_stat", value = "value") %>%
gather(key = "key", value = "value", which(grepl("p", names(.)))) %>%
filter(!is.na(value)) %>%
mutate(sig = value,
value = printp(value),
value = cell_spec(value, "html",
color = ifelse(sig >= .05 | is.na(sig),
"black", "red"))) %>%
filter(!grepl("NA", value))%>%
dplyr::select(-sig) %>%
spread(key = "key", value = "value") %>%
full_join(smoker.n) %>%
mutate(term = gsub("\\(", "", term),
term = gsub("\\)", "", term),
term = toTitleCase(term),
term = gsub("\\:", " x ", term),
term = factor(term,
levels = c("Intercept", "Age", "Gender", "Edu", "Agree", "Extra", "Open",
"Neur", "Con", "Neur x con", "N"))) %>%
arrange(term) %>%
dplyr::select(term, columns) %>%
kable(., booktabs = T, escape = F, digits = 2, format = "html",
align=c(rep('c',times=ncol(.))),
col.names = c("Term", rep(c("Est","SE","OR", "t value", "p"), length(smoker.names)))) %>%
kable_styling("bordered", full_width = TRUE) %>%
add_header_above(header)
Interaction, demographics
#sample size
smoker.n = data.frame(study = smoker.names,
term = "N", estimate =
sapply(X = smoker.names, FUN = function(x)
get(paste0(x,"_behavior"))$regression$cov1$smoker$n)) %>%
mutate(study = paste0(study, "_estimate")) %>%
spread(key = "study", value = "estimate")
lapply(X = smoker.names, FUN = function(x) get(paste0(x,"_behavior"))$regression$cov1$smoker$coef) %>%
map2_df(., smoker.names, ~ mutate(.x, study = .y)) %>%
mutate(OR = exp(estimate)) %>%
gather(key = "key", value = "value", -study, -term) %>%
unite(study_stat, study, key, sep="_") %>%
filter(!is.infinite(value)) %>%
spread(key = "study_stat", value = "value") %>%
gather(key = "key", value = "value", which(grepl("p", names(.)))) %>%
filter(!is.na(value)) %>%
mutate(sig = value,
value = printp(value),
value = cell_spec(value, "html",
color = ifelse(sig >= .05 | is.na(sig),
"black", "red"))) %>%
filter(!grepl("NA", value))%>%
dplyr::select(-sig) %>%
spread(key = "key", value = "value") %>%
full_join(smoker.n) %>%
mutate(term = gsub("\\(", "", term),
term = gsub("\\)", "", term),
term = toTitleCase(term),
term = gsub("\\:", " x ", term),
term = factor(term,
levels = c("Intercept", "Age", "Gender", "Edu", "Agree", "Extra", "Open",
"Neur", "Con", "Neur x con", "N"))) %>%
arrange(term) %>%
dplyr::select(term, columns) %>%
kable(., booktabs = T, escape = F, digits = 2, format = "html",
align=c(rep('c',times=ncol(.))),
col.names = c("Term", rep(c("Est","SE","OR", "t value", "p"), length(smoker.names)))) %>%
kable_styling("bordered", full_width = TRUE) %>%
add_header_above(header)
Interaction, all covariates
#sample size
smoker.n = data.frame(study = smoker.names,
term = "N", estimate =
sapply(X = smoker.names, FUN = function(x)
get(paste0(x,"_behavior"))$regression$cov2$smoker$n)) %>%
mutate(study = paste0(study, "_estimate")) %>%
spread(key = "study", value = "estimate")
lapply(X = smoker.names, FUN = function(x) get(paste0(x,"_behavior"))$regression$cov2$smoker$coef) %>%
map2_df(., smoker.names, ~ mutate(.x, study = .y)) %>%
mutate(OR = exp(estimate)) %>%
gather(key = "key", value = "value", -study, -term) %>%
unite(study_stat, study, key, sep="_") %>%
filter(!is.infinite(value)) %>%
spread(key = "study_stat", value = "value") %>%
gather(key = "key", value = "value", which(grepl("p", names(.)))) %>%
filter(!is.na(value)) %>%
mutate(sig = value,
value = printp(value),
value = cell_spec(value, "html",
color = ifelse(sig >= .05 | is.na(sig),
"black", "red"))) %>%
filter(!grepl("NA", value)) %>%
dplyr::select(-sig) %>%
spread(key = "key", value = "value") %>%
full_join(smoker.n) %>%
mutate(term = gsub("\\(", "", term),
term = gsub("\\)", "", term),
term = toTitleCase(term),
term = gsub("\\:", " x ", term),
term = factor(term,
levels = c("Intercept", "Age", "Gender", "Edu", "Agree", "Extra", "Open",
"Neur", "Con", "Neur x con", "N"))) %>%
arrange(term) %>%
dplyr::select(term, columns) %>%
kable(., booktabs = T, escape = F, digits = 2, format = "html",
align=c(rep('c',times=ncol(.))),
col.names = c("Term", rep(c("Est","SE","OR", "t value", "p"), length(smoker.names)))) %>%
kable_styling("bordered", full_width = TRUE) %>%
add_header_above(header)