# NOT RUN {
GenerateData <- function(n)
{
x1 <- runif(n, min=-0.5,max=0.5)
x2 <- runif(n, min=-0.5,max=0.5)
error <- rnorm(n, sd= 0.5)
tp <- exp(-1+1*(x1+x2))/(1+exp(-1+1*(x1+x2)))
a <- rbinom(n = n, size = 1, prob=tp)
y <- 1+x1+x2 + a*(3 - 2.5*x1 - 2.5*x2) + (0.5 + a*(1+x1+x2)) * error
return(data.frame(x1=x1,x2=x2,a=a,y=y))
}
n <- 300
testData <- GenerateData(n)
# 1. Estimate the 0.25th-quantile optimal treatment regime. ###
# }
# NOT RUN {
fit1 <- IPWE_Qopt(data = testData, regimeClass = "a~x1+x2",
tau = 0.25, moPropen="a~x1+x2")
fit1
# }
# NOT RUN {
# 2. Go parallel. This saves time in calculation. ###
# }
# NOT RUN {
fit2 <- IPWE_Qopt(data = testData, regimeClass = "a~x1+x2",
tau = 0.25, moPropen="a~x1+x2", cl.setup=2)
fit2
# }
# NOT RUN {
# }
# NOT RUN {
# 3. Set a quardratic term in the class #######################
# }
# NOT RUN {
fit3 <- IPWE_Qopt(data = testData, regimeClass = "a~x1+x2+I(x1^2)",
tau = 0.25, moPropen="a~x1+x2", pop.size=1000)
fit3
# }
# NOT RUN {
# 4. Set screen prints level. #######################
# Set the p_level to be 0,
# then all screen prints from the genetic algorithm will be suppressed.
# }
# NOT RUN {
fit4 <- IPWE_Qopt(data = testData, regimeClass = "a~x1+x2",
tau = 0.25, moPropen="a~x1+x2", cl.setup=2, p_level=0)
fit4
# }
Run the code above in your browser using DataLab