{"id":26766124,"url":"https://github.com/ucl/refbasedmi","last_synced_at":"2026-02-26T08:19:26.823Z","repository":{"id":46074788,"uuid":"199465723","full_name":"UCL/RefbasedMI","owner":"UCL","description":"Multiple imputation sensitivity analysis for longitudinal trials ","archived":false,"fork":false,"pushed_at":"2024-09-04T12:31:35.000Z","size":9383,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-05T14:26:48.165Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UCL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-29T14:11:18.000Z","updated_at":"2024-09-04T12:31:40.000Z","dependencies_parsed_at":"2024-08-27T15:12:08.831Z","dependency_job_id":"22b5af10-6a95-4740-be27-b3eb5fa6cfee","html_url":"https://github.com/UCL/RefbasedMI","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UCL%2FRefbasedMI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UCL%2FRefbasedMI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UCL%2FRefbasedMI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UCL%2FRefbasedMI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UCL","download_url":"https://codeload.github.com/UCL/RefbasedMI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246093168,"owners_count":20722403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-28T20:19:13.206Z","updated_at":"2026-02-26T08:19:26.787Z","avatar_url":"https://github.com/UCL.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href =\"https://www.mrcctu.ucl.ac.uk/\"\u003e\u003cimg src=\"MRCCTU_at_UCL_Logo.png\" width=\"50%\" /\u003e\u003c/a\u003e\n\n# RefBasedMI\n *0.2.0*\n\n# An R package for Reference-based multiple imputation for sensitivity analysis of longitudinal trials with protocol deviation\n\n# Background\n\nWe have ported the functionality of the Stata program **mimix**  into the R package RefBasedMI, and added extra functionality including options for the Causal model and Delta adjustment. \n\nThe **mimix** program is described in the paper\n\n\u003e Reference-based sensitivity analysis via multiple imputation for longitudinal trials with protocol deviation\nby Suzie Cro, Tim P. Morris, Michael G. Kenward, and James R. Carpenter\nhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC5796638/\n\nand can be accessed by typing (within Stata) \"ssc install mimix\" to install the code  and \"help mimix\" to read help documentation.\n \n# Imputation methods\n\nThe five **reference-based imputation methods** available in RefBasedMI are:\n \n| Method         | Abbreviation             | Reference group required? |\n| --------------- | --------------- | --------------------  |\n| Randomized-arm                | MAR | No |\n| Jump to reference\t            | J2R | Yes |\n| Copy increments in reference\t| CIR | Yes |\n| Copy reference\t              | CR  | Yes |\n| Last mean carried forward\t    | LMCF| No |\n\nIn the **Causal model**, the maintained treatment effect after treatment discontinuation is related to the final treatment effect: it is either a constant fraction (specified by K0), or decays exponentially by being multiplied by specifying a K1 value (0\u003c=K1\u003c=1) in every period. Values K0=1, K1=0 are equivalent to method J2R, whilst values K0=1, K1=1 are equivalent to method CIR. \n\nFull details of the **Causal model** are in the paper by White, Royes and Best: https://www.tandfonline.com/doi/full/10.1080/10543406.2019.1684308.\n\nIn **Delta adjustment**, imputations differ sytematically from values imputed by the above methods to an extent specified by parameters delta and dlag. \nThese specify an increment which is added on to all values imputed after \ntreatment discontinuation, but not on to interim (intermediate) missing values. \nValues of delta are cumulated after treatment discontinuation.\nFor example, for an individual who discontinued treatment at the 2nd time point, we take \nthe vector of delta's starting at the 3rd time point and add their cumulative sums to the imputed values. \nSpecifying dlag modifies this behaviour, so that the vector of delta's starting at the 3rd time point is \nmultipled elementwise by the vector dlag.\nThe formula for the increment at time k for an individual who discontinued after time p is \n`delta[p+1]*dlag[1] + delta[p+2]*dlag[2] + ... + delta[k]*dlag[k-p]`.\nA common increment of 3 at all time points after treatment discontinuation is achieved \nby setting  `delta=c(3,3,3,...)` and `dlag=c(1,0,0,...)`, both vectors having the length of the number of time points.\n\nFor further details of **Delta adjustment**, \nsee James Roger's SAS programs and user-guide under \"Reference-based MI via Multivariate Normal RM (the \"five macros\" and MIWithD)\" at  \nhttps://www.lshtm.ac.uk/research/centres-projects-groups/missing-data#dia-working-group.\n\n\n# Installation\n\nWithin the R environment type \n\n    if(!require(devtools)) install.packages('devtools') \n\n    library(devtools) \n\nfollowed by \n\n    devtools::install_github(\"UCL/RefBasedMI\")\n\n\n# Usage\n\n**RefBasedMI**(data,covar,depvar,treatvar,idvar,timevar,..... options.....)\n\n\n# Arguments \n\n**data**\t       dataset in wide (longitudinal data) format\n\n**covar**       baseline covariates and/or baseline depvar, must be complete (no missing vaules) and treated as numeric\n\n**depvar**\t     dependent variable\n\n**treatvar**   \ttreatment group\n\n**idvar**\t      patient id\n\n**timevar**\t    time point for repeated measures\n\n**M**\t          number of imputations\n \n**reference**\t      reference group for J2R, CIR, CR and Causal methods\n\n**method**\t       imputation method\n\n**seed**\t    seed value to obtain same outputs\n\n**prior**     prior to use in mcmcNorm: jeffreys (default), uniform or ridge\n\n**burnin**\t     number of burnin iterations in MCMC\n\n**bbetween**\t   number of iterations between imputed data sets in MCMC\n\n**methodvar**   variable in data specifying the individual imputation method \n\n**referencevar**   variable in data specifying the individual reference group\n\n**delta**       vector of delta values to add onto imputed values (a values in Roger's paper) (non-mandatory)\n\n**dlag**        vector of dlag values (b values in Roger's paper)\n\n**K0**\t         causal constant for use with Causal method\n\n**K1**\t         exponential decaying causal constant for use with Causal method\n\n\n\n# Examples\n\n## Sample data: asthma trial\n\n### J2R imputation with control as reference\n\tasthmaJ2R \u003c- RefBasedMI(data = asthma, covar = base, depvar = fev, treatvar = treat,\t\n\t\tidvar = id, timevar = time, method = \"J2R\", reference = 2, M = 5, seed = 101, \n\t\tprior = \"ridge\", burnin = 1000)`\n \n### Analysis\n\nFit specified model to each imputed data set (assigned as mids class) and pool results together (Rubin's rules),\nfunctions from mice package:\n\n\tlibrary(mice)\n\n\tfit\u003c-with(as.mids(subset(asthmaJ2R,time==12)), lm(fev~treat+base))\n\n\tsummary(pool(fit))\n\n\n### Delta-adjustment imputation - all values are 1 unit lower than expected under J2R\n\n\timpJ2Rridge \u003c- RefBasedMI(data = asthma, covar = c(base), depvar = fev, treatvar = treat,\t\n\t\tidvar = id, timevar = time, method = \"J2R\", reference = 2, \n\t\tdelta = c(-1, 0, 0, 0), M = 5, seed = 101, prior = \"ridge\")      \n\n\tfit\u003c-with(as.mids(subset(impJ2Rridge,time==12)), lm(fev~treat+base))\n\n\tsummary(pool(fit))\n\n\n\n## Sample data: antidepressant trial\n\n### Mixed imputation methods \n\n`methodcol` and `referencecol` are variables in the data set \n\nNOTE - either `method` or `methodvar` must specified but NOT both\n\n\tantidepIndiv \u003c- RefBasedMI(data = antidepressant, covar = c(basval, PATIENT.SEX),\n\t\tdepvar = HAMD17.TOTAL, treatvar = TREATMENT.NAME, idvar = PATIENT.NUMBER, \n\t\ttimevar = VISIT.NUMBER, methodvar = methodcol, referencevar = referencecol, \n\t\tM = 5, seed = 54321)        \n\n### Analysis\n\n\tantidepIndiv \u003c- with(data =  as.mids(subset(antidepIndiv, VISIT.NUMBER == 7)),\t\n\t\tlm(HAMD17.TOTAL ~ TREATMENT.NAME + basval + PATIENT.SEX))\n\t\n\tsummary(pool(antidepIndiv))  \n\n## Sample data: acupuncture trial \n\n### Causal model imputation\n\nWe assume that the treatment effect halves every 1 time unit after treatment discontinuation, so K0 = 1 and K1 = 0.5.\nNote that K0=1, K1=0 would be equivalent to J2R, and K0=1, K1=1 would be equivalent to CIR.\n\n\tacuCausal \u003c- RefBasedMI(data = acupuncture, covar = c(head_base), depvar = head,\t\n\t\ttreatvar = treat, idvar = id, timevar = time, method = \"Causal\", \n\t\treference = 1, K0 = 1, K1 = 0.5, M = 5, seed = 54321)\n\t \n### Analysis\n\n\tacufit \u003c- with(as.mids(subset(impCausalref, time == 12)), lm(head ~ treat + head_base))\n\t\n\tsummary(pool(acufit))    \n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucl%2Frefbasedmi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fucl%2Frefbasedmi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucl%2Frefbasedmi/lists"}