The predict () function does not accept exponential regression in R

2

Please try to perform parametric survival analysis modeling and the predict() function is returning an error that it does not recognize a variable, but it is there.

Here's an example:

base=NULL

base$DIAS= c(7,6,8,6,5,5,5,6,6,11,6,4,5,5,5,5,6,4,5,6)

base$DELTA= c(0,1,0,1,0,1,1,0,1,1,0,0,0,1,1,1,1,0,0,0)

base$Protocolo= c(1,0,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1)

base$TIPAC= c(1,0,1,0,0,0,0,1,1,1,0,1,1,1,1,1,0,0,0,0)

base=data.frame(base)

modelo <- survreg(Surv(DIAS,DELTA) ~ Protocolo+TIPAC,data= base, dist = "exponential")

ptempo <- predict(modelo , type = "quantile", newdata= data.frame(1), p=1:99/100,se=TRUE)
  

Error in eval (expr, envir, enclos): 'Protocol' object not found

    
asked by anonymous 27.04.2016 / 02:09

1 answer

1

In your code, you use base as argument data , but I imagine you meant modelo . It is not good practice to use the same variable name for completely different objects as well (the data frame and regression). (Modified after AP editing)

Returning to your problem, the error occurs because you pass a data frame that does not have a column called Protocolo when it calls the predict . You must pass a new dataset of the same format as the data used in the regression (with the same variables used in the formula), or leave it blank, to perform the prediction with the initial data. The code below works:

base <- data.frame(DIAS = c(7,6,8,6,5,5,5,6,6,11,6,4,5,5,5,5,6,4,5,6),
                     DELTA = c(0,1,0,1,0,1,1,0,1,1,0,0,0,1,1,1,1,0,0,0),
                     Protocolo = c(1,0,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1),
                     TIPAC = c(1,0,1,0,0,0,0,1,1,1,0,1,1,1,1,1,0,0,0,0))

library(survival)
modelo <- survreg(Surv(DIAS, DELTA) ~ Protocolo + TIPAC, data = base, dist = "exponential")

ptempo <- predict(modelo , type = "quantile", p = 1:99/100, se = TRUE)
str(ptempo)
# List of 2
#  $ fit   : num [1:20, 1:99] 0.1285 0.0929 0.1285 0.1228 0.0929 ...
#  $ se.fit: num [1:20, 1:99] 0.0587 0.0552 0.0587 0.0701 0.0552 ...
    
27.04.2016 / 02:57