[R-sig-Geo] Constraining a linear regression model
Jean-Paul Kibambe Lubamba
jean-paul.kibambe at uclouvain.be
Fri May 22 15:15:53 CEST 2009
I have two questions:
I am computing a linear regression model with 0 as Intercept.
Well, I would like the sum of my predicted values be equal to a constant
and therefore analyze if my coefficients are significatively different
using or not this constraint.
Does anyone know how I can constrain my model in a such way?
Here is the code:
data<-read.table ("input.txt", header=T, dec=".", sep="\t"); attach(data)
lm <-lm(pop ~ ag + sav + mf -1, data=data)
pred <- predict(lm)
So I want to constrain my sum (pred) to be equal to C, with C=sum(pop)
My second question is: is it possible to make the same constraint BUT with
C as a vector of values?
If I have 5 observations in 'data' (for simplification reasons), with
'pop' as the first column. I want to compute the same model as above with
a 'vector' of constraints. In that case, C=xi (with i from 1 to 3)
x1 = sum (data[c(2:4), 1])
x2 = sum(data [c(1,3), 1])
x3 = data[5,1]
Thanks in advance -- Any help is welcome!
More information about the R-sig-Geo