Type: Package
Title: Nonparametric Double Additive Location-Scale Model (DALSM)
Version: 0.9.1
Maintainer: Philippe Lambert <p.lambert@uliege.be>
BugReports: https://github.com/plambertULiege/DALSM/issues
Description: Fit of a double additive location-scale model with a nonparametric error distribution from possibly right- or interval censored data. The additive terms in the location and dispersion submodels, as well as the unknown error distribution in the location-scale model, are estimated using Laplace P-splines. For more details, see Lambert (2021) <doi:10.1016/j.csda.2021.107250>.
License: GPL-3
URL: <https://github.com/plambertULiege/DALSM>
Encoding: UTF-8
LazyData: true
Imports: cubicBsplines, MASS, plyr
RoxygenNote: 7.2.3
NeedsCompilation: no
Packaged: 2023-10-02 13:33:39 UTC; plambert
Author: Philippe Lambert ORCID iD [aut, cre]
Depends: R (≥ 3.5.0)
Repository: CRAN
Date/Publication: 2023-10-02 16:50:02 UTC

Fit a double additive location-scale model (DALSM) with a flexible error distribution

Description

Fit a location-scale regression model with a flexible error distribution and additive terms in location (=mean) and dispersion (= log(sd)) using Laplace P-splines from potentially right- and interval-censored response data.

Usage

DALSM(y, formula1,formula2, data,
       K1=10, K2=10, pen.order1=2, pen.order2=2,
       b.tau=1e-4, lambda1.min=1, lambda2.min=1,
       phi.0=NULL,psi1.0=NULL,psi2.0=NULL,lambda1.0=NULL,lambda2.0=NULL,
       REML=FALSE, diag.only=TRUE, Normality=FALSE, sandwich=TRUE,
       K.error=20, rmin=NULL,rmax=NULL,
       ci.level=.95, iterlim=50,verbose=FALSE)

Arguments

y

n-vector of responses or (nx2)-matrix/data.frame when interval-censoring (with the 2 elements giving the interval bounds) or right-censoring (when the element in the 2nd column equals Inf).

formula1

model formula for location (i.e. for the conditional mean).

formula2

model formula for dispersion (i.e. for the log of the conditional standard deviation).

data

data frame containing the model covariates.

K1

(optional) number of B-splines to describe a given additive term in the location submodel (default: 10).

K2

(optional) number of B-splines to describe a given additive term in the dispersion submodel (default: 10).

pen.order1

(optional) penalty order for the additive terms in the location submodel (default: 2).

pen.order2

(optional) penalty order for the additive terms in the dispersion submodel (default: 2).

b.tau

(optional) prior on penalty parameter \tau is Gamma(1,b.tau=1e-4) (for additive terms) (default: 1e-4).

lambda1.min

(optional) minimal value for the penalty parameters in the additive model for location (default: 1.0).

lambda2.min

(optional) minimal value for penalty parameters in the additive model for log-dispersion (default: 1.0).

phi.0

(optional) initial values for the spline parameters in the log-hazard of the standardized error distribution.

psi1.0

(optional) initial values for the location submodel parameters.

psi2.0

(optional) initial values for the dispersion submodel parameters.

lambda1.0

(optional) initial value for the J1 penalty parameters of the additive terms in the location submodel.

lambda2.0

(optional) initial value for the J2 penalty parameters of the additive terms in the dispersion submodel.

REML

(optional) logical indicating if a REML correction is desired to estimate the dispersion parameters (default: FALSE).

diag.only

(optional) logical indicating if only the diagonal of the Hessian needs to be corrected during REML (default: TRUE).

Normality

(optional) logical indicating if Normality is assumed for the error term (default: FALSE).

sandwich

(optional) logical indicating if sandwich variance estimators are needed for the regression parameters for a NP error distribution (when Normality=FALSE) ; it is forced to be TRUE when Normality=TRUE.

K.error

(optional) number of B-splines to approximate the log of the error hazard on (rmin,rmax) (default: 20).

rmin

(optional) minimum value for the support of the standardized error distribution (default: min(y)-sd(y)).

rmax

(optional) maximum value for the support of the standardized error distribution (default: max(y)+sd(y)).

ci.level

