[R] regression problem
Patrick Burns
pburns at pburns.seanet.com
Fri Mar 26 17:23:19 CET 2004
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
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
pnick at virgilio.it wrote:
>i need to know how to estimate a linear regression whose coefficients sum
>to zero
>
>______________________________________________
>R-help at stat.math.ethz.ch 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
>
>
>
>
More information about the R-help
mailing list