Skip to content

Commit

Permalink
make LPD work for single variable cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaMeyer committed May 30, 2024
1 parent 6d43b3e commit 99a12b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/aoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ aoa <- function(newdata,
}
newdata <- terra::as.data.frame(newdata,na.rm=FALSE)
}
newdata <- newdata[,na.omit(match(trainDI$variables, names(newdata)))]
newdata <- newdata[,na.omit(match(trainDI$variables, names(newdata))),drop = FALSE]


## Handling of categorical predictors:
Expand Down Expand Up @@ -270,9 +270,11 @@ aoa <- function(newdata,
scale=trainDI$scaleparam$`scaled:scale`)

if(!inherits(trainDI$weight, "error")){
tmpnames <- names(newdata)#!!!!!
newdata <- sapply(1:ncol(newdata),function(x){
newdata[,x]*unlist(trainDI$weight[x])
})
names(newdata)<-tmpnames#!!!!
}


Expand All @@ -287,7 +289,7 @@ aoa <- function(newdata,
# Distance Calculation ---------
okrows <- which(apply(newdata, 1, function(x)
all(!is.na(x))))
newdataCC <- newdata[okrows, ]
newdataCC <- newdata[okrows, ,drop=F]

if (method == "MD") {
if (dim(train_scaled)[2] == 1) {
Expand Down Expand Up @@ -463,7 +465,7 @@ aoa <- function(newdata,
# Euclidean Distance
return(FNN::knnx.index(reference, point, k = maxLPD))
} else if (method == "MD") {
# hier muss noch was hin
stop("MD currently not implemented for LPD")
}
}

0 comments on commit 99a12b5

Please sign in to comment.