(optional) nominal level for the reported credible intervals (default: .95).

iterlim

(optional) maximum number of iterations (after which the algorithm is interrupted with a non-convergence diagnostic) (default: 50).

verbose

(optional) logical indicating whether estimation step details should be displayed (default: FALSE).

Value

An object of class DASLM containing several components from the fit, see DALSM.object for details. A summary can be printed using print.DALSM or plotted using plot.DALSM.

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

DALSM.object, print.DALSM, plot.DALSM.

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
print(fit)
plot(fit)


Object resulting from the fit of a double additive location-scale model (DALSM).

Description

An object returned by the DALSM function: this is a list with various components related to the fit of a double additive location-scale model using Laplace P-splines.

Value

A DALSM object has the following elements:

Essential part:

Additional elements:

If there are additive terms in the location submodel:

If there are additive terms in the dispersion submodel:

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

DALSM, print.DALSM, plot.DALSM, densityLPS, densLPS.object


Income data

Description

Income (in euros) available per person in 756 Belgian households (ESS 2016 ; Lambert 2021, Section 4) for respondents aged 25-55 when the main source of income comes from wages or salaries. The data were extracted from the European Social Survey (2016) and reworked to quantify the resources available at the individual level in the selected Belgian households.

Usage

data(DALSM_IncomeData)

Format

A data frame with 756 rows and 5 columns:

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

European Social Survey Round 8 Data (2016) Data file edition 2.1. NSD - Norwegian Centre for Research Data, Norway.


Extraction of the estimated additive terms in a DALSM.object

Description

Extract the estimated additive terms with their standard errors from a DALSM.object resulting from the fit of a DALSM model. In addition to the estimated functions in the location and dispersion submodels, their values on a regular grid covering the observed covariate values are reported together with credible intervals. The mean effective coverage of these pointwise credible intervals for the additive terms with respect to given (optional) reference functions (such as the ones for the 'true' additive terms used to generate data in a simulation study) can also be computed.

Usage

DALSM_additive(obj.DALSM, ngrid=101,
       true.loc=NULL, true.disp=NULL, ci.level=NULL,
       verbose=FALSE)

Arguments

obj.DALSM

a DALSM.object

ngrid

(optional) grid size of covariate values where the additive terms are calculated (default: 101).

true.loc

(optional) list of functions containing the 'true' additive terms in the location sub-model.

true.disp

(optional) list of functions containing the 'true' additive terms in the dispersion sub-model.

ci.level

(optional) level of credible intervals.

verbose

logical indicating whether the computed corverages should be printed out (default: TRUE).

Value

It returns an invisible list containing:

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

DALSM.object, DALSM, print.DALSM, plot.DALSM.

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
obj = DALSM_additive(fit)
str(obj)

## Visualize the estimated additive terms for Age
## ... in the location submodel
with(obj$f.loc.grid$age, matplot(x,y.mat,
                                 xlab="Age",ylab="f.loc(Age)",
                                 type="l",col=1,lty=c(1,2,2)))
## ... and in the dispersion submodel
with(obj$f.disp.grid$age, matplot(x,y.mat,
                                 xlab="Age",ylab="f.disp(Age)",
                                 type="l",col=1,lty=c(1,2,2)))
## Also report their values for selected age values
obj$f.loc$age(c(30,40,50)) ; obj$f.disp$age(c(30,40,50))
## ... together with their standard errors
obj$se.loc$age(c(30,40,50)) ; obj$se.disp$age(c(30,40,50))

Object creation for density estimation from right- or interval-censored data

Description

Object creation for density estimation from right- or interval-censored data using function densityLPS.

Usage

Dens1d(y, event=NULL, ymin=NULL, ymax=NULL,
       K=25, equid.knots=TRUE, pen.order=2, nbins=501)

Arguments

y

a n-vector (if no interval-censored data) or a nx2 matrix (left and right limits of the interval for IC data ; right limit set to Inf for right-censored data).

event

a n-vector of observation indicators (0: right-censored ; 1: exactly observed or interval-censored).

ymin

left limit of the variable support.

ymax

right limit of the variable support.

K

number of B-splines in the basis to approximate the log-hazard.

equid.knots

logical indicating if equidistants knots are desired.

pen.order

