[R] Constraining parameters using tag() in SUR model - ZELIG
Arne Henningsen
arne.henningsen at gmail.com
Thu Sep 13 22:38:03 CEST 2012
On 13 September 2012 18:38, Samantha Azzarello
<samantha.azzarello at cmegroup.com> wrote:
> Thanks for the help. Ill make sure to cite systemfit along with Zelig.
:-)
> I cannot see how to constrain parameters based on the manual when there is
> more than 2 eqs using the M Matrix.
> I have 10 eqns with 6 parameters each and need to constrain all 6 across the
> 10 equations.
> For example B1s need to be equal in all 10 eqns, B2 need to be equal in all
> 10 eqs stc.
> Can you assist in a brief example?
A simple example with three equation and two parameters in each equation:
eq1: y1 = a0 + a1 * x1
eq2: y2 = b0 + b1 * x1
eq3: y3 = c0 + c1 * x1
with restrictions
a0 = b0 = c0
and
a1 = b1 = c1
In fact, you have 4 restrictions (number of equality signs):
a0 = b0
b0 = c0
a1 = b1
b1 = c1
Given that you have 4 restrictions and 6 parameters, argument
restriction.matrix should be:
m <- matrix( 0, nrow = 4, ncol = 6 )
# a0 - b0 = 0
m[ 1, 1 ] <- 1
m[ 1, 3 ] <- -1
# b0 - c0 = 0
m[ 2, 3 ] <- 1
m[ 2, 5 ] <- -1
# a1 - b1 = 0
m[ 3, 2 ] <- 1
m[ 3, 4 ] <- -1
# b1 - c1 = 0
m[ 4, 4 ] <- 1
m[ 4, 6 ] <- -1
Of course, the above restrictions are identical to:
a0 = b0
a0 = c0
a1 = b1
a1 = c1
m <- matrix( 0, nrow = 4, ncol = 6 )
# a0 - b0 = 0
m[ 1, 1 ] <- 1
m[ 1, 3 ] <- -1
# a0 - c0 = 0
m[ 2, 1 ] <- 1
m[ 2, 5 ] <- -1
# a1 - b1 = 0
m[ 3, 2 ] <- 1
m[ 3, 4 ] <- -1
# a1 - c1 = 0
m[ 4, 2 ] <- 1
m[ 4, 6 ] <- -1
Alternatively, you can specify the restrictions symbolically using
argument restrict.matrix:
m <- c( "eq1_(Intercept) - eq2_(Intercept) = 0",
"eq2_(Intercept) - eq3_(Intercept) = 0",
"eq1_x1 - eq2_x1 = 0", "eq2_x1 - eq3_x2 = 0" )
Finally, you might use argument restrict.regMat. As you have 6
unconstrained parameters (a0,a1,b0,b1,c0,c1) and two constrained
parameters (r0,r1), argument restrict.regMat should be:
m <- matrix( 0, nrow = 6, ncol = 2 )
m[1,1] <- 1 # r0 = a0
m[3,1] <- 1 # r0 = b0
m[5,1] <- 1 # r0 = c0
m[2,2] <- 1 # r1 = a1
m[4,2] <- 1 # r1 = b1
m[6,2] <- 1 # r1 = c1
All approaches are mathematically equivalent but the latter approach
(using argument restrict.regMat) is computationally/numerically
preferable.
ATTENTION: all of the code above is untested!
> I am using this in conjunction with a few Perl porgrams already written -
> but
> I am open to switching everything I have directly to systemfit if I can get
> teh parameters constrained
OK.
/Arne
--
Arne Henningsen
http://www.arne-henningsen.name
More information about the R-help
mailing list