首页 > 解决方案 > 以非交互方式运行期望交互式输入的 R 包

问题描述

在 R 编程方面,我有点新手,所以如果这听起来很明显或被误导,请原谅我。

我正在使用一个名为 bcrm 的 R 包(它为癌症临床试验的剂量升级做了一些聪明的事情),当我以交互方式运行它时,它要求我通过终端输入。

我希望能够以非交互方式运行它。有什么方法可以编写一个脚本,其中不仅包括调用 bcrm 包的命令,还包括它随后提出的问题的答案?

2018 年 12 月 21 日编辑:这是要求我进行交互式输入的代码。我很想在提供输入的最后一点(或者可能在 DOS 批处理脚本中)之后放置一些代码,其中包括输入一系列数字。

library(bcrm)

dose.levels <- c(1, 2, 3, 4)
prior.tox <- c(0.05, 0.1, 0.2, 0.3)
cohort.size <- 3
target.tox <- 0.33
max.size <- 6
prior.mean <- c(-0.5, 0.01)
prior.vcm <- matrix(c(0.5, 0.3, 0.3, 2), ncol=2)
prior.dist <- list(4, prior.mean, prior.vcm) 

tox.seq <- c(0, 0, 0)
dose.seq <- c(1, 1, 1)

mydata <- data.frame(patient = 1:3, dose=dose.seq, tox=tox.seq)




crm<-bcrm(dose = dose.levels,               # Dose levels
          p.tox0 = prior.tox,               # Prior probabilities of DLT
          target.tox = target.tox,          # Target tox level
          cohort = cohort.size,             # Cohort size
          stop = list(nmax = max.size),     # Stopping criteria
          ff = "logit2",                    # Model
          prior.alpha = prior.dist,         # Prior distribution on model parameter
          sdose.calculate = "median",       # How to calculate dose labels
          pointest = "plugin",              # How we will estimate DLT risks
          data = mydata,                    # Data so far
          simulate = FALSE,                 # Simulate lots of trials?
          method="rjags",                   # Calculation method
          truep = prior.tox,                # True probabilities, assume same as prior
          plot = TRUE)                      # Plot trial data as we go

标签: r

解决方案


查看返回值的数据结构,您似乎可以提取与设置模拟 = 假相同的输出值,如果您设置模拟 = True 和 nsims = 1

例如设置模拟=假给出:

crm$ndose[[1]][[1]] # returns [1] 2

设置模拟 = true 和 nsims = 1 给出:

crm[[1]]$ndose[[1]][[1]]

像以前一样返回 2,所有其他值也相同。


推荐阅读