Assuming that you want to estimate via least squares, you can
do something like this:

reg.coefsum <- function(x, y, start=coef(lm.fit(x, y)), coefsum=0, penalty=1000) {
subfun.objective <- function(coef){
sum((y - x %*% coef)^2) + abs(sum(coef)) * penalty
}
opt <- optim(start, subfun.objective, method='BFGS')
ans <- list(coefficients=opt$par)
ans
}


You can enhance the return value and make other improvements,
like check that the coefficient sum is accurate enough for you.

Patrick Burns

Burns Statistics
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

[EMAIL PROTECTED] wrote:

i need to know how to estimate a linear regression whose coefficients sum
to zero

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html





______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to