penalty order when equidistant knots (otherwise: penalty matrix computed to penalize the second derivative).

nbins

number of small bins used for quadrature and approximations.

Value

A Dens1d.object, i.e. a list with summary measures and precomputed components required for density estimation using densityLPS.

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

Dens1d.object, densityLPS.

Examples

library(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
head(resp,n=20)
temp = Dens1d(y=resp,ymin=0) ## Create Dens1d object from positive censored data
obj = densityLPS(temp) ## Density estimation from IC & RC data
plot(obj) ## Visualize the estimated density


Object created by Dens1d to prepare for density estimation from censored data using densityLPS

Description

An object returned by function Dens1d to prepare for density estimation with given mean and variance from censored data using function densityLPS.

Value

A Dens1d.object is a list with the following elements:

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

Dens1d, densityLPS, densLPS.object


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, n = NULL)

Arguments

formula

a formula describing the fixed effects and the additive terms in a regression model.

data

a dataframe containing the data.

K

number of B-splines to describe an additive term.

pen.order

desired penalty order for the spline parameters in the additive terms.

n

number of units (Default: number of rows in the design matrix constructed from the formula and the data frame).

Value

a list with

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>


Generation of the penalty matrix for an additive model based on P-splines

Description

Compute the penalty matrix associated to a vector containing fixed (non-penalized) parameters and equal-size sub-vectors of penalized B-spline parameters.

Usage

Pcal.fun(nfixed, lambda, Pd.x)

Arguments

nfixed

the number of fixed (i.e. non-penalized) parameters.

lambda

a vector of p penalty parameters where each component is associated to a sub-vector of spline parameters of length J.

Pd.x

a penalty matrix of size J associated to a given sub-vector of spline parameters.

Value

A block diagonal penalty matrix of size (nfixed+pJ) given by Blockdiag(diag(0,nfixed), diag(lambda).kron.Pd.x).

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

Examples

D = diff(diag(5),diff=2) ## Difference penalty matrix of order 2 for 5 P-spline parameters
P = t(D) %*% D ## Penalty matrix of order 2 for 5 B-spline parameters
lambda = c(100,10) ## Penalty parameters for 2 additive terms with 5 B-spline parameters each
Pcal.fun(3,lambda,P) ## Global penalty matrix for 3 additional non-penalized parameters

Generation of a recentered cubic B-spline basis matrix in additive models

Description

Generation of a cubic 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)

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).

Value

List containing

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

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)

Object generated by function densityLPS

Description

An object returned by function densityLPS: this is a list with various components related to the estimation of a density with given mean and variance from potentially right- or interval-censored data using Laplace P-splines.

Value

An object returned by densityLPS has the following elements: Essential part:

Additional elements: the content of the Dens1d.object used when densityLPS was called.

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

densityLPS, DALSM


Constrained density estimation from censored data with given mean and variance using Laplace P-splines

Description

P-spline estimation of the density (pdf), cumulative distribution (cdf), hazard and cumulative hazard functions from interval- or right-censored data under possible marginal mean and/or variance constraints. The penalty parameter \tau tuning the smoothness of the log-hazard can be selected using the Laplace P-splines (LPS) method maximizing an approximation to the marginal posterior of \tau (also named the 'evidence') or using Schall's method.

Usage

densityLPS(obj.data,
       is.density=TRUE, Mean0=NULL, Var0=NULL,
       fixed.penalty=FALSE, method=c("LPS","Schall"),
       fixed.phi=FALSE,phi.ref=NULL, phi0=NULL,tau0=exp(5),tau.min=.1,
       verbose=FALSE)

Arguments

obj.data

a list created from potentially right- or interval-censored data using Dens1d. It includes summary statistics, the assumed density support, the knots for the B-spline basis, etc.

is.density

(optional) logical indicating whether the estimated density should integrate to 1.0 over the range of the knots in obj.data$knots (default: TRUE).

Mean0

(optional) constrained value for the mean of the fitted density (defaut: NULL).

Var0

(optional) constrained value for the variance of the fitted density (defaut: NULL).

fixed.penalty

(optional) logical indicating whether the penalty parameter should be selected from the data (fixed.penalty=FALSE) or fixed (fixed.penalty=TRUE) at its initial value \tau_0.

