This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Dose-response plot when using "noboot" | |
| # example: plotting odds ratio as function of exposure | |
| # problem: The default plot option in qgcomp for noboot objects just gives a histogram for the weights. | |
| # It's not always clear how to do something like a dose-response function | |
| # solution: Explicitly use the "bounds" functions | |
| library(qgcomp) | |
| library(ggplot2) | |
| # example data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(qgcomp) | |
| set.seed(50) | |
| N=200 | |
| dat <- data.frame(time=(tmg <- pmin(.1,rweibull(N, 10, 0.1))), | |
| d=1.0*(tmg<0.1), x1=runif(N), x2=runif(N), z=runif(N)) | |
| expnms=paste0("x", 1:2) | |
| f = survival::Surv(time, d)~x1 + x2 + z | |
| (qfit <- qgcomp.cox.boot(f, expnms = expnms, data = dat, deg=2, B=10, MCsize=20000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # using BKMRhat with multiple imputation | |
| library(bkmrhat) | |
| library(mice) | |
| library(bkmr) | |
| library(future) | |
| # create simulated dataset for testing | |
| dat <- bkmr::SimData(n = 50, M = 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(qgcomp) | |
| library(survival) | |
| library(ggplot2) | |
| set.seed(50) | |
| N=200 | |
| dat <- data.frame(time=(tmg <- pmin(.1,rweibull(N, 10, 0.1))), | |
| d=1.0*(tmg<0.1), x1=runif(N), x2=runif(N), z=runif(N)) | |
| expnms=paste0("x", 1:2) | |
| f = survival::Surv(time, d)~x1 + x2 + I(x2*x1) | |
| ## Not run: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # simple example of using Bayes to penalize estimates in quantile g-computation | |
| library(qgcomp) | |
| library(MASS) | |
| n= 50 | |
| Sigma <- matrix(c(10,3,3,2),2,2) | |
| Sigma | |
| set.seed(1232) | |
| X = MASS::mvrnorm(n, mu=rep(0,2), Sigma) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # simple application of qgcomp with time-varying exposures | |
| # the simulated model is for the discrete hazard, given recent exposure and recent values of confounders | |
| # this method can be used for alternative scenarios (e.g. cumulative exposure), which corresponds to | |
| # different parametric assumptions | |
| library(qgcomp) | |
| library(survival) | |
| # create simple data set with time-varying exposures | |
| makedata <- function(N=100){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # scoping issue when using in-formula transformations | |
| # example: spline basis functions | |
| # problem: when including functions like `rms(x)` in a formula to put a spline | |
| # function on 'x', plotting a qgcomp.cox.boot object yields an error that 'x' can't be found | |
| # solution: explicitly create the spline basis functions as variables in a data.frame. Example follows. | |
| library(qgcomp) | |
| library(rms) | |
| library(survival) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # qgcomp with a gee like approach using bootstrapping or an estimating equation based approach - useful for clustered or longitudinal data when the interest is in effect of x -> y, pooled over multiple time points | |
| library(qgcomp) | |
| library(qgcompint) # requires version 0.8+, which may not be on cran but can be obtained via qgcompint:::.devinstall() | |
| set.seed(50) | |
| ####### simulate some clustered data ----- | |
| # linear model, binary modifier | |
| # simulate cluster specific exposures and outcome means by just treating these like independent observations | |
| dat <- qgcompint::simdata_quantized_emm(outcometype = "continuous", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(qgcomp) | |
| msm.fit.noint <- function(f, | |
| qdata, | |
| intvals, | |
| expnms, | |
| rr=TRUE, | |
| main=TRUE, | |
| degree=1, | |
| id=NULL, |
NewerOlder