Calculate the log-probability and the gradient w.r.t. each input for a given vector of unconstrained parameters — fit-method-grad_log_prob • cmdstanr
Description: The $grad_log_prob() method provides access to the Stan model's log_prob function and its derivative.

# Calculate the log-probability and the gradient w.r.t. each input for a given vector of unconstrained parameters

Source: `R/fit.R`
`fit-method-grad_log_prob.Rd`

The `$grad_log_prob()` method provides access to the Stan model's `log_prob` function and its derivative.

    grad_log_prob(unconstrained_variables, jacobian_adjustment = TRUE)

## Arguments

unconstrained_variables

  (numeric) A vector of unconstrained parameters to be passed to `grad_log_prob`.

jacobian_adjustment

  (logical) Whether to include the log-density adjustments from un/constraining variables.

## See also

`log_prob()`, `grad_log_prob()`, `constrain_variables()`, `unconstrain_variables()`, `unconstrain_draws()`, `variable_skeleton()`, `hessian()`

## Examples

    # \dontrun{
    fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
    #> Compiling Stan program...
    fit_mcmc$init_model_methods()
    #> Compiling additional model methods...
    fit_mcmc$grad_log_prob(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2))
    #> [1]   1.462151 -26.619534 -25.528776 -14.286822
    #> attr(,"log_prob")
    #> [1] -130.2141
    # }