kercon:

Usage Arguments Examples

Usage

1
kercon(x, y, pyhat = FALSE, cval = NA, plotit = TRUE, eout = FALSE, xout = FALSE, outfun = out, iran = 0.05, xlab = "X", ylab = "Y", pch = ".")

Arguments

x
y
pyhat
cval
plotit
eout
xout
outfun
iran
xlab
ylab
pch

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
86
87
88
89
90
91
92
##---- 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, pyhat = FALSE, cval = NA, plotit = TRUE, eout = FALSE, 
    xout = FALSE, outfun = out, iran = 0.05, xlab = "X", ylab = "Y", 
    pch = ".") 
{
    d <- ncol(x)
    if (d != 2) 
        stop("Argument x should have two columns only")
    np1 <- d + 1
    m <- elimna(cbind(x, y))
    x <- m[, 1:d]
    y <- m[, np1]
    yhat1 <- NA
    if (eout && xout) 
        stop("Can't have both eout and xout=F")
    if (eout) {
        flag <- outfun(m)$keep
        m <- m[flag, ]
    }
    if (xout) {
        flag <- outfun(x)$keep
        m <- m[flag, ]
    }
    x <- m[, 1:d]
    y <- m[, np1]
    if (is.na(cval[1])) {
        temp <- idealf(x[, 2])
        cval <- c(temp$ql, median(x[, 2]), temp$qu)
    }
    xrem <- x
    x2 <- x[, 2]
    n <- nrow(x)
    sig <- sqrt(var(x2))
    temp <- idealf(x2)
    iqr <- (temp$qu - temp$ql)/1.34
    A1 <- min(c(sig, iqr))
    A <- 1.77
    hval <- A * (1/n)^(1/6)
    svec <- NA
    for (j in 1:d) {
        sig <- sqrt(var(x[, j]))
        temp <- idealf(x[, j])
        iqr <- (temp$qu - temp$ql)/1.34
        A <- min(c(sig, iqr))
        svec[j] <- A
        x[, j] <- x[, j]/A
    }
    hval <- hval * sqrt(mean(svec^2))
    ilow <- round(iran * length(y))
    iup <- round((1 - iran) * length(y))
    for (il in 1:length(cval)) {
        temp4 <- NA
        for (j in 1:nrow(x)) {
            temp4[j] <- ((x2[j] - cval[il])/A1)^2
        }
        yhat <- NA
        epan1 <- ifelse(temp4 < 1, 0.75 * (1 - temp4), 0)
        for (j in 1:n) {
            yhat[j] <- NA
            temp1 <- cbind(x[, 1] - x[j, 1], x[, 2] - cval[il]/A)/hval
            temp1 <- temp1^2
            temp1 <- apply(temp1, 1, FUN = "sum")
            temp <- 0.5 * (d + 2) * (1 - temp1)/gamma(0.5)^2
            epan <- ifelse(temp1 < 1, temp, 0)
            if (epan1[j] > 0) 
                epan[j] <- epan[j]/epan1[j]
            if (epan1[j] == 0) 
                epan[j] <- 0
            chkit <- sum(epan != 0)
            if (chkit >= np1) {
                vals <- lsfit(x[, 1], y, wt = epan)$coef
                yhat[j] <- x[j, 1] * vals[2] + vals[1]
            }
        }
        if (plotit) {
            xorder <- order(xrem[, 1])
            if (il == 1) 
                plot(xrem[, 1], y, xlab = xlab, ylab = ylab, 
                  pch = pch)
            lines(xrem[xorder[ilow:iup], 1], yhat[xorder[ilow:iup]], 
                lty = il)
        }
    }
    m <- "Done"
    if (pyhat) 
        m <- yhat
    m
  }

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