Skip to content

Commit

Permalink
Fix a bug of MI extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
xsswang committed May 2, 2022
1 parent ac73303 commit 8625888
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
14 changes: 14 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@
#' }
#' @source long-to-wise tranformation of schizo data, i.e. schizob = data.table::dcast(schizo, id + tx ~ week, value.var = "imps79b")
"schizob"


#' wide format of continuous response of antidepressant data.
#'
#' A data set containing the treatment and continuous responses measured at baseline and 4 post-baseline visits
#'
#' @format A data frame with 172 rows and 6 variables:
#' \describe{
#' \item{PID}{Patient ID}
#' \item{tx}{Treatment, 1 for treated and 0 for placebo}
#' \item{y0}{HADM-17 measurement at the baseline}
#' \item{y1, y2, y4, y6}{Change score of HADM-17 measurement at the post-baseline week 1, 2, 4, and 6.}
#' }
#' @source https://www.lshtm.ac.uk/research/centres-projects-groups/missing-data#dia-missing-data
2 changes: 1 addition & 1 deletion R/glm_MI_CR.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ glm_MI_CR <- function(object, treatment, start=NULL, end=NULL, thin=NULL,
}

coefs <- coef_list[[vimp[j]]]
if (nrow(vdv)>0) {
if (length(refs) > 0) {
coefs <- merge(coefs, vdv, by="varname", all.x=TRUE)
coefs$var[is.na(coefs$var)] = "inter"
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/glm_MI_J2R.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ glm_MI_J2R <- function(object, treatment, start=NULL, end=NULL, thin=NULL,
}

coefs <- coef_list[[vimp[j]]]
if (nrow(vdv)>0) {
if (length(refs) > 0) {
coefs <- merge(coefs, vdv, by="varname", all.x=TRUE)
coefs$var[is.na(coefs$var)] = "inter"
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/glm_MI_delta.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ glm_MI_delta <- function(object, treatment, delta=0, start=NULL, end=NULL, thin=
}

coefs <- coef_list[[vimp[j]]]
if (nrow(vdv)>0) {
if (length(refs) > 0) {
coefs <- merge(coefs, vdv, by="varname", all.x=TRUE)
coefs$var[is.na(coefs$var)] = "inter"
} else {
Expand Down
12 changes: 8 additions & 4 deletions R/list.models.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ list.models <- function (object, details = FALSE, print = TRUE) {
refs = Mlist$refs

## dummy vars -->> original varname
vdvlist = lapply(names(refs), function(dv) data.frame(var=dv, varname=attr(refs[[dv]],"dummies")) )
vdv = do.call(rbind.data.frame, vdvlist)

if (length(refs)>0){
vdvlist = lapply(names(refs), function(dv) data.frame(var=dv, varname=attr(refs[[dv]],"dummies")) )
vdv = do.call(rbind.data.frame, vdvlist)
}
vimp = rev(names(info_list))

for (j in 1:length(vimp)){
varname = vimp[j]
coefs <- coef_list[[vimp[j]]]
coefs <- merge(coefs, vdv, by="varname", all.x=TRUE)

if (length(refs)>0) coefs <- merge(coefs, vdv, by="varname", all.x=TRUE)
else coefs$var = coefs$varname

coefs$var[is.na(coefs$var)] = coefs$varname[is.na(coefs$var)]
coefs = subset(coefs, !grepl("intercept", var,ignore.case = TRUE))
dtj = data.frame(Order=j, model_formula = paste0(varname," ~ ", paste(unique(coefs$var), collapse = " + ")))
Expand Down
Binary file added data/antidep.rda
Binary file not shown.

0 comments on commit 8625888

Please sign in to comment.