1 |
x |
|
y |
|
pyhat |
|
pts |
|
np |
|
plotit |
|
eout |
|
outfun |
|
xlab |
|
ylab |
|
pch |
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 | ##---- 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, pts = NA, np = 100, plotit = TRUE,
eout = FALSE, outfun = out, xlab = "X", ylab = "Y", pch = ".")
{
m <- elimna(cbind(x, y))
if (eout) {
keep <- outfun(m, plotit = FALSE)$keep
m <- m[keep, ]
}
x <- m[, 1]
y <- m[, 2]
n <- length(x)
sig <- sqrt(var(x))
temp <- idealf(x)
iqr <- (temp$qu - temp$ql)/1.34
A <- min(c(sig, iqr))
yhat <- NA
temp <- NA
if (is.na(pts[1])) {
if (np > 0)
pts <- seq(min(x), max(x), length = np)
if (np == 0)
pts <- x
}
pts <- sort(pts)
for (i in 1:length(pts)) {
yhat[i] <- NA
for (j in 1:length(x)) {
temp[j] <- ((x[j] - pts[i])/A)^2
}
epan <- ifelse(temp < 1, 0.75 * (1 - temp), 0)
chkit <- sum(epan != 0)
if (chkit > 1) {
vals <- lsfit(x, y, wt = epan)$coef
yhat[i] <- vals[2] * pts[i] + vals[1]
}
}
if (plotit) {
plot(x, y, xlab = xlab, ylab = ylab, pch = pch)
if (np > 0) {
ilow <- round(0.1 * np)
iup <- round(0.9 * np)
}
if (np == 0) {
ilow <- 1
iup <- length(pts)
}
lines(pts[ilow:iup], yhat[ilow:iup])
}
m <- "Done"
if (pyhat)
m <- yhat
m
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.