1

I want to perform a time-to-event analysis using qgcomp package. I used qgcomp.cox.boot function and adjusted for confounding factors. However I have encountered some problems.

library("ggplot2")
data("metals", package="qgcomp")

Xnm <-c('arsenic','barium','cadmium','calcium','chromium','copper','iron','lead','magnesium','manganese','mercury','selenium','silver','sodium','zinc')

qc.survfit2 <- qgcomp.cox.boot(Surv(disease_time, disease_state) ~ arsenic+barium+cadmium+calcium+chromium+copper+iron+lead+magnesium+manganese+mercury+selenium+silver+sodium+zinc+ph,expnms=Xnm,data=metals[,c(Xnm, 'disease_time', 'disease_state')], q=4,B=5, MCsize=1000, parallel=TRUE, parplan=TRUE)         #ph is a confounding factor
Error in eval(predvars, data, env) : object 'ph' not found

Then I fixed the code as followed:

qc.survfit2 <- qgcomp.cox.boot(Surv(disease_time, disease_state) ~ arsenic+barium+cadmium+calcium+chromium+copper+iron+lead+magnesium+manganese+mercury+selenium+silver+sodium+zinc+metals$ph,expnms=Xnm,data=metals[,c(Xnm, 'disease_time', 'disease_state')], q=4,B=5, MCsize=1000, parallel=TRUE, parplan=TRUE)

Error in model.frame.default(data = list(id__ = c(2L, 2L, 3L, 3L, 3L,  : 
variable lengths differ ('metals$ph')

Can anyone solve this problem? Thanks a lot.

I have googled this quite a lot, however they didn't solve my problem. In the linear model, I can adjust for confounding factors by inputting the variable name directly. However, it did not work in the time-to-event analysis with qgcomp.cox.boot function.

Curry Qin
  • 11
  • 2
  • Have you tried adding `'ph'` to your `Xnm` vector? – zephryl Dec 10 '22 at 05:40
  • Yes, as you said, adding 'ph' to Xnm vector can solve this problem. However, Xnm is a mixture of metals, and ph is a covariate. Although the code works, it doesn't seem to be the correct method to adjust for confounding factors. More details are available at https://cran.r-project.org/web/packages/qgcomp/vignettes/qgcomp-vignette.html. Thank you very much for your suggestions! – Curry Qin Dec 10 '22 at 09:52

1 Answers1

0

Your problem is that you’re including ph in your model, but subsetting metals to not include ph. I can see that in the vignette you linked, they do sometimes subset metals, but this is only a matter of convenience to use y~. notation, it’s not necessary. So you can either leave metals as is:

library(survival)
library(qgcomp)
data(metals)

Xnm <-c('arsenic','barium','cadmium','calcium','chromium','copper','iron','lead','magnesium','manganese','mercury','selenium','silver','sodium','zinc')

qc.survfit2 <- qgcomp.cox.boot(
  Surv(disease_time, disease_state) ~ arsenic+barium+cadmium+calcium+chromium+copper+iron+lead+magnesium+manganese+mercury+selenium+silver+sodium+zinc+ph,
  expnms=Xnm,
  data=metals, 
  q=4,
  B=5, 
  MCsize=1000, 
  parallel=TRUE, 
  parplan=TRUE
)

Or, if you want to use y~. notation, make sure to include ph in your subset:

qc.survfit2 <- qgcomp.cox.boot(
  Surv(disease_time, disease_state) ~ .,
  expnms=Xnm,
  data=metals[,c(Xnm, 'ph', 'disease_time', 'disease_state')], 
  q=4,
  B=5, 
  MCsize=1000, 
  parallel=TRUE, 
  parplan=TRUE
)
zephryl
  • 14,633
  • 3
  • 11
  • 30
  • 1
    Your answer solved my problem perfectly. As a rookie of R, I learned a lot from it. Thank you so much. – Curry Qin Dec 11 '22 at 11:17