Q.reg: Conditional quantile regression with 'VGAM'

View source: R/Q.reg.R

Q.regR Documentation

Conditional quantile regression with VGAM

Description

Use this function to adequately confer the formula in VGAM when fitting quantile regression models.

Usage

    Q.reg(y, pvector = NULL, length.arg = NULL)

Arguments

y

Numeric, a vector or a matrix. It is the response or dependent variable in the formula of the model to be fit, as in vglm or vgam. See below for further details.

pvector

A prototype vector. Entries are the conditional p–quantiles in the fitting process.

length.arg

A length–1 positive integer. It is the number of p–quantiles to be modelled.

Details

Conditional quantile regression can be carried out using family functions in VGAM and VGAMextra. The formula must be set up using this function, Q.reg. Here, the p–quantiles of interest may be entered via pvector. Alternatively, use argument length.arg by establishing the length of pvector.

Besides, the corresponding link must be entered. For example, gamma1Qlink is the proper link to fit models of conditional quantiles for data distributed as Gamma via the family function gamma1.

See examples for further details.

Value

A matrix, each column adequately arranged for regression on conditional quantiles, conforming with VGAM.

Indeed, this is equivalent to cbind(y, y, ...), where the total number of columns is, either the length of pvector, or length.arg.

Note

Link functions for quantile regression in VGAM require the vector of p–quantiles of interest via the argument p. See normal1sdQlink or maxwellQlink for instance.

Therefore, the integer entered at length.arg in this function, if utilized, must match the length of the vector p. Else, it will be recycled.

Author(s)

V. Miranda and T. W. Yee.

See Also

normal1sdQlink, maxwellQlink, gamma1Qlink, gamma1, vglm, vgam

Examples

   
  ###  Quantile regression with data distributed as Maxwell(s)  ###
   set.seed(12073)
   x2 <- seq(0, 100,length.out = 100)       # independent variable
   b0 <- 0.5                                # true intercept
   b1 <- 0.25                               # true slope
   b2 <- 0.02                               # true second order coef.
   alpha <- b0 + b1 * x2 + b2 * x2^2        # Quadratically modelling the parameters
   nn <- 100                                # Sample size
  
   # The data as a data frame. #
   mdata <- data.frame(y = rmaxwell(n = nn, rate = alpha), x2 = x2, x3 = x2^2)
   
   # Quantile regression using our link function maxwellQlink(). #
   # Quantiles 25%, 50%, 75% are of interest #
   my.p <- c(0.25, 0.50, 0.75)
   
   fit <- vglm(Q.reg(y, pvector = my.p) ~ x2 + x3, 
   
  # OPTIONALLY Q.reg(y, length = length(my.p)) ~ x2 + x3
   
              maxwell(link = maxwellQlink(p = my.p)), 
              data = mdata,  trace = TRUE, crit = "coef")

   coef(fit, matrix = TRUE) 
   summary(fit)
   head(predict(fit))
   constraints(fit)

VGAMextra documentation built on Nov. 2, 2023, 5:59 p.m.