qreg:

Usage Arguments Examples

Usage

1
qreg(x, y, qval = 0.5, q = NULL, pr = FALSE, xout = FALSE, outfun = outpro, plotit = FALSE, xlab = "X", ylab = "Y", op = 1, v2 = TRUE, ...)

Arguments

x
y
qval
q
pr
xout
outfun
plotit
xlab
ylab
op
v2
...

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, y, qval = 0.5, q = NULL, pr = FALSE, xout = FALSE, 
    outfun = outpro, plotit = FALSE, xlab = "X", ylab = "Y", 
    op = 1, v2 = TRUE, ...) 
{
    if (!is.null(q)) 
        qval = q
    x <- as.matrix(x)
    X <- cbind(x, y)
    X <- elimna(X)
    np <- ncol(X)
    p <- np - 1
    x <- X[, 1:p]
    x <- as.matrix(x)
    y <- X[, np]
    if (xout) {
        x <- as.matrix(x)
        flag <- outfun(x, plotit = FALSE, ...)$keep
        x <- x[flag, ]
        y <- y[flag]
        x <- as.matrix(x)
    }
    if (!v2) {
        temp <- ltareg(x, y, 0, op = op)
        if (qval == 0.5) {
            coef <- temp$coef
            res <- temp$res
        }
        if (qval != 0.5) {
            START <- temp$coef
            coef <- nelderv2(X, np, FN = qreg.sub, START = START, 
                qval = qval)
        }
    }
    if (v2) {
        if (pr) {
            print("v2=T attempts to use a faster version by calling")
            print("the function rq")
            print("To avoid this message, use pr=FALSE")
            print(" ")
        }
        library(quantreg)
        x <- as.matrix(x)
        temp <- rq(y ~ x, tau = qval)
        coef <- temp[1]$coefficients
    }
    if (ncol(x) == 1) {
        if (plotit) {
            plot(x, y, xlab = xlab, ylab = ylab)
            abline(coef)
        }
    }
    res <- y - x %*% coef[2:np] - coef[1]
    list(coef = coef, residuals = res)
  }

musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.