1 |
x |
|
y |
|
z |
|
plotit |
|
op |
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 | ##---- 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, z = NA, plotit = FALSE, op = 1)
{
xsort <- sort(x)
ysort <- sort(y)
xhat <- 0
yhat <- 0
yyhat <- 0
if (op == 1) {
for (i in 1:length(xsort)) xhat[i] <- kerden(x, 0, xsort[i])
for (i in 1:length(xsort)) yhat[i] <- kerden(y, 0, xsort[i])
}
if (op == 2) {
xhat <- akerd(x, pts = xsort, pyhat = TRUE, plotit = FALSE)
yhat <- akerd(y, pts = xsort, pyhat = TRUE, plotit = FALSE)
}
yhat[is.na(yhat)] <- 0
if (plotit) {
if (op == 1) {
for (i in 1:length(ysort)) yyhat[i] <- kerden(y,
0, ysort[i])
}
if (op == 2)
yyhat <- akerd(y, pts = ysort, plotit = FALSE, pyhat = T)
plot(c(xsort, ysort), c(xhat, yyhat), type = "n", xlab = "",
ylab = "")
lines(xsort, xhat)
lines(ysort, yyhat)
}
phat <- sum(xhat > yhat)/length(x)
zhat <- NA
if (!is.na(z[1])) {
zxhat <- 0
zyhat <- 0
zhat <- 0
if (op == 2) {
zxhat <- akerd(x, pts = z, pyhat = TRUE, plotit = FALSE)
zyhat <- akerd(y, pts = z, pyhat = TRUE, plotit = FALSE)
}
for (i in 1:length(z)) {
if (op == 1) {
zxhat[i] <- kerden(x, 0, z[i])
zyhat[i] <- kerden(y, 0, z[i])
}
zhat[i] <- 1
if (is.na(zxhat[i]) || is.na(zyhat[i])) {
arb <- runif(1)
zhat[i] <- 1
if (arb < 0.5)
zhat[i] <- 0
}
else if (zxhat[i] < zyhat[i])
zhat[i] <- 0
}
}
list(phat = phat, zhat = zhat)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.