| logLik.lgspline | R Documentation |
Returns the log-likelihood as a "logLik" object for use with
AIC, BIC, and other model
comparison tools.
## S3 method for class 'lgspline'
logLik(
object,
include_prior = TRUE,
new_weights = NULL,
B_predict = NULL,
sigmasq_predict = NULL,
...
)
object |
A fitted lgspline model object. |
include_prior |
Logical; add the log-prior penalty term. Default TRUE. |
new_weights |
Numeric scalar or N-vector; optional observation weights
overriding |
B_predict |
List; optional coefficient list at which to evaluate the
likelihood. Default NULL uses |
sigmasq_predict |
Numeric scalar; optional dispersion at which to
evaluate the likelihood. Default NULL uses |
... |
Not used. |
Gaussian identity, no correlation.
\ell = -\frac{N}{2}\log(2\pi\tilde{\sigma}^2) -
\frac{1}{2\tilde{\sigma}^2}\sum_{i}w_i(y_i - \hat{y}_i)^2
+ \frac{1}{2}\sum_i\log w_i
Gaussian identity, with correlation. GLS log-likelihood:
\ell = -\frac{N}{2}\log(2\pi\tilde{\sigma}^2)
+ \log|\mathbf{V}^{-1/2}|
- \frac{1}{2\tilde{\sigma}^2}
\sum_i w_i[\mathbf{V}^{-1/2}(\mathbf{y} -
\hat{\mathbf{y}})]_i^2
+ \frac{1}{2}\sum_i\log w_i
\log|\mathbf{V}^{-1/2}| is obtained from VhalfInv_logdet
when available, or computed directly from VhalfInv.
Prior contribution.
When include_prior = TRUE (default), the log-prior
-\frac{1}{2\tilde{\sigma}^2}
\sum_{k}\boldsymbol{\beta}_k^\top\boldsymbol{\Lambda}_k
\boldsymbol{\beta}_k
is added, giving the penalised MAP log-likelihood coherent with the
smoothing spline objective. Set include_prior = FALSE for the
unpenalised marginal likelihood, which is more appropriate when comparing
models with different penalty structures or numbers of knots.
Other GLM families.
Uses family$aic() when available. For correlated non-Gaussian models,
the family contribution is evaluated on the raw response scale and the
correlation log-determinant correction is added when available. When
family$aic() is unavailable, a deviance-based approximation is used
(valid for relative comparisons; a warning is emitted).
This function returns the marginal (full) GLS log-likelihood, not the
REML log-likelihood. This is consistent with REML = FALSE in
lme and gls, and is the conventional choice for AIC/BIC
comparisons of fixed-effects structure.
The df attribute is set to N - \mathrm{trace}(\mathbf{XUGX}^\top).
A "logLik" object with attributes df (effective
degrees of freedom) and nobs (number of observations).
lgspline, prior_loglik,
logLik, AIC,
BIC
set.seed(1234)
t <- runif(1000, -10, 10)
y <- 2*sin(t) + -0.06*t^2 + rnorm(length(t))
model_fit <- lgspline(t, y)
logLik(model_fit)
logLik(model_fit, include_prior = FALSE)
logLik(model_fit, B_predict = model_fit$B,
sigmasq_predict = model_fit$sigmasq_tilde)
AIC(model_fit)
BIC(model_fit)
## Compare models with different K using unpenalized likelihood
fit_k3 <- lgspline(t, y, K = 3)
fit_k7 <- lgspline(t, y, K = 7)
AIC(fit_k3, fit_k7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.