This file contains 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 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 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 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 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 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) | |
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 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, |
This file contains 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 qgcomp.cox.noboot in a nested case-control analysis as a way to fit a conditional logit qgcomp model | |
library(qgcomp) | |
library(survival) | |
# read in data from a nested case control study | |
data(infert, package = "datasets") | |
head(infert) | |
### 1) check that it works, part A |
This file contains 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
#!/usr/local/env R | |
# a way to base the quantiles off of weighted data | |
library(qgcomp) | |
library(DescTools) # need this to calculate weighted quantiles | |
data(metals) | |
# new function to calculate weighted quantiles | |
quantize.wtd <- function (data, expnms, q = 4, breaks = NULL, weights=NULL) | |
{ |
NewerOlder