Allan Sikk
2012-Apr-16 22:02 UTC
[R] Simultaneous OLS fitting with constraints on coeffcients
Hi, Is it possible in R to fit two equations simultaneously: y1 = a1 - b1*t and y2 = a2 - b2*t so that the following constraint applies: a1/b1 = a2/b2 ? Thanks
Gabor Grothendieck
2012-Apr-16 22:54 UTC
[R] Simultaneous OLS fitting with constraints on coeffcients
On Mon, Apr 16, 2012 at 6:02 PM, Allan Sikk <a.sikk at ucl.ac.uk> wrote:> Hi, > > Is it possible in R to fit two equations simultaneously: > > y1 = a1 - b1*t ? and > y2 = a2 - b2*t > > so that the following constraint applies: a1/b1 = a2/b2 ? >Try this: set.seed(123) # simulated data a2 <- 2; b1 <- 3; b2 <- 4; a1 <- b1 * a2/b2 y <- rnorm( 100, c(a1 - b1 * seq(50), a1 - b2 * seq(50)) ) # fit it g <- gl(2, 50) sq <- c(seq(50), seq(50)) lm(y ~ g / sq + 0) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com