Title: | Additive Model for Ordinal Data using Laplace P-Splines |
---|---|
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: <arXiv:2210.01668>). |
Authors: | Philippe Lambert [aut, cre] |
Maintainer: | Philippe Lambert <[email protected]> |
License: | GPL-3 |
Version: | 0.9.1 |
Built: | 2024-11-08 03:42:07 UTC |
Source: | https://github.com/plambertuliege/ordgam |
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.
centeredBasis.gen(x, knots, cm = NULL, pen.order = 2, verbose = TRUE)
centeredBasis.gen(x, knots, cm = NULL, pen.order = 2, verbose = TRUE)
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) |
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.
Philippe Lambert [email protected]
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>.
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)
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)
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.
data(freehmsData)
data(freehmsData)
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.
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.
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.
data(freehmsDataBE)
data(freehmsDataBE)
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).
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
lmarg.gammaTilde(gamtk, k, model)
lmarg.gammaTilde(gamtk, k, model)
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 |
Log of p(gamma.tilde[k] | lambda,data)
Philippe Lambert [email protected]
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>.
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)
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
lpost.gamma(model)
lpost.gamma(model)
model |
Log joint posterior density function for the non-penalized regression parameters.
Philippe Lambert [email protected]
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>.
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)
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
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 )
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 )
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) |
an object of type ordgam.object
.
Philippe Lambert [email protected]
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>.
library(ordgam) data(freehmsData) mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age), data=freehmsData, descending=TRUE) print(mod) plot(mod)
library(ordgam) data(freehmsData) mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age), data=freehmsData, descending=TRUE) print(mod) plot(mod)
Compute the additive terms estimated using an 'ordgam' model
ordgam_additive(obj.ordgam, ngrid = 300, ci.level = 0.95)
ordgam_additive(obj.ordgam, ngrid = 300, ci.level = 0.95)
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 |
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 region
f
:
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
Philippe Lambert [email protected]
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>.
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)"))
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)"))
An object returned by the ordgam
function: this is a list
with various components related to the fit of such a model.
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 at theta
.
Hessian
:
Hessian of the log-posterior at theta
.
iter
:
Number of iterations of the N-R algorithm.
llik
:
Multinomial log likelihood.
Hessian0
:
Hessian of the (non-penalized) log-likelihood at theta
.
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 for theta
.
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 function DesignFormula
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) parameters theta
and vector of penalty parameters lambda
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 if lambda
should be selected by maximizing the marginal likelihood or its marginal posterior.
lambda.family
:
Chosen prior for lambda
: possible choices are "none", "dgamma" (i.e. dgamma(1,1e-4)), "BetaPrime" (BetaPrime(.5,.5)) or "myprior" (with log of the prior density function in myprior
). When "none" is selected, the marginal likelihood is directly maximized.
lprior.lambda
:
Log of the prior density for the penalty parameters lambda
when select.lambda
is TRUE.
loglambda.loss
:
The function of log(lambda)
that is minimized to select lambda
. It is minus the log marginal likelihood (when lambda.family
is "none") or minus the log of the marginal posterior for lambda
otherwise.
nu.lpost
:
Function giving the log of the marginal posterior density of nu=log(lambda)
.
nu.hat
:
The mode of the marginal posterior density nu.lpost
for nu=log(lambda)
.
V.nu
:
Variance of the marginal posterior for nu=log(lambda)
.
se.nu
:
Standard error of nu=log(lambda)
, i.e. the square-root of the diagonal elements of V.nu
.
nu.dp
:
List containing the parameters of the skew-t approximation to the marginal posterior of nu[j]=loglambda[j]
associated to each of the J
additive terms.
formula
:
Formula used during the model specification.
elapsed.time
:
Elapsed time.
Philippe Lambert [email protected]
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>.
ordgam
, print.ordregr
, plot.ordgam
Fit a proportional odds model for ordinal data
ordregr( y, nc = NULL, Xcal = Xcal, descending = FALSE, prior = list(mean = NULL, Prec = NULL), theta0 = NULL, ci.level = 0.95 )
ordregr( y, nc = NULL, Xcal = Xcal, descending = FALSE, prior = list(mean = NULL, Prec = NULL), theta0 = NULL, ci.level = 0.95 )
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. |
An object of class ordregr.object.
Philippe Lambert [email protected]
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>.
library(ordgam) data(freehmsData) Xcal = with(freehmsData, cbind(gndr,eduyrs,age)) mod = ordregr(y=freehmsData$freehms, Xcal=Xcal, descending=TRUE) print(mod)
library(ordgam) data(freehmsData) Xcal = with(freehmsData, cbind(gndr,eduyrs,age)) mod = ordregr(y=freehmsData$freehms, Xcal=Xcal, descending=TRUE) print(mod)
Log-posterior function for a proportional odds model
ordregr_lpost( y, nc, Xcal, theta, descending = FALSE, prior = list(mean = NULL, Prec = NULL), gradient = TRUE, Hessian = TRUE )
ordregr_lpost( y, nc, Xcal, theta, descending = FALSE, prior = list(mean = NULL, Prec = NULL), gradient = TRUE, Hessian = TRUE )
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. |
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).
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>.
An object returned by the ordregr
function: this is a list
with various components related to the fit of such a model.
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 at theta
.
Hessian
:
Hessian of the log-posterior at theta
.
iter
:
Number of iterations of the N-R algorithm.
Hessian0
:
Hessian of the (non-penalized) log-likelihood at theta
.
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 for theta
.
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').
Philippe Lambert [email protected]
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>.
Compute the penalty matrix associated to a vector containing fixed (non-penalized) parameters and equal-size sub-vectors of penalized spline parameters
Pcal.fun(nfixed, lambda, Pd.x)
Pcal.fun(nfixed, lambda, Pd.x)
nfixed |
the number of fixed (i.e. non-penalized) parameters |
lambda |
a vector of |
Pd.x |
a penalty matrix of size |
A block diagonal penalty matrix of size (nfixed+JK)
given by Blockdiag(diag(0,nfixed
), diag(lambda
).kron.Pd.x
)
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>.
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)
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)
Plot the the additive terms in an object generated by ordgam
with its credible regions
## S3 method for class 'ordgam' plot(x,ngrid=300,ci.level=.95,mfrow=NULL,...)
## S3 method for class 'ordgam' plot(x,ngrid=300,ci.level=.95,mfrow=NULL,...)
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. |
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.
Philippe Lambert [email protected]
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>.
ordgam
, ordgam.object
, ordgam.additive
, print.ordregr
.
library(ordgam) data(freehmsData) mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age), data=freehmsData, descending=TRUE) print(mod) plot(mod)
library(ordgam) data(freehmsData) mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age), data=freehmsData, descending=TRUE) print(mod) plot(mod)
Print a summary of the information contained in an ordregr.object
or ordgam.object
generated by ordregr
or ordgam
.
## S3 method for class 'ordregr' print(x, expEst, ...)
## S3 method for class 'ordregr' print(x, expEst, ...)
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. |
Print summary statistics.
Philippe Lambert [email protected]
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>.
library(ordgam) data(freehmsData) mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age), data=freehmsData, descending=TRUE) print(mod) plot(mod)
library(ordgam) data(freehmsData) mod = ordgam(freehms ~ gndr + s(eduyrs) + s(age), data=freehmsData, descending=TRUE) print(mod) plot(mod)
Skew-Normal approximation to a density evaluated on a sparse grid
SNapprox(x, lfx)
SNapprox(x, lfx)
x |
Vector containing a grid of values on the density support and covering the posterior mode. |
lfx |
Log density values on the grid |
A list containing
dp
:
Parameters of the approximating skew-Normal density.
fitted.moments
:
Mean, variance, skewness, kurtosis of the approximating skew-Normal.
Philippe Lambert [email protected]
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>.
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)
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
STapprox(x, lfx)
STapprox(x, lfx)
x |
Vector containing a grid of values on the density support and covering the posterior mode. |
lfx |
Log density values on the grid |
A list containing
dp
:
Parameters of the approximating skew-t density.
fitted.moments
:
Mean, variance, skewness, kurtosis of the approximating skew-t.
Philippe Lambert [email protected]
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>.
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")
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")