Unused Argument, help with code from publication

Hi everyone,

I am attempting to copy code taken from the article "Decision curve analysis: a technical note" (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6123195/)

When I try to make the simple model taken from the article, I get this error:

"Error in ntbft(data = dt, outcome = outcome, from = model1, xstart = xstart, :

unused argument (from = model1)"

I have no explanation for why this is happening, I am 99% sure I am copying the code correctly. I would appreciate the help!

This code requires nothing to download from except one package, so if anyone would like to copy the code themselves to see if they get this error, here it is:

set.seed(123)

n<-500

rr<-round(abs(rnorm(n,30,10)))

hr<-round(abs(rnorm(n,90,20)))

crp<-round(abs(rnorm(n,150,80)))

install.packages("dummies")

beta0=-7;betarr=0.05

betahr=0.02;betacrp=0.02

linpred<-cbind(1,rr,hr,crp)%*%

c(beta0,betarr,betahr,betacrp)

pi<-exp(linpred)/(1+exp(linpred))

sepsis.tag<-rbinom(n=n,size=1,prob=pi)

dt<-data.frame(rr,hr,crp,sepsis.tag)

ntbft<-function(data,outcome, frm = NULL,

exterdt=NULL, pred=NULL, xstart=0.01,

xstop=0.99, step=0.01, type="treated"){

pt<-seq(from=xstart,to=xstop,by=step)

lpt<-length(pt)

if(type=="treated") coef<-cbind(rep(1,lpt),rep(0,lpt))

if(type=="untreated") coef<-cbind(rep(0,lpt),rep(1,lpt))

if(type=="overall") coef<-cbind(rep(1,lpt),rep(1,lpt))

if(type=="adapt") coef<-cbind(1-pt,pt)

reponse<-as.vector(t(data[outcome]))

if(is.data.frame(exterdt))response<-as.vector(t(exterdt[outcome]))

event.rate<-mean(response)

nball<-event.rate-(1-event.rate)*pt/(1-pt)

nbnone<-1-event.rate-event.rate*(1-pt)/pt

if(is.null(pred)){

model<-glm(frm,data=data,family=binomial("logit"))

pred<-model$fitted.values

if(is.data.frame(exterdt))

pred<-predict(model,newdata=exterdt,type="response")

}

N<-length(pred)

nbt<-rep(NA,lpt)

nbu<-rep(NA,lpt)

for(t in 1:lpt){

tp<-sum(pred>=pt[t]&response==1)

fp<-sum(pred>=pt[t]&response==0)

fn<-sum(pred<pt[t]&response==1)

tn<-sum(pred<pt[t]&response==0)

nbt[t]<-tp/N-fp/N*(pt[t]/(1-pt[t]))

nbu[t]<-tn/N-fn/N*((1-pt[t])/pt[t])

}

nb<-data.frame(pt)

names(nb)<-"threshold"

nb["all"]<-coef[,1]*nball

nb["none"]<-coef[,2]*nbnone

nb["pred"]<-coef[,1]*nbt+coef[,2]*nbu

return(nb)

}

outcome<-"sepsis.tag"

model1<-sepsis.tag~rr+hr

model2<-sepsis.tag~rr+hr+crp

xstart<-0.01;xstop<-0.99;step<-0.01

type<-"treated"

nb.simple<-ntbft(data=dt, outcome=outcome,

from=model1,xstart=xstart,xstop=xstop,

step=step, type=type)

Typo. You spelled the argument "frm" rather than "from".

It apparently is not a typo according to the article:

frm : a formula in the form of outcome~predictor 1 + predictor 2, where each variable should be the contained in the data frame. The argument specifies the prediction model to be fitted in case the argument pred below is NULL (if the pred argument is provided, frm is not used).

Should be frm = model1

ntbft<-function(data, outcome, frm=NULL,
exterdt=NULL,pred=NULL, xstart=0.01,
xstop=0.99,step=0.01,type="treated"){ \dots

from the article cited.

When you called the function you spelled the argument "from" rather than "frm".

1 Like

When I changed that, I got this error:

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'mean': object 'response' not found

When I changed that, I got this error:

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'mean': object 'response' not found

Is it in namespace with ls()? Otherwise should it be response?

More typos. You spelled it

1 Like

It always seems to come down to spelling and punctuation for so many problems.

1 Like

ugh yep you found it, thank you so much!

Hate when it is that simple, thank you!

1 Like

Never happens to me, myself, personally.:joy:

1 Like

Actually, could you help me understand how to fix this next error I am having with the code:

"Error in data[ii, ] : object of type 'closure' is not subsettable"

From the article, the argument ii to allow boot() function to select a sample

Whenever you see a closure error, it means that the name of a function is being used inappropriately. data() is a function. It's possible in theory to predict when a user object of the same name will conflict, but better to avoid with Data data_ my_data or similar.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.