predict.piqr: Prediction After Penalized Quantile Regression Coefficients...

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Predictions from an object of class “piqr”, after selecting the best tuning parameter.

Usage

1
2
3
## S3 method for class 'piqr'
predict(object, lambda, type=c("beta", "CDF", "QF", "sim"), newdata,
                       p, se=TRUE, ...)

Arguments

object

an object of class “piqr”, the result of a call to piqr.

lambda

a value of lambda in the sequence of the object of class “piqr”. Could be the best after selecting the result of a call to gof.piqr

type

a character string specifying the type of prediction. See ‘Details’.

newdata

an optional data frame in which to look for variables with which to predict. If omitted, the data are used. For type = "CDF", it must include the response variable. Ignored if type = "beta".

p

a numeric vector indicating the order(s) of the quantile to predict. Only used if type = "beta" or type = "QF".

se

logical. If TRUE (the default), standard errors of the prediction will be computed. Only used if type = "beta" or type = "QF".

...

for future methods.

Details

If the best lambda or one value of lambda is chosen, the function call predict.iqr.

Value

See details in predict.iqr

Note

Prediction may generate quantile crossing if the support of the new covariates values supplied in newdata is different from that of the observed data.

Author(s)

Gianluca Sottile gianluca.sottile@unipa.it

See Also

piqr, for model fitting; gof.piqr, to find the best lambda value; summary.piqr and plot.piqr, for summarizing and plotting piqr objects.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# using simulated data

set.seed(1234)
n <- 1000
x1 <- rexp(n)
x2 <- runif(n, 0, 5)
x <- cbind(x1,x2)

b <- function(p){matrix(cbind(1, qnorm(p), slp(p, 2)), nrow=4, byrow=TRUE)}
theta <- matrix(0, nrow=3, ncol=4); theta[, 1] <- 1; theta[1,2] <- 1; theta[2:3,3] <- 2
qy <- function(p, theta, b, x){rowSums(x * t(theta %*% b(p)))}

y <- qy(runif(n), theta, b, cbind(1, x))

s <- matrix(1, nrow=3, ncol=4); s[1,3:4] <- 0
obj <- piqr(y ~ x1 + x2, formula.p = ~ I(qnorm(p)) + slp(p, 2), s=s)

best <- gof.piqr(obj, method="AIC", plot=FALSE)

# predict beta(0.25), beta(0.5), beta(0.75)
predict(obj, best$minLambda, type = "beta", p = c(0.25,0.5, 0.75))

# predict the CDF and the PDF at new values of x and y
predict(obj, best$minLambda, type = "CDF",
        newdata = data.frame(x1=rexp(3), x2=runif(3), y = c(1,2,3)))

# computes the quantile function at new x, for p = (0.25,0.5,0.75)
predict(obj, best$minLambda, type = "QF", p = c(0.25,0.5,0.75),
        newdata = data.frame(x1=rexp(3), x2=runif(3), y = c(1,2,3)))

# simulate data from the fitted model
ysim <- predict(obj, best$minLambda, type = "sim") # 'newdata' can be supplied

# if the model is correct, the distribution of y and that of ysim should be similar
qy <- quantile(y, prob = seq(.1,.9,.1))
qsim <- quantile(ysim, prob = seq(.1,.9,.1))
plot(qy, qsim); abline(0,1)

gianluca-sottile/qrcmPen documentation built on May 8, 2019, 9:23 a.m.