jthaman / ciTools

An R Package for Quick Uncertainty Intervals
GNU General Public License v3.0
106 stars 9 forks source link

Error in predict add_pi.survreg #48

Closed sriharitn closed 3 years ago

sriharitn commented 3 years ago

When I run the survreg with boot option, I get the error.

> ## Define a data set.
> df <- survival::stanford2
> ## remove a covariate with missing values.
> df <- df[, 1:4]
> ## next, create the Surv object inside the survreg call:
> fit <- survival::survreg(survival::Surv(time, status) ~ age + I(age^2),
+                          data = df, dist = "lognormal")
> add_pi(df, fit, alpha = 0.1, names = c("lwr", "upr"),method="boot")
Error in MASS::mvrnorm(nSims, beta.hat, vcov.hat) : 
  incompatible arguments

I know what is causing it, basically, the scale coefficient is not being picked up with Log(scale).

> vcov(fit)
             (Intercept)           age      I(age^2)    Log(scale)
(Intercept)  3.453920115 -0.1844604713  2.304116e-03  0.0052810250
age         -0.184460471  0.0105711147 -1.379510e-04  0.0001468898
I(age^2)     0.002304116 -0.0001379510  1.854279e-06 -0.0000039567
Log(scale)   0.005281025  0.0001468898 -3.956700e-06  0.0049915276
> coef(fit)
 (Intercept)          age     I(age^2) 
 3.344231092  0.226092785 -0.003504315 
jthaman commented 3 years ago

Can you test?

devtools::install_github("jthaman/ciTools")