Description Usage Arguments Value Examples
A KDE method for one dim
1 | rodeo.local1(t, x)
|
t |
target points, a vector |
x |
data points, vector |
a vector of estimated f(x)
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 | ## Not run:
set.seed(111)
n <- 200
Num.Cmp <- 8
pro <- rep(1/8, Num.Cmp)
multi <- sample(1:Num.Cmp, n, replace = T, prob=pro)
mu <- 3 * ((2/3)^(1:Num.Cmp) - 1)
sigma <- (2/3)^(1:Num.Cmp)
x <- NULL
for (ii in 1:Num.Cmp) {
com_txt <- paste("com", ii, " <- rnorm(length(which(multi==", ii, ")),
mean=", mu[ii], ", sd=", sigma[ii], ")",sep="")
eval(parse(text=com_txt))
com_txt <- paste("x <- c(x, com", ii, ")", sep="")
eval(parse(text=com_txt))
}
# true density function, y is h, and z is v.
y <- seq(-3, 1, 0.01)
z <- rep(0, length(y))
for (ii in 1:Num.Cmp) {
z <- z + pro[ii] * dnorm(y, mean=mu[ii], sd=sigma[ii])
}
t <- seq(-3, 1, 0.05)
h <- unlist(base::lapply(X=t, FUN=rodeo.local.bw1, x=x))
t <- seq(-3, 1, 0.05)
h <- unlist(base::lapply(X=t, FUN=rodeo.local.bw1, x=x))
fit.rodeo <- rodeo.local1(t=t, x=x)
plot(t, fit.rodeo, "l", lty=2, ylim=c(0,2.5), xlim=c(-3, 1), main="Rodeo", xlab="x", ylab="Density")
lines(y, z, lty=1, lwd=2)
legend("topright", legend=c("True Density", "Rodeo"), col=1, lty=c(1, 2), lwd=c(2, 1))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.