prior_loglik: Log-Prior Distribution Evaluation for lgspline Models

View source: R/prior_loglik.R

prior_loglikR Documentation

Log-Prior Distribution Evaluation for lgspline Models

Description

Evaluates the log-prior on the spline coefficients conditional on the dispersion and penalty matrices.

Usage

prior_loglik(
  model_fit,
  B_predict = NULL,
  sigmasq_predict = NULL,
  include_constant = TRUE,
  ...
)

Arguments

model_fit

An lgspline model object.

B_predict

Optional list of coefficient vectors at which to evaluate the prior. Default NULL uses the fitted coefficients.

sigmasq_predict

Numeric scalar dispersion parameter. If NULL, model_fit$sigmasq_tilde is used. Legacy sigmasq calls are still accepted.

include_constant

Logical; if TRUE (default), include the multivariate normal normalizing constant.

...

Optional legacy arguments.

Details

Returns the quadratic form of \beta^{T}\Lambda\beta evaluated at the tuned or fixed penalties, scaled by negative one-half inverse dispersion.

Assuming fixed penalties, the prior on \beta is taken to be

\beta | \sigma^2 \sim \mathcal{N}(\textbf{0}, \sigma^2\Lambda^{-1})

so that, up to a normalizing constant C with respect to \beta,

\implies \log P(\beta|\sigma^2) = C-\frac{1}{2\sigma^2}\beta^{T}\Lambda\beta

The value of C is included when include_constant = TRUE, and omitted when FALSE.

This is useful for computing joint penalized log-likelihoods and related MAP-style diagnostics for a fitted lgspline object.

Value

A numeric scalar representing the prior log-likelihood.

See Also

lgspline

Examples



## Data
t <- sort(runif(100, -5, 5))
y <- sin(t) - 0.1*t^2 + rnorm(100)

## Model keeping penalties fixed
model_fit <- lgspline(t, y, opt = FALSE)

## Full joint log-likelihood, conditional upon known sigma^2 = 1
jntloglik <- sum(dnorm(model_fit$y,
                    model_fit$ytilde,
                    1,
                    log = TRUE)) +
          prior_loglik(model_fit, sigmasq_predict = 1)
print(jntloglik)



lgspline documentation built on Aug. 5, 2026, 1:10 a.m.