Learn R Programming

Qest (version 1.0.1)

invQ: Inverse of Quantile Function

Description

Auxiliary function to compute cumulative distribution function (CDF) by inverting a quantile function.

Usage

invQ(Q, theta, y, data, n.it = 17)

Value

a vector of CDF values.

Arguments

Q

any parametric quantile function of the form Q(theta, tau, data).

theta

a vector of model parameters.

y

vector of observations to evaluate the CDF.

data

data frame containing the variables used in the Q() function.

n.it

the number of iterations (see “details”).

Author

Maintainer: Gianluca Sottile <gianluca.sottile@unipa.it>

Details

Given a parametric quantile function \(Q(\tau | \theta)\), the CDF is defined as \(F(y | \theta) = Q^{-1}(y | \theta)\). Alternatively, \(F(y | \theta)\) corresponds to the value \(\tau*\) such that \(Q(\tau* | \theta) = y\). Starting from \(\tau = 0.5\), a bisection algorithm is used to evaluate numerically \(\tau*\). The maximum error is given by 1/2^(n.it + 1).

See Also

Qest

Examples

Run this code
# Ex. 1 Normal model

# Quantile function of a linear model.
Qlinmod <- function(theta, tau, data){
  sigma <- exp(theta[1])
  beta <- theta[-1]
  X <- model.matrix( ~ x1 + x2, data = data)
  qnorm(tau, X %*% beta, sigma)
}

n <- 100
x1 <- rnorm(n)
x2 <- runif(n,0,3)
theta <- c(1,4,1,2)

# generate the data
U <- runif(n)
y <- Qlinmod(theta, U, data.frame(x1,x2))

# Given y and theta, evaluate U = F(y)
invQ(Qlinmod, theta, y, data.frame(x1,x2))

Run the code above in your browser using DataLab