ui = rbind(c(1,1,1,1,1,1), c(-1,-1,-1,-1,-1,-1))
ci = c(0.999, -1.001)
init = c(1,0,0,0,0,0)
parameters <- constrOptim(theta=init,optimize_ranks,grad=NULL,data,ui = ui,hessian=FALSE,method=if(is.null(grad))"Nelder-Mead" else "BFGS",ci = ci,init=init)
optimize_ranks <- function(data,init)
{
data$variance <- init[1]*((data$vs.rank - data$mew)^2) + init[2]*((data$gbu.rank - data$mew)^2) + init[3]*((data$vr.rank - data$mew)^2) + init[4]*((data$vre.rank - data$mew)^2) + init[5]*((data$vss.rank - data$mew)^2) + init[6]*((data$gbs.rank - data$mew)^2)
weighted_variance <- sum(data$variance)
#print(weighted_variance)
return(weighted_variance)
}
数据框数据肯定包含所有这些列。我收到了这个错误:
Error in data$vs.rank : $ operator is invalid for atomic vectors