I'm trying to do a linear regression in R, however I have the added constraint the coefficients from the linear regression need to sum to a user given value between 0 and 1. (I understand forcing the coefficients like this will make the fit rather poor, but it's a needed constraint)
I've been though the documentation for lm() and the glmc package, as well as some similar questions, but none seem to tackle how to get the coefficients to sum to a specific value.
For data T, N, and target sum for coefficients p:
Regression <- function(T, N, p) {
fit <- lm(T[,1] ~ N)
coef <- coef(fit)
...
}
Ideally I want sum(coef[-1]) = p (ignoring the intercept)
Sorry I can't provide more code, but I don't think I can do what I would like with lm().
Does anyone know of a way to do this, or of a package that will let me do this?