1 |
xx |
|
hval |
|
aval |
|
op |
|
fr |
|
pyhat |
|
pts |
|
plotit |
|
xlab |
|
ylab |
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 | ##---- 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 (xx, hval = NA, aval = 0.5, op = 1, fr = 0.8, pyhat = TRUE,
pts = 0, plotit = FALSE, xlab = "", ylab = "")
{
fval <- "Done"
if (is.matrix(xx)) {
if (ncol(xx) > 1)
fval <- akerdmul(xx, pts = pts, hval = hval, aval = aval,
fr = fr, pr = pyhat, plotit = plotit)
plotit <- F
}
if (is.matrix(xx) && ncol(xx) == 1)
xx <- xx[, 1]
if (!is.matrix(xx)) {
x <- sort(xx)
if (op == 1) {
m <- mad(x)
if (m == 0) {
temp <- idealf(x)
m <- (temp$qu - temp$ql)/(qnorm(0.75) - qnorm(0.25))
}
if (m == 0)
m <- sqrt(winvar(x)/0.4129)
if (m == 0)
stop("All measures of dispersion are equal to 0")
fhat <- rdplot(x, pyhat = TRUE, plotit = FALSE, fr = fr)
if (m > 0)
fhat <- fhat/(2 * fr * m)
}
if (op == 2) {
init <- density(xx)
fhat <- init$y
x <- init$x
}
n <- length(x)
if (is.na(hval)) {
sig <- sqrt(var(x))
temp <- idealf(x)
iqr <- (temp$qu - temp$ql)/1.34
A <- min(c(sig, iqr))
if (A == 0)
A <- sqrt(winvar(x))/0.64
hval <- 1.06 * A/length(x)^(0.2)
}
gm <- exp(mean(log(fhat[fhat > 0])))
alam <- (fhat/gm)^(0 - aval)
dhat <- NA
if (is.na(pts[1]))
pts <- x
pts <- sort(pts)
for (j in 1:length(pts)) {
temp <- (pts[j] - x)/(hval * alam)
sq5 = 0 - sqrt(5)
epan = 0.75 * (temp - 0.2 * temp^3/3)/sqrt(5) - 0.75 *
(sq5 - 0.2 * sq5^3/3)/sqrt(5)
flag = (temp >= sqrt(5))
epan[flag] = 1
flag = (temp < sq5)
epan[flag] = 0
dhat[j] <- mean(epan)
}
if (plotit) {
plot(pts, dhat, type = "n", ylab = ylab, xlab = xlab)
lines(pts, dhat)
}
if (pyhat)
fval <- dhat
}
fval
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.