Density function, distribution function, and quantile/expectile function and random generation for the scaled Student t distribution with 2 degrees of freedom.

dsc.t2(x, location = 0, scale = 1, log = FALSE)
psc.t2(q, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
qsc.t2(p, location = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
rsc.t2(n, location = 0, scale = 1)

Arguments

x, q

Vector of expectiles/quantiles. See the terminology note below.

p

Vector of probabilities. These should lie in \((0,1)\).

n, log

See runif.

location, scale

Location and scale parameters. The latter should have positive values. Values of these vectors are recyled.

lower.tail, log.p

Same meaning as in pt or qt.

Details

A Student-t distribution with 2 degrees of freedom and a scale parameter of sqrt(2) is equivalent to the standard form of this distribution (called Koenker's distribution below). Further details about this distribution are given in sc.studentt2.

Value

dsc.t2(x) gives the density function. psc.t2(q) gives the distribution function. qsc.t2(p) gives the expectile and quantile function. rsc.t2(n) gives \(n\) random variates.

Author

T. W. Yee and Kai Huang

See also

Examples

my.p <- 0.25; y <- rsc.t2(nn <- 5000)
(myexp <- qsc.t2(my.p))
#> [1] -1.154701
sum(myexp - y[y <= myexp]) / sum(abs(myexp - y))  # Should be my.p
#> [1] 0.2484664
# Equivalently:
I1 <- mean(y <= myexp) * mean( myexp - y[y <= myexp])
I2 <- mean(y >  myexp) * mean(-myexp + y[y >  myexp])
I1 / (I1 + I2)  # Should be my.p
#> [1] 0.2484664
# Or:
I1 <- sum( myexp - y[y <= myexp])
I2 <- sum(-myexp + y[y >  myexp])

# Non-standard Koenker distribution
myloc <- 1; myscale <- 2
yy <- rsc.t2(nn, myloc, myscale)
(myexp <- qsc.t2(my.p, myloc, myscale))
#> [1] -1.309401
sum(myexp - yy[yy <= myexp]) / sum(abs(myexp - yy))  # Should be my.p
#> [1] 0.2486396
psc.t2(mean(yy), myloc, myscale)  # Should be 0.5
#> [1] 0.4973873
abs(qsc.t2(0.5, myloc, myscale) - mean(yy))  # Should be 0
#> [1] 0.02090155
abs(psc.t2(myexp, myloc, myscale) - my.p)  # Should be 0
#> [1] 0
integrate(f = dsc.t2, lower = -Inf, upper = Inf,
          locat = myloc, scale = myscale)  # Should be 1
#> 1 with absolute error < 8e-08

y <- seq(-7, 7, len = 201)
max(abs(dsc.t2(y) - dt(y / sqrt(2), df = 2) / sqrt(2)))  # Should be 0
#> [1] 8.326673e-17
if (FALSE)  plot(y, dsc.t2(y), type = "l", col = "blue", las = 1,
     ylim = c(0, 0.4), main = "Blue = Koenker; orange = N(0, 1)")
lines(y, dnorm(y), type = "l", col = "orange")
#> Error in plot.xy(xy.coords(x, y), type = type, ...): plot.new has not been called yet
abline(h = 0, v = 0, lty = 2)  # \dontrun{}
#> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet