multinma icon indicating copy to clipboard operation
multinma copied to clipboard

No parameter "beta_aux"

Open dkarletsos opened this issue 1 year ago • 1 comments

Hi,

The following code works when likelihood is set to 'msplines' but returns the error below when 'exponential' or 'weibull' or any other likelihood that is not 'mspline'. Am I missing any settings in nma() ?

CODE:

    fit <- nma(net,
               regression = ~(covariate1 + covariate2)*.trt,
               likelihood = likelihood,
               prior_intercept = normal(0, 100),
               prior_trt = normal(0, 100),
               prior_reg = normal(0, 100),
               prior_aux = half_normal(1),
               QR = TRUE,
               aux_regression = ~.trt)

    refdat <- (...)

    hazard_ratios <- multinma::marginal_effects(fit,
                                                type = "hazard",
                                                mtype = "ratio",
                                                baseline = "Study-1",
                                                aux = "Study-1",
                                                newdata = refdat,
                                                times = refdat$times,
                                                all_contrasts = FALSE,
                                                trt_ref = reference_treatment)

ERROR:

Error in `as.array()`:
! No parameter "beta_aux".
Run `rlang::last_trace()` to see where the error occurred.

> rlang::last_trace()
<error/rlang_error>
Error in `as.array()`:
! No parameter "beta_aux".
---
Backtrace:
    ▆
 1. ├─multinma::marginal_effects(...)
 2. │ └─rlang::eval_tidy(...)
 3. ├─stats (local) `<fn>`(...)
 4. ├─multinma:::predict.stan_nma_surv(...)
 5. ├─base::NextMethod(...)
 6. └─multinma:::predict.stan_nma(...)
 7.   ├─base::as.array(object, pars = "beta_aux")
 8.   └─multinma:::as.array.stan_nma(object, pars = "beta_aux")

dkarletsos avatar Jul 17 '24 12:07 dkarletsos

Hi @dkarletsos, thanks for reporting this.

I can recreate the error with likelihood = "exponential"; the issue is caused by predict() trying to access the auxiliary regression parameters beta_aux when there are none, because the exponential model has no shape parameters. Both aux_regression and aux_by have no effect for the exponential model, and are ignored.

This is fixed in the latest development version, and I have also added informative warning messages when aux_regression or aux_by are being ignored (e.g. for the exponential model).

You can install this latest version from r-universe:

install.packages("multinma", repos = c("https://dmphillippo.r-universe.dev", getOption("repos")))

I don't see errors for any other likelihoods, these are behaving as expected in my testing. Are you still seeing other errors?

dmphillippo avatar Jul 31 '24 08:07 dmphillippo