tsgreg:

Usage Arguments Examples

Usage

1
tsgreg(x, y, tries = (length(y)^2 - length(y))/2)

Arguments

x
y
tries

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
##---- 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, tries = (length(y)^2 - length(y))/2) 
{
    x <- as.matrix(x)
    if (nrow(x) != length(y)) 
        stop("Length of y must match the number of rows of x")
    m1 <- cbind(x, y)
    m1 <- elimna(m1)
    x <- m1[, 1:ncol(x)]
    y <- m1[, ncol(x) + 1]
    set.seed(2)
    data <- matrix(NA, ncol = ncol(x) + 1, nrow = tries)
    for (i in 1:tries) {
        data[i, ] <- sample(length(y), size = ncol(x) + 1, replace = FALSE)
    }
    bvec <- apply(data, 1, tsgregs1, x, y)
    coef <- 0
    numzero <- 0
    loc <- 0
    for (i in 1:ncol(x)) {
        ip <- i + 1
        temp <- bvec[ip, ]
        loc[i] <- median(x[, i])
        coef[i + 1] <- median(temp[temp != 0])
        numzero[i] <- length(temp[temp == 0])
    }
    ip <- ncol(x) + 1
    coef[1] <- median(y) - sum(coef[2:ip] * loc)
    res <- y - x %*% coef[2:ip] - coef[1]
    list(coef = coef, residuals = res, numzero = numzero)
  }

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