R/alfa.knn.reg.R

Defines functions alfa.knn.reg

Documented in alfa.knn.reg

## Predictors are compositional data
alfa.knn.reg <- function(xnew, y, x, a = 1, k = 2:10, apostasi = "euclidean", method = "average") {
  nu <- dim(xnew)[1]
  
  if ( !is.null(a) ) {
    znew <- Compositional::alfa(xnew, a, h = FALSE)$aff
    z <- Compositional::alfa(x, a, h = FALSE)$aff
  } else {
    znew <- xnew
    z <- x
  }
  
  g <- Rfast::knn(xnew = znew, y = y, x = z, k = k, dist.type = apostasi, type = "R", method = method)
  colnames(g) <- paste("k=", k, sep = "")
  g
}

Try the Compositional package in your browser

Any scripts or data that you put into this service are public.

Compositional documentation built on Oct. 23, 2023, 5:09 p.m.