0

I have a vector epsilon of length N. I am applying the function bw.CDF.pi(x, pilot="UCV") from the sROC package to compute bandwidths for cdf Kernel estimation.

My goal is to repeat this bandwidth function for every subvector from epsilon from the beginning value on. Stated otherwise, I would like to apply this function for the first value in epsilon, then for the first two values in epsilon, then for the first three values in epsilon, continiuing until the function is applied fot the total vector epsilon. Finally i want to have then N values for the bandwidth.

How can I accomplish this?

Caleb
  • 124,013
  • 19
  • 183
  • 272
krehal
  • 1
  • 2
  • Hi! Have a look here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Your question needs to have reproducible data as well as an expected output. – User2321 Jul 07 '17 at 13:57

1 Answers1

0

Apparently you need a vector of 2 elements for the function bw.CDF.pi to run. If you want to run it for the first 2 elemts of a vector, then the first 3, etc, you can do the following. Note that the data example is the one in the help page for the function.

library(sROC)

set.seed(100)
n <- 200
x <- c(rnorm(n/2, mean=-2, sd=1), rnorm(n/2, mean=3, sd=0.8))

lapply(seq_along(x)[-1], function(m) bw.CDF.pi(x[seq_len(m)], pilot="UCV"))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66