Mínimos cuadrados con restricciones
Sí, había restricciones. No me preguntéis por qué, pero los coeficientes tenían que ser positivos y sumar uno. Es decir, buscaba la combinación convexa de cuatro vectores que más se aproximase a y en alguna métrica razonable. Y lo resolví así: # prepare constrained optimization y <- dat.clean$actual x <- t(dat.clean[,2:5]) # target function: L2 first, then other metrics L2 <- function(coef){ sum(abs((y - colSums(x * coef)))^1.5) } # restrictions: coefs > 0, sum(coefs) ~ 1 ui <- rbind(diag(4), c(-1,-1,-1,-1), c(1,1,1,1)) ci <- c(0,0,0,0,-1.000001,0.999999) theta <- rep(0.25, 4) best.coef <- constrOptim(theta, L2, grad = NULL, ui = ui, ci = ci) coefs <- best.coef$par Objetos aparte de x e y, hay: ...