olshc4:

Usage Arguments Examples

Usage

1
olshc4(x, y, alpha = 0.05, CN = FALSE, xout = FALSE, outfun = outpro, HC3 = FALSE, plotit = FALSE, xlab = "X", ylab = "Y", zlab = "Z", ...)

Arguments

x
y
alpha
CN
xout
outfun
HC3
plotit
xlab
ylab
zlab
...

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
##---- 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, alpha = 0.05, CN = FALSE, xout = FALSE, outfun = outpro, 
    HC3 = FALSE, plotit = FALSE, xlab = "X", ylab = "Y", zlab = "Z", 
    ...) 
{
    x <- as.matrix(x)
    pnum = ncol(x)
    if (nrow(x) != length(y)) 
        stop("Length of y does not match number of x values")
    m <- cbind(x, y)
    m <- elimna(m)
    y <- m[, ncol(x) + 1]
    x = m[, 1:ncol(x)]
    n = length(y)
    nrem = n
    n.keep = length(y)
    x <- as.matrix(x)
    if (xout) {
        flag <- outfun(x, plotit = FALSE, ...)$keep
        x <- as.matrix(x)
        x <- x[flag, ]
        y <- y[flag]
        n.keep = length(y)
        x <- as.matrix(x)
    }
    temp <- lsfit(x, y)
    x <- cbind(rep(1, nrow(x)), x)
    xtx <- solve(t(x) %*% x)
    h <- diag(x %*% xtx %*% t(x))
    n <- length(h)
    d <- (n * h)/sum(h)
    for (i in 1:length(d)) {
        d[i] <- min(4, d[i])
    }
    if (HC3) 
        d = 2
    hc4 <- xtx %*% t(x) %*% diag(temp$res^2/(1 - h)^d) %*% x %*% 
        xtx
    df <- nrow(x) - ncol(x)
    crit <- qt(1 - alpha/2, df)
    if (CN) 
        crit = qnorm(1 - alpha/2)
    al <- ncol(x)
    p = al - 1
    ci <- matrix(NA, nrow = al, ncol = 6)
    lab.out = rep("Slope", p)
    dimnames(ci) <- list(c("(Intercept)", lab.out), c("Coef.", 
        "Estimates", "ci.lower", "ci.upper", "p-value", "Std.Error"))
    for (j in 1:al) {
        ci[j, 1] <- j - 1
        ci[j, 2] <- temp$coef[j]
        ci[j, 3] <- temp$coef[j] - crit * sqrt(hc4[j, j])
        ci[j, 4] <- temp$coef[j] + crit * sqrt(hc4[j, j])
        test <- temp$coef[j]/sqrt(hc4[j, j])
        ci[j, 5] <- 2 * (1 - pt(abs(test), df))
        if (CN) 
            ci[j, 5] <- 2 * (1 - pnorm(abs(test), df))
    }
    ci[, 6] = sqrt(diag(hc4))
    if (plotit) {
        if (pnum == 1) {
            plot(x[, -1], y, xlab = xlab, ylab = ylab)
            abline(ci[, 2])
        }
        if (pnum == 2) {
            regp2plot(x[, -1], y, regfun = ols, xlab = xlab, 
                ylab = ylab, zlab = zlab)
        }
    }
    list(n = nrem, n.keep = n.keep, ci = ci, cov = hc4)
  }

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