method

method used for the selection of the penalty parameter: "LPS" (by maximizing the marginal posterior for \tau, cf. "Laplace P-splines") or "Schall" (Schall's method).

fixed.phi

(optional) logical indicating whether the spline parameters are fixed (fixed.phi=TRUE) or estimated from the data (default: fixed.phi=FALSE).

phi.ref

(optional) reference value for the spline parameters with respect to which deviations are penalized (default: zero vector).

phi0

starting value for the spline parameters (default: spline parameters corresponding to a Student density with 5 DF).

tau0

(optional) initial value for the penalty parameter \tau (default: exp(5)).

tau.min

(optional) minimal value for the penalty parameter \tau (default: .1).

verbose

(optional) logical indicating whether estimation step details should be displayed (default: FALSE).

Value

a densLPS.object containing the density estimation results.

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

densLPS.object, print.densLPS, plot.densLPS, Dens1d.object, Dens1d.

Examples

library(DALSM)

## Example 1: estimation of the error density in a DALSM model
require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
plot(fit$derr)  ## Plot the estimated error density
print(fit$derr) ## ... and provide summary statistics for it

## Example 2: density estimation from censored income data
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
head(resp,n=20)
temp = Dens1d(y=resp,ymin=0) ## Create Dens1d object from positive censored data
obj = densityLPS(temp) ## Density estimation from IC & RC data
print(obj) ## Summary information on the estimated density
plot(obj,hist=TRUE) ## Visualize the estimated density
legend("topright",col=c("black","grey"),lwd=c(2,20),
       legend=c("Fitted density","Pseudo-data"),bty="n")

## Example 3: density estimation from simulated RC and IC data
## Data generation
set.seed(123)
n = 500 ## Sample size
x = rgamma(n,10,2) ## Exact (unobserved) data
width = runif(n,1,3) ## Width of the IC data (mean width = 2)
w = runif(n) ## Positioning of the exact data within the interval
xmat = cbind(pmax(0,x-w*width),x+(1-w)*width) ## Generated IC data
t.cens = rexp(n,1/15) ## Right-censoring values
idx.RC = (1:n)[t.cens<x] ## Id's of the right-censored units
xmat[idx.RC,] = cbind(t.cens[idx.RC],Inf) ## Data for RC units: (t.cens,Inf)
head(xmat,15)
## Density estimation with mean and variance constraints
obj.data = Dens1d(xmat,ymin=0) ## Prepare the data for estimation
obj = densityLPS(obj.data,Mean0=10/2,Var0=10/4) ## Density estimation
print(obj)
plot(obj) ## Plot the estimated density
curve(dgamma(x,10,2), ## ... and compare it to the true density (in red)
      add=TRUE,col="red",lwd=2,lty=2)
legend("topright",col=c("black","red"),lwd=c(2,2),lty=c(1,2),
       legend=c("Estimated density","True density"),bty="n")
## Same story for the cdf
with(obj, curve(pdist(x),ymin,ymax,lwd=2,xlab="",ylab="F(x)"))
curve(pgamma(x,10,2),add=TRUE,col="red",lwd=2,lty=2)
legend("right",col=c("black","red"),lwd=c(2,2),lty=c(1,2),
       legend=c("Estimated cdf","True cdf"),bty="n")


Log-determinant of a positive-definite matrix

Description

Log-determinant of a positive-definite matrix

Usage

logDet.fun(x)

Arguments

x

positive definite matrix.

Value

log of det(x).

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

Examples

A = matrix(1:4,ncol=2)
logDet.fun(A)


Plot visual information on a DALSM.object

Description

Visualize the estimated additive terms and error density corresponding to a Double Additive Location-Scale Model (DALSM) object.

Usage

## S3 method for class 'DALSM'
plot(x,
       mfrow.loc=NULL, mfrow.disp=NULL,
       nx=101, equal.ylims=TRUE, true.loc=NULL,true.disp=NULL, ci.level=NULL,
       error.lim = NULL, add.residuals=FALSE, true.derr=NULL, new.dev=TRUE, ...)

Arguments

x

a DALSM.object.

mfrow.loc

(optional) window layout to plot the additive terms for location.

mfrow.disp

(optional) window layout to plot the additive terms for dispersion.

nx

(optional) number of points to make the plots for the fitted additive terms (default: 101).

equal.ylims

logical indicating if the same y-limits must be used when plotting the fitted additive terms (default: TRUE).

true.loc

(optional) list of functions to be superposed to the corresponding estimated additive terms in the location submodel (default: NULL).

true.disp

(optional) list of functions to be superposed to the corresponding estimated additive terms in the dispersion submodel (default: NULL).

ci.level

(optional) nominal level for the plotted pointwise credible intervals (default: x$ci.level).

error.lim

(optional) plotting interval for the estimated standardized error density in the DALSM model (default: support of the fitted standardized error density).

add.residuals

logical requesting to add the (possibly censored) standardized residuals to the plot of the fitted standardized error density (default: FALSE).

true.derr

(optional) density function to superpose to the estimated standardized error density when plotting (default: NULL).

new.dev

(optional) logical indicating whether a new plotting device must be opened for each graph (default: TRUE).

...

additional generic plotting arguments.

Details

Plot the fitted additive terms and the estimated standardized error density contained in the DALSM.object x.

Value

In addition to the plots, an invisible list containing the following is returned:

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

DALSM, DALSM.object, print.DALSM

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
plot(fit)


Plot the density estimate in a densLPS.object

Description

Plot the density estimate obtained by densityLPS from censored data with given mean and variance.

Usage

## S3 method for class 'densLPS'
plot(x,
       xlim=range(fit$bins),breaks=NULL,hist=FALSE,histRC=FALSE,
       xlab="",ylab="Density",main="",...)

Arguments

x

a densLPS.object.

xlim

interval of values where the density should be plotted.

breaks

(Optional) breaks for the histogram of the observed residuals.

hist

Logical (Default: FALSE) indicating whether the histogram of the (pseudo-) data should be plotted with the estimated density.

histRC

Logical (Default: FALSE) indicating whether the histogram of the right-censored residuals should be highlighted.

xlab

Optional label for the x-axis (Defaut: empty).

ylab

Optional label for the y-axis (Default: "Density").

main

Plot main title (Default: "").

...

Optional additional plot parameters.

Value

No returned value (just plots).

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

densLPS.object, print.densLPS, densityLPS.

Examples

require(DALSM)

## Example 1: density estimation from simulated IC data
n = 500 ## Sample size
x = 3 + rgamma(n,10,2) ## Exact generated data
width = runif(n,1,3) ## Width of the IC data (mean width = 2)
w = runif(n) ## Positioning of the exact data within the interval
xmat = cbind(x-w*width,x+(1-w)*width) ## Generated IC data
head(xmat)
obj.data = Dens1d(xmat,ymin=0) ## Prepare the data for estimation
## Density estimation with fixed mean and variance
obj = densityLPS(obj.data,Mean0=3+10/2,Var0=10/4)
plot(obj, hist=TRUE) ## Histogram of the pseudo-data with the density estimate
curve(dgamma(x-3,10,2), ## ... compared to the true density (in red)
      add=TRUE,col="red",lwd=2,lty=2)
legend("topright",col=c("black","red","grey"),lwd=c(2,2,10),lty=c(1,2,1),
       legend=c("Fitted density","True density","Pseudo-data"),bty="n")
print(obj) ## ... with summary statistics

## Example 2: estimation of the error density in a DALSM model
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
plot(fit$derr, hist=TRUE)  ## Plot the estimated error density
legend("topright",col=c("black","grey"),lwd=c(2,10),lty=c(1,1),
       legend=c("Estimated error density","Pseudo-residuals"),bty="n")
print(fit$derr) ## ... and provide summary statistics for it

Plot a credible region for a curve together with its point estimates

Description

Plot a credible region (in grey) for a curve together with its point estimates.

Usage

plotRegion(x,mat,
       add=FALSE, xlim=range(x), ylim=range(mat),
       lwd=2, xlab="", ylab="", main="", ...)

Arguments

x

vector of values where the curve is evaluated.

mat

cbind(f.hat,f.low,f.up) is a matrix containing the point estimates <f.hat> and the liming values <f.low> and <f.up> for the credible region.

add

Logical indicating if the plot must be added to the active plot (Default: FALSE).

xlim

range of <x> values for which the plot should be provided.

ylim

range of curve values that should be considered for the plot.

lwd

line width for the plot (Default: 2).

xlab

x-label.

ylab

y-label.

main

main title.

...

optional plotting parameters.

Value

No returned value (just a plot)

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

DALSM, DALSM.object.

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
obj = DALSM_additive(fit)
## par(mfrow=c(1,2),mar=c(4,5,1,1))
with(obj$f.loc.grid$age, plotRegion(x, y.mat,
     xlab="age", ylab=expression('f'[1]^{~mu}*(age))))
with(obj$f.disp.grid$age, plotRegion(x, y.mat,
     xlab="age", ylab=expression('f'[1]^{~sigma}*(age))))

Prediction based on a DALSM model

Description

Estimated conditional mean and standard deviation of the response based on a DALSM object for given covariate values in a data frame 'newdata'. Conditional quantiles can also be computed.

Usage

## S3 method for class 'DALSM'
predict(object, newdata, probs, ...)

Arguments

object

a DALSM.object.

newdata

an optional data frame in which to look for variables with which to predict. If omitted, the covariate values in the original data frame used to fit the DALSM model are considered.

probs

probability levels of the requested conditional quantiles.

...

further arguments passed to or from other methods.

Value

Returns a list containing:

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

DALSM.object, print.DALSM, plot.DALSM.

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
data2 = data.frame(age=c(40,60),eduyrs=c(18,12))
predict(fit, data = DALSM_IncomeData, newdata=data2, probs=c(.2,.5,.8))

Print summary information on a DALSM.object

Description

Print summary information on a DALSM.object.

Usage

## S3 method for class 'DALSM'
print(x,...)

Arguments

x

an object of class DALSM.object.

...

additional generic printing arguments.

Details

Provides summary measures on the estimation of the regression parameters and additive terms in the location and dispersion submodels corresponding to a DALSM.object generated by DALSM.

Value

No returned value (just printed summary).

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

plot.DALSM, DALSM.object, DALSM.

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
print(fit)


Print a summary of the information in a densLPS.object

Description

Print summary information on the density estimate obtained by densityLPS from censored data with given mean and variance.

Usage

## S3 method for class 'densLPS'
print(x,...)

Arguments

x

a densLPS.object.

...

Optional additional print parameters.

Value

No returned value (just printed summary).

Author(s)

Philippe Lambert p.lambert@uliege.be

References

Lambert, P. (2021). Fast Bayesian inference using Laplace approximations in nonparametric double additive location-scale models with right- and interval-censored data. Computational Statistics and Data Analysis, 161: 107250. <doi:10.1016/j.csda.2021.107250>

See Also

densLPS.object, plot.densLPS, densityLPS.

Examples

require(DALSM)
data(DALSM_IncomeData)
resp = DALSM_IncomeData[,1:2]
fit = DALSM(y=resp,
            formula1 = ~twoincomes+s(age)+s(eduyrs),
            formula2 = ~twoincomes+s(age)+s(eduyrs),
            data = DALSM_IncomeData)
plot(fit$derr)  ## Plot the estimated error density
print(fit$derr) ## ... and provide some descriptive elements on it


Specification of knots in a cubic P-spline model

Description

Specification of knots for a cubic B-spline basis with K elements in a P-spline model. The knots should support the data contained in vector x and are by default assumed equidistant. Alternatively, they can be based on the data quantiles. The penalty matrix of the selected penalty order (3 by default) is also returned.

Usage

qknots(x, xmin = NULL, xmax = NULL, equid.knots = TRUE, pen.order = 3, K = 25)

Arguments

x

data that the knots should upport.

xmin

desired minimum value for the knots.

xmax

desired maximum value for the knots.

equid.knots

logical indicating if equidistant knots are desired (Default: TRUE). If FALSE, the quantile of x are used to select the knots.

pen.order

penalty order if equid.knots is TRUE.

K

number of B-splines in the basis.

Value

A list containing:

Examples

x = runif(500)
obj = qknots(x,xmin=0,xmax=1,K=13)
print(obj)

Specification of smooth terms in formulas in the DALSM function.

Description

Specification of smooth terms in formulas in the DALSM 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