knitr::opts_chunk$set(echo = TRUE)
This package implements methods for methods for conducting subgroup analyses and estimating the impact of implementing the optimal individualized treatment strategy in the population.
To install the package via devtools, use
devtools::install_github("alexluedtke12/sg")
We now present an example on a sample of size n=1000. The SuperLearner library is small so that the example does not take long to run -- in practice, we recommend using a larger SuperLearner library.
library(quadprog) library(nnls) library(SuperLearner)
library(sg) sim.data = function(nn){ W = data.frame(W1=rnorm(nn),W2=rnorm(nn),W3=rnorm(nn),W4=rnorm(nn)) A = rbinom(nn,1,1/2) Y = rbinom(nn,1,Qbar(A,W)) return(list(W=W,A=A,Y=Y)) } SL.library = c('SL.mean','SL.glm') n = 1000 Qbar = function(a,w){plogis(-1 + 2*a*w$W1)} # function(a,w){plogis(a*(w$W1>0)*w$W1)} # data to run methods on dat = sim.data(n) W = dat$W A = dat$A Y = dat$Y # data to evaluate true parameter values n.mc = 2e4 dat = sim.data(n.mc) W.mc = dat$W A.mc = dat$A Y.mc = dat$Y blip.mc = Qbar(1,W.mc)-Qbar(0,W.mc)
Below each example, we also print the true impact of implementing the rule, i.e. the quantity that sg.cvtmle is estimating.
# Contrast optimal treatment strategy against treating with probability 1/2 sg.cvtmle(W,A,Y,SL.library=SL.library,txs=c(0,1),baseline.probs=c(1/2,1/2),CATE.SL.library=SL.library,sig.trunc=0.001,family=binomial(),kappa=1,num.SL.rep=2,num.est.rep=2,lib.ests=TRUE,verbose=FALSE) # truth mean(Qbar(1,W.mc)*((blip.mc>0)-1/2) + Qbar(0,W.mc)*((blip.mc<=0)-1/2)) # Contrast optimal treatment strategy against treating everyone with tx 0 sg.cvtmle(W,A,Y,SL.library=SL.library,txs=c(0,1),baseline.probs=c(1,0),CATE.SL.library=SL.library,sig.trunc=0.001,family=binomial(),kappa=1,num.SL.rep=2,num.est.rep=2,lib.ests=TRUE,verbose=FALSE) # truth mean((blip.mc)*(blip.mc>=0)) # Resource constraint: at most 25% can be treated. Contrast against treating everyone with tx 0 sg.cvtmle(W,A,Y,SL.library=SL.library,txs=c(0,1),baseline.probs=c(1,0),CATE.SL.library=SL.library,sig.trunc=0.001,family=binomial(),kappa=0.25,num.SL.rep=2,num.est.rep=2,lib.ests=TRUE,verbose=FALSE) # truth mean((blip.mc)*(blip.mc>=max(quantile(blip.mc,1-0.25),0)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.