Linear regression with non-linear constrained coefficients I have a simple 3-factor linear model: $y = a_1x_1 + a_2x_2 + a_3x_3$, and I want the coefficients to satisfy $a_3 = a_1 \times a_2$. How should I code it in R?
 A: Instead of thinking of it as a linear regression subject to a non-linear constraint, you can get a solution by non-linear least squares (nls() in R):
N <- 1000
x1 <- rnorm(N)
x2 <- rnorm(N)
x3 <- rnorm(N)

a1 = 2
a2 = 3

y <- a1*x1 + a2*x2 + a1*a2*x3 + rnorm(N)

nls(y ~ -1 + a1*x1 + a2*x2 + a1*a2*x3, start = list(a1 = 0, a2 = 0), trace = T)

50722.64 :  0 0
2064.18 :  2.145276 2.859526
1995.486 :  2.002083 2.960784
1995.284 :  2.004799 2.963501
Nonlinear regression model
model: y ~ -1 + a1 * x1 + a2 * x2 + a1 * a2 * x3
data: parent.frame()
 a1    a2 
2.005 2.964 
residual sum-of-squares: 1995

Number of iterations to convergence: 3 
Achieved convergence tolerance: 7.22e-06

A: In principle, I believe you can do this using lavaan (short for "latent variable analysis"), which can fit general linear models with nonlinear equality constraints (see page 32 of this PDF, "lavaan: An R package for structural equation modeling."). However, I haven't yet been able to get it to work on simulated data without encountering a non-positive definite matrix error. Anyway, the code would look something like this:
y=~a*x+b*w+c*z
c==a*b

