Type: | Package |
Title: | Additive Model for Ordinal Data using Laplace P-Splines |
Version: | 0.9.1 |
Maintainer: | Philippe Lambert <p.lambert@uliege.be> |
BugReports: | https://github.com/plambertULiege/ordgam/issues |
Description: | Additive proportional odds model for ordinal data using Laplace P-splines. The combination of Laplace approximations and P-splines enable fast and flexible inference in a Bayesian framework. Specific approximations are proposed to account for the asymmetry in the marginal posterior distributions of non-penalized parameters. For more details, see Lambert and Gressani (2023) <doi:10.1177/1471082X231181173> ; Preprint: <doi:10.48550/arXiv.2210.01668>). |
License: | GPL-3 |
URL: | <https://github.com/plambertULiege/ordgam> |
Encoding: | UTF-8 |
LazyData: | true |
Imports: | cubicBsplines, Matrix, mgcv, marqLevAlg, sn, MASS, numDeriv, ucminf |
RoxygenNote: | 7.2.1 |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2023-09-13 11:26:17 UTC; plambert |
Author: | Philippe Lambert |
Depends: | R (≥ 3.5.0) |
Repository: | CRAN |
Date/Publication: | 2023-09-14 09:20:02 UTC |
Internal function extracting design matrices from formulas in the DALSM function and computing penalty related matrices.
Description
Internal function extracting design matrices from formulas in the DALSM function and computing penalty related matrices.
Usage
DesignFormula(
formula,
data,
K = 10,
pen.order = 2,
knots.x = NULL,
n = NULL,
nointercept = FALSE,
verbose = TRUE
)
Compute the penalty matrix associated to a vector containing fixed (non-penalized) parameters and equal-size sub-vectors of penalized spline parameters
Description
Compute the penalty matrix associated to a vector containing fixed (non-penalized) parameters and equal-size sub-vectors of penalized spline parameters
Usage
Pcal.fun(nfixed, lambda, Pd.x)
Arguments
nfixed |
the number of fixed (i.e. non-penalized) parameters |
lambda |
a vector of |
Pd.x |
a penalty matrix of size |
Value
A block diagonal penalty matrix of size (nfixed+JK)
given by Blockdiag(diag(0,nfixed
), diag(lambda
).kron.Pd.x
)
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
Examples
Dd = diff(diag(1,5),diff=2) ## Difference penalty matrix for a vector of length 5
Pd = t(Dd) %*% Dd ## Penalty matrix of order 2
nfixed = 2 ## 2 unpenalized parameters
## Global penalty matrix when 2 unpenalized parameters and 2 additive terms with
## 2 vectors of 5 P-splines coefficients with lambda values 10 and 100 respectively.
Pcal.fun(nfixed=2,lambda=c(10,100),Pd)
Skew-Normal approximation to a density evaluated on a sparse grid
Description
Skew-Normal approximation to a density evaluated on a sparse grid
Usage
SNapprox(x, lfx)
Arguments
x |
Vector containing a grid of values on the density support and covering the posterior mode. |
lfx |
Log density values on the grid |
Value
A list containing
dp
:
Parameters of the approximating skew-Normal density.fitted.moments
:
Mean, variance, skewness, kurtosis of the approximating skew-Normal.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
## Density to be approximated by a Skew-Normal
dtarget = function(x) dgamma(x,10,2)
curve(dtarget(x),0,15,lwd=2,ylab="Density")
## Values of the target density on a sparse grid
ngrid = 6 ## Sparse grid size
xgrid = seq(2,8,length=ngrid) ## Grid
lfx = log(dtarget(xgrid)) ## Log values
## Skew-Normal approximation
dp = ordgam::SNapprox(xgrid,lfx)$dp
curve(sn::dsn(x,dp=dp),add=TRUE,lwd=2,lty=2,col=2)
points(xgrid,exp(lfx))
legend("topright",legend=c("Target density","Skew-Normal approx."),
col=1:2,lty=1:2,lwd=2,bty="n")#' library(ordgam)
Skew-t approximation to a density evaluated on a sparse grid
Description
Skew-t approximation to a density evaluated on a sparse grid
Usage
STapprox(x, lfx)
Arguments
x |
Vector containing a grid of values on the density support and covering the posterior mode. |
lfx |
Log density values on the grid |
Value
A list containing
dp
:
Parameters of the approximating skew-t density.fitted.moments
:
Mean, variance, skewness, kurtosis of the approximating skew-t.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
## Density to be approximated by a Skew-t
dtarget = function(x) dgamma(x,10,2)
curve(dtarget(x),0,15,lwd=2,ylab="Density")
## Values of the target density on a sparse grid
ngrid = 6 ## Sparse grid size
xgrid = seq(2,8,length=ngrid) ## Grid
lfx = log(dtarget(xgrid)) ## Log values
## Skew-t approximation
dp = ordgam::STapprox(xgrid,lfx)$dp
curve(sn::dst(x,dp=dp),add=TRUE,lwd=2,lty=2,col=2)
points(xgrid,exp(lfx))
legend("topright",legend=c("Target density","Skew-t approx."),
col=1:2,lty=1:2,lwd=2,bty="n")
Generation of a recentered B-spline basis matrix in additive models
Description
Generation of a B-spline basis matrix with recentered columns to handle the identifiability constraint in additive models. See Wood (CRC Press 2017, pp. 175-176) for more details.
Usage
centeredBasis.gen(x, knots, cm = NULL, pen.order = 2, verbose = TRUE)
Arguments
x |
vector of values where to compute the "recentered" B-spline basis |
knots |
vector of knots (that should cover the values in <x>) |
cm |
(Optional) values subtracted from each column of the original B-spline matrix |
pen.order |
penalty order for the B-spline parameters (Default: 2) |
verbose |
verbose indicator (Default: TRUE) |
Value
List containing
B
:
centered B-spline matrix (with columns recentered to have mean 0 over equi-spaced x values on the range of the knots).Dd
:
difference matrix (of order <pen.order>) for the associated centered B-spline matrix.Pd
:
penalty matrix (of order <pen.order>) for the associated centered B-spline matrix.K
:
number of centered B-splines in the basis.cm
:
values subtracted from each column of the original B-spline matrix. By default, this is a vector containing the mean of each column in the original B-spline matrix.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
Examples
x = seq(0,1,by=.01)
knots = seq(0,1,length=5)
obj = centeredBasis.gen(x,knots)
matplot(x,obj$B,type="l",ylab="Centered B-splines")
colMeans(obj$B)
Perception of gay men and lesbians in Wallonia, Belgium.
Description
Data extracted from the European Social Survey (2018) conducted in a series of European countries including Belgium and one of its three regions, Wallonia. Each of the 552 participants (aged at least 15) was asked to react to the following statement, "Gay men and lesbians should be free to live their own life as they wish", with a positioning on a Likert scale going from 1 (=Agree strongly) to 5 (=Disagree strongly), with 3 labelled as Neither agree nor disagree.
Usage
data(freehmsData)
Format
A data frame with 552 rows and 4 columns.
freehms
Ordinal response (1: Agree strongly to 5: Disagree strongly).
age
Age of the respondent.
gndr
Gender of the respondent.
eduyrs
Number of years of education completed.
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
European Social Survey Round 9 Data (2018) Data file edition 3.1. NSD - Norwegian Centre for Research Data, Norway.
Perception of gay men and lesbians in Belgium.
Description
Data extracted from the European Social Survey (2018) conducted in a series of European countries including Belgium. Each of the 1737 participants (aged at least 15) was asked to react to the following statement, "Gay men and lesbians should be free to live their own life as they wish", with a positioning on a Likert scale going from 1 (=Agree strongly) to 5 (=Disagree strongly), with 3 labelled as Neither agree nor disagree.
Usage
data(freehmsDataBE)
Format
A data frame with 1737 rows and 5 columns.
freehms
Ordinal response (1: Agree strongly to 5: Disagree strongly).
gndr
Gender of the respondent.
age
Age of the respondent.
eduyrs
Number of years of education completed.
region
Belgian region of residence: WAL (Wallonia), FL (Flanders) or BXL (Brussels).
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
European Social Survey Round 9 Data (2018) Data file edition 3.1. NSD - Norwegian Centre for Research Data, Norway.
Marginal posterior density function for a remapped non-penalized parameter in an ordgam model
Description
Marginal posterior density function for a remapped non-penalized parameter in an ordgam model
Usage
lmarg.gammaTilde(gamtk, k, model)
Arguments
gamtk |
Remapped parameter value at which the marginal log posterior density for <gamma.tilde[k]> must be evaluated. |
k |
Targetted component in the vector of remapped non-penalized parameters <gamma.tilde>. |
model |
An |
Value
Log of p(gamma.tilde[k] | lambda,data)
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
data(freehmsData)
mod = ordgam(freehms ~ s(eduyrs) + s(age), data=freehmsData, descending=TRUE,
lambda0=c(192,18),select.lambda=FALSE)
ngamma = with(mod, nalpha+nfixed) ## Number of non-penalized parms
k = 1 ## Focus on gamma.tilde[1]
x.grid = seq(-4,4,length=7) ## Grid of values for gamma.tilde[k]
lfy.grid = ordgam::lmarg.gammaTilde(x.grid,k=k,mod) ## log p(gamma.tilde[k] | D) on the grid
gamt.ST = ordgam::STapprox(x.grid,lfy.grid)$dp ## Approximate using a skew-t
## Plot the estimated marginal posterior for <gamma.tilde[k]>
xlab = bquote(tilde(gamma)[.(k)])
ylab = bquote(p(tilde(gamma)[.(k)]~ "|"~lambda~","~D))
xlim = sn::qst(c(.0001,.9999),dp=gamt.ST)
curve(sn::dst(x,dp=gamt.ST),xlim=xlim,
xlab=xlab,ylab=ylab,col="blue",lwd=2,lty=1)
Posterior density function for the non-penalized parameters in an ordgam model
Description
Posterior density function for the non-penalized parameters in an ordgam model
Usage
lpost.gamma(model)
Arguments
model |
Value
Log joint posterior density function for the non-penalized regression parameters.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
data(freehmsData)
mod = ordgam(freehms ~ s(eduyrs) + s(age), data=freehmsData, descending=TRUE)
print(mod$theta) ## Model regression parameters
gam.hat = mod$theta[1:4] ## Non-penalized parameter estimates
ordgam::lpost.gamma(mod)(gam.hat)
Fit of an additive proportional odds model for ordinal data using Laplace approximations and P-splines
Description
Fit of an additive proportional odds model for ordinal data using Laplace approximations and P-splines
Usage
ordgam(
formula,
data,
nc = NULL,
K = 10,
pen.order = 2,
descending = TRUE,
select.lambda = TRUE,
lambda.family = "dgamma",
lambda.optimizer = "nlminb",
lprior.lambda = function(x) dgamma(x, 1, 1e-04, log = TRUE),
theta0 = NULL,
lambda0 = NULL,
ci.level = 0.95,
verbose = FALSE
)
Arguments
formula |
A model formula |
data |
A data frame containing a column 'y' with the ordinal response (taking integer values) besides the covariates. |
nc |
(optional) Number of categories for the ordinal response. |
K |
Number of B-splines to model each additive term (Default: 10). |
pen.order |
Penalty order (Default: 2). |
descending |
Logical indicating if the odds of the response taking a value in the upper scale should be preferred over values in the lower scale (Default: TRUE). |
select.lambda |
Logical indicating if the penalty parameters should be tuned (Default: TRUE). |
lambda.family |
Prior for <lambda>. Possible choices are "none", "dgamma", "BetaPrime" or "myprior" for a user specified function for the prior of <lambda>. |
lambda.optimizer |
Algorithm used to maximize p(lambda|data). Possible choices are "nlminb","ucminf","nlm","LevMarq" (Default: "nlminb"). |
lprior.lambda |
Log of the prior density for a <lambda> component if |
theta0 |
(Optional) Vector containing starting values for the regression parameters. |
lambda0 |
Vector of penalty parameters for the additive terms (Default: 10 for each additive term). |
ci.level |
Confidence levels of the computed credible intervals for the regression parameters. |
verbose |
Verbose mode (logical) |
Value
an object of type ordgam.object
.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
data(freehmsData)
mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age),
data=freehmsData, descending=TRUE)
print(mod)
plot(mod)
Object resulting from the fit of an additive proportional odds model using 'ordgam'
Description
An object returned by the ordgam
function: this is a list
with various components related to the fit of such a model.
Value
An ordgam
object is a list with following elements:
val
:
Value of the log-posterior at convergence.val.start
:
Value of the log-posterior at the start of the Newton-Raphson (N-R) algorithm.theta
:
(Penalized) MLE or MAP of the regression coefficients.grad
:
Gradient of the log-posterior attheta
.Hessian
:
Hessian of the log-posterior attheta
.iter
:
Number of iterations of the N-R algorithm.llik
:
Multinomial log likelihood.Hessian0
:
Hessian of the (non-penalized) log-likelihood attheta
.Sigma.theta
:
Variance-covariance of 'theta'.ED.full
:
Effective degrees of freedom associated to each regression parameter, penalized parameters included.se.theta
:
Standard errors of the regression coefficents.theta.mat
:
Matrix containing the point estimate, standard error, credible interval, Z-score and P-value fortheta
.nc
:
Number of categories for the ordinal response.nalpha
:
Number of intercepts in the proportional odds model (=nc
-1) .nbeta
:
Number of regression parameters (intercepts excluded).nfixed
:
Number of non-penalized regression parameters.ci.level
:
Nominal coverage of the credible intervals (Default: .95).n
:
Sample size.call
:
Function call.descending
:
Logical indicating if the odds of the response taking a value in the upper scale should be preferred over values in the lower scale.use.prior
:
Logical indicating if a prior (such as a penalty) is assumed for the regression parameters.lpost
:
Value of the log-posterior at convergence.levidence
:
Log of the marginal likelihood (also named 'evidence').AIC
:
Aikake information criterion: AIC = -2 logLik + 2 x edf where edf stands for the effective degrees of freedom.BIC
:
Schwarz information criterion: BIC = -2 logLik + n x log(edf) where edf stands for the effective degrees of freedom.y
:
Vector containing the values of the ordinal response.regr
:
List created by the internal functionDesignFormula
and containing diverse objects associated to the model specification, including the part of the design matrix 'X' associated to regressors and its extended version 'Xcal' with B-spline bases for additive term.ED.Chi2
:
Matrix containing the Effective Degrees of Freedom associated to the additive terms with their respective significance Chi2 test and P-value.ED.Tr
:
Matrix containing the Effective Degrees of Freedom associated to the additive terrms with their respective significance <Tr> test (described by S. Wood, Biometrika 2013) and P-value.lpost.fun
:
Function with arguments (theta,lambda,gradient=TRUE,Hessian=TRUE) computing the log-posterior for given regression (and possibly spline) parameterstheta
and vector of penalty parameterslambda
associated to the additive terms. Gradient and Hessian are also computed if requested.lambda0
:
Initial values for the vector of penalty parameters. Its length corresponds to the number of additive terms.lambda
:
(Selected) vector of penalty parameters. Its length corresponds to the number of additive terms.select.lambda
:
Logical indicating iflambda
should be selected by maximizing the marginal likelihood or its marginal posterior.lambda.family
:
Chosen prior forlambda
: possible choices are "none", "dgamma" (i.e. dgamma(1,1e-4)), "BetaPrime" (BetaPrime(.5,.5)) or "myprior" (with log of the prior density function inmyprior
). When "none" is selected, the marginal likelihood is directly maximized.lprior.lambda
:
Log of the prior density for the penalty parameterslambda
whenselect.lambda
is TRUE.loglambda.loss
:
The function oflog(lambda)
that is minimized to selectlambda
. It is minus the log marginal likelihood (whenlambda.family
is "none") or minus the log of the marginal posterior forlambda
otherwise.nu.lpost
:
Function giving the log of the marginal posterior density ofnu=log(lambda)
.nu.hat
:
The mode of the marginal posterior densitynu.lpost
fornu=log(lambda)
.V.nu
:
Variance of the marginal posterior fornu=log(lambda)
.se.nu
:
Standard error ofnu=log(lambda)
, i.e. the square-root of the diagonal elements ofV.nu
.nu.dp
:
List containing the parameters of the skew-t approximation to the marginal posterior ofnu[j]=loglambda[j]
associated to each of theJ
additive terms.formula
:
Formula used during the model specification.elapsed.time
:
Elapsed time.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
ordgam
, print.ordregr
, plot.ordgam
Compute the additive terms estimated using an 'ordgam' model
Description
Compute the additive terms estimated using an 'ordgam' model
Usage
ordgam_additive(obj.ordgam, ngrid = 300, ci.level = 0.95)
Arguments
obj.ordgam |
An object of class 'ordgam'. |
ngrid |
Number of grid points where the additive terms are computed. |
ci.level |
Credibility level for the pointwise credible region for the additive terms |
Value
a list containing:
nalpha
:
number of intercepts in the proportional odds model.nfixed
:
number of non-penalized regression parameters in 'beta'.J
:
number of additive terms.additive.lab
:
labels of the additive terms.K
:
number of spline parameters to specify an additive term.knots
:
list of length J containing the knots for the B-spline basis associated to a given additive term.f.grid
:
list of length J with, for each additive term, a list of length 2 with 'x': a vector of grid values for the covariate ; 'y.mat': a matrix with 3 columns (est,low,up) giving the additive term and its pointwise credible regionf
:
a list of length J with, for each additive term <x>, a list with f$x: a function computing the additive term f(x) for a given covariate value 'x' ; attributes(f$x): support, label, range.f.se
:
a list of length J with, for each additive term <x>, a list with f.se$x: a function computing the s.e. of f(x) for a given covariate value 'x' ; attributes(f.se$x): support, label, range
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
Examples
library(ordgam)
data(freehmsData)
mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age),
data=freehmsData, descending=TRUE)
obj = ordgam_additive(mod)
names(obj)
with(obj$f.grid$age,
matplot(x, y.mat, lty=c(1,2,2),type="l",col=1,
xlab="Age", ylab="f(Age)"))
Fit a proportional odds model for ordinal data
Description
Fit a proportional odds model for ordinal data
Usage
ordregr(
y,
nc = NULL,
Xcal = Xcal,
descending = FALSE,
prior = list(mean = NULL, Prec = NULL),
theta0 = NULL,
ci.level = 0.95
)
Arguments
y |
Vector containing the ordinal response (coded using integers in 1:nc). |
nc |
(optional) Maximum value of |
Xcal |
Design matrix (excluding intercept columns). |
descending |
Logical indicating if the odds of the response taking a value in the upper scale should be preferred over values in the lower scale. |
prior |
(optional) List giving the 'mean' and 'Prec'(ision) of the regression parameters. |
theta0 |
(Optional) Vector containing starting values for the regression parameters. |
ci.level |
Confidence levels of the computed credible intervals for the regression parameters. |
Value
An object of class ordregr.object.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
data(freehmsData)
Xcal = with(freehmsData, cbind(gndr,eduyrs,age))
mod = ordregr(y=freehmsData$freehms, Xcal=Xcal, descending=TRUE)
print(mod)
Object resulting from the fit of a proportional odds model using 'ordregr'
Description
An object returned by the ordregr
function: this is a list
with various components related to the fit of such a model.
Value
A ordregr
object is a list with following elements:
val
:
Value of the log-posterior at convergence.val.start
:
Value of the log-posterior at the start of the Newton-Raphson (N-R) algorithm.theta
:
(Penalized) MLE or MAP of the regression coefficients.grad
:
Gradient of the log-posterior attheta
.Hessian
:
Hessian of the log-posterior attheta
.iter
:
Number of iterations of the N-R algorithm.Hessian0
:
Hessian of the (non-penalized) log-likelihood attheta
.Sigma.theta
:
Variance-covariance of 'theta'.ED.full
:
Effective degrees of freedom associated to each regression parameter, penalized parameters included.se.theta
:
Standard errors of the regression coefficents.theta.mat
:
Matrix containing the point estimate, standard error, credible interval, Z-score and P-value fortheta
.nc
:
Number of categories for the ordinal response.nalpha
:
Number of intercepts in the proportional odds model (=nc
-1) .nbeta
:
Number of regression parameters (intercepts excluded).nfixed
:
Number of non-penalized regression parameters.ci.level
:
Nominal coverage of the credible intervals (Default: .95).n
:
Sample size.call
:
Function call.descending
:
Logical indicating if the odds of the response taking a value in the upper scale should be preferred over values in the lower scale.use.prior
:
Logical indicating if a prior (such as a penalty) is assumed for the regression parameters.lpost
:
Value of the log-posterior at convergence.levidence
:
Log of the marginal likelihood (also named 'evidence').
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Log-posterior function for a proportional odds model
Description
Log-posterior function for a proportional odds model
Usage
ordregr_lpost(
y,
nc,
Xcal,
theta,
descending = FALSE,
prior = list(mean = NULL, Prec = NULL),
gradient = TRUE,
Hessian = TRUE
)
Arguments
y |
Vector containing the ordinal response (coded using integers in 1:nc). |
nc |
(optional) Maximum value of |
Xcal |
Design matrix. |
theta |
Vector c(alpha,beta) with intercepts <alpha> and regression parameters <beta>. |
descending |
Logical indicating if the odds of the response taking a value in the upper scale should be preferred over values in the lower scale. |
prior |
(optional) List given the mean and Prec(ision) of the regression parameters. |
gradient |
Logical indicating if the gradient of the log-posterior should be computed. |
Hessian |
Logical indicating if the Hessian of the log-posterior should be computed. |
Value
The log-posterior with the following attributes:
Salpha
:
gradient wrt intercepts 'alpha'.Sbeta
:
gradient wrt regression parameters 'beta'.grad
:
gradient wrt c(alpha,beta).Halpha
:
Hessian wrt intercepts 'alpha'.Hbeta
:
Hessian wrt regression parameters 'beta'.Hba
:
cross-derivatives (Hessian) submatrix wrt 'alpha' & 'beta'.Hessian
:
Hessian wrt c(alpha,beta).dtheta
:
step in a Newton-Raphson iteration: solve(-Hessian,grad).
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
Plot the the additive terms in an <ordgam> object with its credible regions
Description
Plot the the additive terms in an object generated by ordgam
with its credible regions
Usage
## S3 method for class 'ordgam'
plot(x,ngrid=300,ci.level=.95,mfrow=NULL,...)
Arguments
x |
An ordgam.object generated by ordgam. |
ngrid |
An integer indicating the number of gridpoints where the additive terms should be evaluated. |
ci.level |
Credibility level for the pointwise credible region of the additive terms. |
mfrow |
(Optional) A vector of the form c(nr, nc). Subsequent figures will be drawn in an nr-by-nc array on the device by rows. |
... |
Additional generic plotting arguments. |
Value
In addition to the plots, an invisible object containing information on the estimated additive terms is returned, see the ordgam_additive
function documentation for more details.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
ordgam
, ordgam.object
, ordgam.additive
, print.ordregr
.
Examples
library(ordgam)
data(freehmsData)
mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age),
data=freehmsData, descending=TRUE)
print(mod)
plot(mod)
Print an 'ordregr' or an 'ordgam' object.
Description
Print a summary of the information contained in an ordregr.object
or ordgam.object
generated by ordregr
or ordgam
.
Usage
## S3 method for class 'ordregr'
print(x, expEst, ...)
Arguments
x |
An ordregr.object generated by ordregr or ordgam. |
expEst |
Logical indicating if the exponential of the regression coefficients should be printed (Default: TRUE) |
... |
Possible additional printing options. |
Value
Print summary statistics.
Author(s)
Philippe Lambert p.lambert@uliege.be
References
Lambert, P. and Gressani, 0. (2023) Penalty parameter selection and asymmetry corrections to Laplace approximations in Bayesian P-splines models. Statistical Modelling. <doi:10.1177/1471082X231181173>. Preprint: <arXiv:2210.01668>.
See Also
Examples
library(ordgam)
data(freehmsData)
mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age),
data=freehmsData, descending=TRUE)
print(mod)
plot(mod)
Specification of smooth terms in formulas in the ordgam function.
Description
Specification of smooth terms in formulas in the ordgam function.
Usage
s(x)
Arguments
x |
Name of the variable for which an additive term is requested |
Value
The submitted variable for which an additive term is required
Significance test of an additive term
Description
Significance test of an additive term relying on the methodology in Wood (Biometrika 2013). It is extracted from a hidden function in the 'mgcv' package. The additive term is estimated using the product of a matrix <X> and a vector <p>.
Usage
testStat(p, X, V, rank = NULL, type = 0, res.df = -1)
Arguments
p |
Vector of spline parameters used to estimate f(x) |
X |
(Centered) B-spline basis evaluated on a fine regular grid on the support of variable <x> |
V |
Posterior variance-covariance matrix of parameter <p> |
rank |
Effective dimension of <p> |
type |
0 value by default |
res.df |
-1 indicates that the scale is fixed (cf. ordinal response) |
Value
Returns a list with following elements:
stat :
Value of the test statisticspval :
P-value of the test for the null hypothesis Ho: p=0rank :
Effective dimension of <p>