tsreg:

Usage Arguments Examples

Usage

1
tsreg(x, y, xout = FALSE, outfun = outpro, iter = 10, varfun = pbvar, corfun = pbcor, plotit = FALSE, WARN = TRUE, HD = FALSE, OPT = FALSE, xlab = "X", ylab = "Y", ...)

Arguments

x
y
xout
outfun
iter
varfun
corfun
plotit
WARN
HD
OPT
xlab
ylab
...

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
##---- 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, xout = FALSE, outfun = outpro, iter = 10, varfun = pbvar, 
    corfun = pbcor, plotit = FALSE, WARN = TRUE, HD = FALSE, 
    OPT = FALSE, xlab = "X", ylab = "Y", ...) 
{
    x <- as.matrix(x)
    xx <- cbind(x, y)
    xx <- elimna(xx)
    x <- xx[, 1:ncol(x)]
    x <- as.matrix(x)
    y <- xx[, ncol(x) + 1]
    temp <- NA
    x <- as.matrix(x)
    n = nrow(x)
    n.keep = n
    if (xout) {
        x <- as.matrix(x)
        flag <- outfun(x, plotit = FALSE, ...)$keep
        x <- x[flag, ]
        y <- y[flag]
        x <- as.matrix(x)
        n.keep = nrow(x)
    }
    if (ncol(x) == 1) {
        temp1 <- tsp1reg(x, y, HD = HD, OPT = OPT)
        coef <- temp1$coef
        res <- temp1$res
    }
    if (ncol(x) > 1) {
        for (p in 1:ncol(x)) {
            temp[p] <- tsp1reg(x[, p], y, OPT = OPT)$coef[2]
        }
        res <- y - x %*% temp
        if (!HD) 
            alpha <- median(res)
        if (HD) 
            alpha <- hd(res)
        r <- matrix(NA, ncol = ncol(x), nrow = nrow(x))
        tempold <- temp
        for (it in 1:iter) {
            for (p in 1:ncol(x)) {
                r[, p] <- y - x %*% temp - alpha + temp[p] * 
                  x[, p]
                temp[p] <- tsp1reg(x[, p], r[, p], plotit = FALSE, 
                  OPT = OPT)$coef[2]
            }
            if (!HD) 
                alpha <- median(y - x %*% temp)
            if (HD) 
                alpha <- hd(y - x %*% temp)
            tempold <- temp
        }
        coef <- c(alpha, temp)
        res <- y - x %*% temp - alpha
    }
    yhat <- y - res
    stre = NULL
    temp = varfun(y)
    if (temp == 0) {
        if (WARN) 
            print("Warning: When computing strength of association, measure of variation=0")
    }
    e.pow = NULL
    if (temp > 0) {
        e.pow <- varfun(yhat)/varfun(y)
        if (!is.na(e.pow)) {
            if (e.pow >= 1) 
                e.pow <- corfun(yhat, y)$cor^2
            e.pow = as.numeric(e.pow)
            stre = sqrt(e.pow)
        }
    }
    if (plotit) {
        if (ncol(x) == 1) {
            plot(x, y, xlab = xlab, ylab = ylab)
            abline(coef)
        }
    }
    list(n = n, n.keep = n.keep, coef = coef, residuals = res, 
        Strength.Assoc = stre, Explanatory.Power = e.pow)
  }

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