Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula naming #70

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/calcBalStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ calcBalStats <- function(home_dir = NA, data, formulas, exposure, exposure_time_
lagged_time_pts <- exposure_time_pts[exposure_time_pts<exposure_time_pt]

# GETS COVARIATES FROM FORM FOR ASSESSING BALANCE
full_form <- formulas[[names(formulas)[grepl(paste0("form_", exposure, "-", outcome, "-", exposure_time_pt),
names(formulas))]]]
# full_form <- formulas[[names(formulas)[grepl(paste0("-", exposure_time_pt),
# names(formulas))]]]
full_form <- formulas[[names(formulas)[as.numeric(sapply(strsplit(names(formulas), "-"), "[",2)) == exposure_time_pt]]]

covars <- paste(deparse(full_form[[3]], width.cutoff = 500), collapse = "") # gets covariates
covar_time <- sapply(strsplit(unlist(strsplit(as.character(covars), "\\+")), "\\."), "[", 2)
covars <- as.character(unlist(strsplit(covars, "\\+")))
Expand Down
2 changes: 1 addition & 1 deletion R/createFormulas.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ createFormulas <- function(home_dir, exposure, exposure_time_pts, outcome, tv_co
forms_csv <- c(forms_csv, paste(exposure, "~", paste0(vars_to_include[order(vars_to_include)], sep = "", collapse = " + ")))

# Assigns the form to forms list
forms[[paste(type, "_form_", exposure, "-", outcome, "-", time, sep = "")]] <- f
forms[[paste(type, "_form", "-", time, sep = "")]] <- f
}

if(save.out){
Expand Down
10 changes: 9 additions & 1 deletion examplePipelineRevised.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ data_mids <- readRDS(paste0(home_dir, "/imputed_data.rds"))
#example path to imputed data
# data_path <- "/Users/isabella/Library/CloudStorage/Box-Box/BSL General/MSMs/testing/imputations/"

#MD data
data <- read.csv("/Users/isabella/Library/CloudStorage/Box-Box/BSL General/MSMs/testing/meriah/imputations/ESETA1-CORTB.154_imp1.csv")
factor_confounders = c("state","TcBlac2", "PmBlac2")

data[, factor_confounders] <- lapply(data[, factor_confounders], as.factor)
numeric_vars <- colnames(data)[!colnames(data) %in% c(factor_confounders, "ID")]
data[, numeric_vars] <- lapply(data[, numeric_vars], as.numeric)

library(dplyr)
data_df <- data_mids[[1]]
data_df <- data_df %>% dplyr::select(-c(contains(c(":", "Childhood", "Infancy", "Toddlerhood", "pcx"))))
Expand Down Expand Up @@ -126,7 +134,7 @@ data_wide = data_wide[, !colnames(data_wide) %in% c("RHasSO.6","RHasSO.15", "RHa
m <- 1
method <- "pmm"; #pmm, midastouch, sample, cart , rf (default)
imputed_data <- imputeData(data_wide, m, method, home_dir, exposure, outcome, tv_confounders, ti_confounders,
para_proc = FALSE, read_imps_from_file = "no")
para_proc = TRUE, read_imps_from_file = "no")

data = complete(imputed_data, 1)

Expand Down
Loading