predict.iqrL {qrcm} | R Documentation |
Prediction After Quantile Regression Coefficients Modeling with Longitudinal Data
Description
Predictions from an object of class “iqrL
”.
Usage
## S3 method for class 'iqrL'
predict(object, level, type = c("coef", "CDF", "QF", "sim"), newdata, p, se = FALSE, ...)
Arguments
object |
an object of class “ |
level |
a numeric scalar. Use |
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 (ignored if type = "coef").
For type = "CDF", |
p |
a numeric vector indicating the order(s) of the quantile to predict. Only used if type = "coef" or type = "QF". |
se |
logical. If TRUE (the default), standard errors of the prediction will be computed. Only used if type = "coef" or type = "QF". |
... |
for future methods. |
Details
if type = "coef" (the default), quantile regression coefficients are returned: if level = 1,
; and if level = 2,
. If p is missing, a default p = (0.01, ..., 0.99) is used.
if type = "CDF", the value of the fitted CDF (cumulative distribution function) and PDF (probability density function) are computed. If level = 1, these refer to the distribution of
, and the CDF is an estimate of
. If level = 2, they refer to the distribution of
, and the CDF is an estimate of
.
if type = "QF", the fitted values
(if level = 1), or
(if level = 2).
if type = "sim", data are simulated from the fitted model. If level = 1, simulated values are from the distribution of
, while if level = 2, they are from the distribution of
.
Value
if type = "coef" a list with one item for each covariate. Each element of the list is a data frame with columns (u, beta, se, low, up), if level = 1, and (v, gamma, se, low, up), if level = 2. If se = FALSE, the last three columns are not computed.
if type = "CDF", a two-columns data frame (CDF,PDF).
if type = "QF" and se = FALSE, a data frame with one row for each observation, and one column for each value of p. If se = TRUE, a list of two data frames, fit (predictions) and se.fit (standard errors).
if type = "sim", a vector of simulated data.
Note
If no newdata are supplied, the observed data are used and predictions are ordered as follows:
if level = 1, by increasing id and, within each id, by increasing values of the response variable y. Rownames will indicate the position in the original data frame.
if level = 2, by increasing id.
Author(s)
Paolo Frumento paolo.frumento@unipi.it
See Also
iqrL
, for model fitting; summary.iqrL
and plot.iqrL
,
for summarizing and plotting iqrL
objects.
Examples
# using simulated data
n <- 1000 # n. of observations
n.id <- 100 # n. of clusters
id <- rep(1:n.id, each = n/n.id) # cluster id
x1 <- runif(n) # a level-1 covariate
z1 <- rbinom(n.id,1,0.5) # a level-2 covariate
V <- runif(n.id) # V_i
U <- runif(n) # U_it
alpha <- qlogis(V)*(0.5 + z1) # alpha
y_alpha <- 1 + 2*qexp(U) + 3*x1 # y - alpha
y <- y_alpha + alpha[id] # observed outcome
mydata <- data.frame(id = id, y = y, x1 = x1, z1 = z1[id])
# true model: Y_it = beta0(U_it) + beta1(U_it)*x1 + gamma0(V_i) + gamma1(V_i)*z1
# beta0(u) = 1 + 2*pexp(u)
# beta1(u) = 3
# gamma0(v) = 0.5*qlogis(v)
# gamma1(v) = qlogis(V)
model <- iqrL(fx = y ~ x1, fu = ~ I(qexp(u)), fz = ~ z1, fv = ~ -1 + I(qlogis(v)),
id = id, data = mydata)
# predict beta(0.25), beta(0.5), beta(0.75)
predict(model, level = 1, type = "coef", p = c(0.25,0.5,0.75))
# predict gamma(0.1), gamma(0.9)
predict(model, level = 2, type = "coef", p = c(0.1,0.9))
# predict the CDF (u) and the PDF of (y - alpha), at new values of x1
predict(model, level = 1, type = "CDF",
newdata = data.frame(x1 = c(.1,.2,.3), y_alpha = c(1,2,3)))
# predict the CDF (v) and the PDF of alpha, at new values of z1
predict(model, level = 2, type = "CDF",
newdata = data.frame(z1 = c(0,1), alpha = c(-1,1)))
# computes the quantile function of (y - alpha) at new x1, for u = (0.25,0.5,0.75)
predict(model, level = 1, type = "QF", p = c(0.25,0.5,0.75),
newdata = data.frame(x1 = c(.1,.2,.3)))
# computes the quantile function of alpha at new z1, for v = (0.25,0.5,0.75)
predict(model, level = 2, type = "QF", p = c(0.25,0.5,0.75),
newdata = data.frame(z1 = c(.1,.2,.3)))
# simulate data from the fitted model
y_alpha_sim <- predict(model, level = 1, type = "sim")
alpha_sim <- predict(model, level = 2, type = "sim")
y_sim = y_alpha_sim + alpha_sim[id]