Package 'dcurver'

Title: Utility Functions for Davidian Curves
Description: A Davidian curve defines a seminonparametric density, whose shape and flexibility can be tuned by easy to estimate parameters. Since a special case of a Davidian curve is the standard normal density, Davidian curves can be used for relaxing normality assumption in statistical applications (Zhang & Davidian, 2001) <doi:10.1111/j.0006-341X.2001.00795.x>. This package provides the density function, the gradient of the loglikelihood and a random generator for Davidian curves.
Authors: Oğuzhan Öğreden
Maintainer: Oğuzhan Öğreden <[email protected]>
License: GPL-3
Version: 0.9.2
Built: 2024-11-13 06:26:49 UTC
Source: CRAN

Help Index


Gradient of the log-likelihood of univariate Davidian curves

Description

Provides the gradient for use in estimation.

Usage

dc_grad(x, phi)

Arguments

x

A vector of observations.

phi

phi Davidian curve parameters. A maximum of 10 parameters is allowed.

Details

Woods & Lin (2009) provide the gradient (Equations 17 and 18). Note that the gradient is not defined for phi = 0.0.

References

Woods, C. M., & Lin, N. (2009). Item response theory with estimation of the latent density using Davidian curves. Applied Psychological Measurement, 33(2), 102-117. doi:10.1177/0146621608319512

Examples

# The loglikelihood of a univariate Davidian curve is given by,
dc_LL <- function(phi, dat) {
  sum(log(ddc(dat, phi)))
}

# dc_grad can be used for obtaining the gradient of this loglikelihood as follows:
dc_LL_GR <- function(phi, dat) {
  colSums(dc_grad(dat, phi))
}

# This can be verified by numerical approximation.
# For instance, using numDeriv package:
## Not run: 
phi <- c(-5, 2.5, 10)
d <- runif(10, -5, 5)
dc_LL_GR(phi, d)
numDeriv::grad(dc_LL, x = phi, dat = d)

phi <- c(-5, 0, 10)
dc_LL_GR(phi, d)

## End(Not run)

Density function for univariate Davidian curves

Description

Returns the density for a vector of x.

Usage

ddc(x, phi)

Arguments

x

vector of quantiles.

phi

Davidian curve parameters. A maximum of 10 parameters is allowed.

Examples

curve(ddc(x, 1.570789), -6, 6) # Approximately normal.

phi <- c(77.32, 78.51, 76.33, 77.16)
curve(ddc(x, phi), -6, 6) # A bimodal density.
integrate(ddc, phi = phi, lower = -Inf, upper = Inf) # Integrates to 1.

Random samples from univariate Davidian curves

Description

Returns n samples from a univariate Davidian curve.

Usage

rdc(n, phi)

Arguments

n

Number of observations to be sampled.

phi

Davidian curve parameters. A maximum of 10 parameters is allowed.

Examples

# Sample from the standard normal Davidian curve:
hist(rdc(1000, 1.570789), xlim = c(-6, 6), ylim = c(0, 0.5), freq = FALSE, breaks = 20)
curve(dnorm(x), -6, 6, col = "blue", lwd = 1, add = TRUE)
curve(ddc(x, 1.570789), -6, 6, col = "red", lwd = 2, lty = 3, add = TRUE)

# Sample from a bimodal density:
phi <- c(77.32, 78.51, 76.33, 77.16)
hist(rdc(1000, phi), xlim = c(-6, 6), ylim = c(0, 0.4), freq = FALSE, breaks = "fd")
curve(ddc(x, phi), -6, 6, col = "red", lwd = 2, lty = 3, add = TRUE)