Consider a regression equation say:-
Y=a+b1*X1+b2*X2+b3*X3
if all the regression coefficients have to sum to 0
then
a+b1+b2+b3=0
i.e.
b3=-a-b1-b2
Substituting this back into the regression equation we get
Y=a(1-X3)+b1(X1-X3)+b2(X2-X3)
All you need to do then is to create the new input variables say
Z1=1-X3, Z2=X1-X3, Z3=X2-X3
so that
Y=a*Z1+b1*Z2+b*Z3
You can parameterise a,b1 and b2 directly by fitting a linear model with no
intercept term
you can then calculate b3 from b3=-a-b1-b2
This example will generalize to an arbitrary number of parameters..
Regards
Wayne
-----Original Message-----
From: Patrick Burns [mailto:pburns@pburns.seanet.com]
Sent: 26 March 2004 16:23
To: pnick@virgilio.it; 'r-help@stat.math.ethz.ch'
Subject: Re: [R] regression problem
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@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@virgilio.it wrote:
>i need to know how to estimate a linear regression whose coefficients sum
>to zero
>
>______________________________________________
>R-help@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>
>
>
>
______________________________________________
R-help@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
KSS Ltd
Seventh Floor St James's Buildings 79 Oxford Street Manchester M1 6SS
England
Company Registration Number 2800886
Tel: +44 (0) 161 228 0040 Fax: +44 (0) 161 236 6305
mailto:kssg@kssg.com http://www.kssg.com
The information in this Internet email is confidential and m...{{dropped}}