我的方法如下:
library("dplyr")
library("MESS")
library("rgl")
#For a three framed vector
df <- data.frame(ID = LETTERS[1:3],
X = seq(0.1,0.3, by = 0.1),
Y = seq(0.4,0.6, by = 0.1),
Z = seq(0.7,0.9, by = 0.1))
Abs <- data.frame(ID = LETTERS[1:3],
Abs = c(1,0,1))
#3 vector alpha prep
alpham <- data.frame(row = 1:3,
Alpha1 = seq(0.1,0.3,by = 0.1))
alpham2 <- alpham %>%
slice(rep(1:n(), each = nrow(alpham))) %>%
group_by(row) %>%
mutate(Alpha2 = seq(0.1,0.3,by = 0.1)) %>%
mutate(Alpha3 = 1 - (Alpha1+Alpha2)) %>%
filter(if_any(Alpha3,~ . >0))
alpham2$row <- seq_len(nrow(alpham2))
#This is where the fun begins - Determining AUCs
result1 <- df %>%
slice(rep(1:n(), each = nrow(alpham2))) %>%
group_by(ID) %>%
mutate(row = 1:n()) %>%
left_join(.,alpham2,by = "row") %>%
mutate(P = (X^alpham2$Alpha1 * Y^alpham2$Alpha2 * Z^alpham2$Alpha3)) %>%
left_join(., Abs, by = "ID") %>%
select(-row) %>%
#This is to create AUC by each XY pair
group_by(Alpha1,Alpha2) %>%
summarize(AUC = auc(P,Abs,type = "linear"), .groups="keep")
#Finding best alpha combination
maxalpha <- which(result1$AUC == max(result1$AUC))
maxalpha <- result1[maxalpha,]
#plotting
plot3d(result1$Alpha1,result1$AUC,result1$Alpha2)