[英]Feeding new data to existing model and using broom::augment to add predictions
[英]Defining a new model in crmPack and feeding it new data using “update” function
我已經按照crmPack(第16-17頁)插圖中提供的代碼來定義單參數功率模型。 我需要使用更新功能為它提供一些毒性數據,但我得到的錯誤是“沒有名稱的插槽”調用“”。 這是下面的代碼。 我會非常感謝任何評論或想法,以“解決”這個問題。 非常感謝。
# package and options
library(crmPack)
options <- McmcOptions(burnin = 1000, step = 2, samples = 5000)
set.seed(1)
# extra functions to define the power model
.OneParExp <- setClass(Class = "OneParExp", contains = "Model",
representation(skeletonFun = "function",
skeletonProbs = "numeric",
lambda = "numeric"))
OneParExp <- function(skeletonProbs, doseGrid, lambda)
{
skeletonFun <- approxfun(x = doseGrid, y = skeletonProbs, rule = 2)
invSkeletonFun <- approxfun(x = skeletonProbs, y = doseGrid, rule = 1)
.OneParExp(
skeletonFun = skeletonFun, skeletonProbs = skeletonProbs,
lambda = lambda,
datamodel = function(){
for (i in 1:nObs)
{
y[i] ~ dbern(p[i])
p[i] <- skeletonProbs[xLevel[i]]^theta
}},
datanames = c("nObs", "y", "xLevel"),
prob = function(dose, theta){ skeletonFun(dose)^theta },
dose = function(prob, theta){ invSkeletonFun(prob^(1 / theta)) },
priormodel = function(){ theta ~ dexp(lambda) },
modelspecs = function(){ list(skeletonProbs = skeletonProbs,
lambda = lambda) },
init = function(){ list(theta = 1) }, sample = "theta")
}
# tox data and model fitting
data <- Data(x = c(1.2,1.2,1.8,2.4,3),
y = c(0, 0, 0, 1, 1),
cohort = c(1, 1, 2, 3, 4),
doseGrid = seq(1.2, 3, 0.6),
ID = 1:5,
placebo = FALSE)
(skeletonProbs <- round(data@doseGrid / max(data@doseGrid) / 4, 2))
newModel <- OneParExp(skeletonProbs = skeletonProbs,
doseGrid = data@doseGrid, lambda = 1)
newDLTmodel <- update(object=newModel, data=data)
您不在此處使用“更新”功能將數據提供給模型。 (“更新”方法主要是更新crmPack中“數據”對象的內部方法。)而是使用“mcmc”來估計給定模型和數據的參數:
estimates <- mcmc(model=newModel, data=data, options=McmcOptions())
plot(estimates, newModel, data)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.