Hello Jan,
On Apr 26, 2010, at 8:56 AM, Jan van der Laan wrote:
> You can use the '...' for that, as in:
>
> loocv <- function(data, fnc, ...) {
> n <- length(data.x)
> score <- 0
> for (i in 1:n) {
> x_i <- data.x[-i]
> y_i <- data.y[-i]
> yhat <- fnc(x=x_i,y=y_i, ...)
> score <- score +
Giovanni,
You can use the '...' for that, as in:
loocv <- function(data, fnc, ...) {
n <- length(data.x)
score <- 0
for (i in 1:n) {
x_i <- data.x[-i]
y_i <- data.y[-i]
yhat <- fnc(x=x_i,y=y_i, ...)
score <- score + (y_i - yhat)^2
}
score <- score/n
return(score)
}
scoreks <- l
The beauty of trial and error ... if I leave the non x, y parameters i.e. h as
global parameters rather than formal parameters for gaussiankernel it works
fine basically I don't pass anymore h=0.5 to gaussiankernel but consume it from
a global variable. Ugly but works ...
Best regards,
Giovanni
Hello,
I have the following function that receives a "function pointer" formal
parameter name "fnc":
loocv <- function(data, fnc) {
n <- length(data.x)
score <- 0
for (i in 1:n) {
x_i <- data.x[-i]
y_i <- data.y[-i]
yhat <- fnc(x=x_i,y=y_i)
score <- score + (y_i - yhat)^2
4 matches
Mail list logo