bw.fun <- function (x, nb = 1000,lower=0,upper=0){
n <- length(x)
hmax <- 1.144 * sqrt(var(x)) * n^(-1/5)
if(upper==0)upper <- hmax;
if(lower==0)lower <- 0.1*hmax
fucv <- function(h, x, n, d) .C("band_ucv_bin", as.integer(n),
as.integer(length(x)), as.double(d), x, as.double(h),
u = double(1), PACKAGE = "base")$u
if (!is.numeric(x) || !length(x)) stop("invalid x")
storage.mode(x) <- "double"
Z <- .C("band_den_bin", as.integer(n), as.integer(nb), d = double(1),
x, cnt = integer(nb), PACKAGE = "base")
d <- Z$d
cnt <- as.integer(Z$cnt)
h <- optimize(fucv, c(lower, upper), tol = 0.1 * lower, x = cnt,
n = n, d = d)$minimum
if (h < 1.1 * lower | h > upper - 0.1 * lower)
warning("minimum occurred at one end of the range")
h.vec <- seq(lower, upper, length=200)
u.vec <- rep(NA, 200)
for(i in 1:200) u.vec <- fucv(h.vec, x=cnt, n, d)
list(h.optimal=h, bandwidths=h.vec, risk=u.vec)
}
x=c(1,2,3,4,5,6,7,8,9)
library(MASS)
temp <- bw.fun(x)
错误在于:程序包"base"里"band_den_bin"不适用于.C()
请教各位老师这个问题怎么解决啊。