wsp1reg:

Usage Arguments Examples

Usage

1
wsp1reg(x, y, plotit = FALSE)

Arguments

x
y
plotit

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
##---- 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, plotit = FALSE) 
{
    temp <- matrix(c(x, y), ncol = 2)
    temp <- elimna(temp)
    x <- temp[, 1]
    y <- temp[, 2]
    ord <- order(x)
    xs <- x[ord]
    ys <- y[ord]
    vec1 <- outer(ys, ys, "-")
    vec2 <- outer(xs, xs, "-")
    v1 <- vec1[vec2 > 0]
    v2 <- vec2[vec2 > 0]
    slope <- v1/v2
    tmin <- wrregfun(slope[1], x, y)
    ikeep <- 1
    for (i in 2:length(slope)) {
        tryit <- wrregfun(slope[i], x, y)
        if (tryit < tmin) {
            tmin <- tryit
            ikeep <- i
        }
    }
    coef <- NA
    coef[2] <- slope[ikeep]
    coef[1] <- median(y - coef[2] * x)
    if (plotit) {
        plot(x, y, xlab = "X", ylab = "Y")
        abline(coef)
    }
    res <- y - coef[2] * x - coef[1]
    list(coef = coef, residuals = res)
  }

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