Skip to content

Constraining parameters using tag() in SUR model - ZELIG

4 messages · Samantha Azzarello, Arne Henningsen

#
Hello all,
I am following some standard code from Zelig manual when using a SUR
(Seemingly Unrelated Regression Model) to constrain parameters across
equations.
Please see code below:

setwd("C:/Research/Economics/SUR_FX/Model")

# Seemingly Unrelated Regression
# Load our library.

library(Zelig)
library(systemfit)
library(zoo)

# data.

factors <- read.table("./RFactors.txt", header = TRUE)
returns <- read.table("./RReturns.txt", header = TRUE)

myData <- c(factors,returns)

# This is our system of equations.

mySys <- list(mu1  = USDEUR ~ USDRATE + tag(USDYC, "USDYC")+ USDCC + EURRATE
+ EURYC + EURLY, 
	mu2  = USDGBP ~ USDRATE + tag(USDYC, "USDYC") + USDCC + GBPRATE + GBPYC +
GBPLY,
	mu3  = USDCHF ~ USDRATE + tag(USDYC, "USDYC") + USDCC + CHFRATE + CHFYC +
CHFLY,
	mu4  = USDSEK ~ USDRATE + tag(USDYC, "USDYC") + USDCC + SEKRATE + SEKYC +
SEKLY,
	mu5  = USDNOK ~ USDRATE + tag(USDYC, "USDYC") + USDCC + NOKRATE + NOKYC +
NOKLY,
	mu6  = USDJPY ~ USDRATE + tag(USDYC, "USDYC") + USDCC + JPYRATE + JPYYC +
JPYLY,
	mu7  = USDSGD ~ USDRATE + tag(USDYC, "USDYC") + USDCC + SGDRATE + SGDYC +
SGDLY,
	mu8  = USDAUD ~ USDRATE + tag(USDYC, "USDYC") + USDCC + AUDRATE + AUDYC +
AUDLY,
	mu9  = USDCAD ~ USDRATE + tag(USDYC, "USDYC") + USDCC + CADRATE + CADYC +
CADLY,
	mu10 = USDNZD ~ USDRATE + tag(USDYC, "USDYC") + USDCC + NZDRATE + NZDYC +
NZDLY)

# Here is our zelig function call.

z.out <- zelig(mySys,"sur", myData)

------ After this I am getting error:
Error in eval(expr, envir, enclos) : could not find function "tag"

there exists no info  (I could find anyways..) RE installing tag() seperate,
also tag should be able to be used for the SUR model...
Any help would be appreciated.
Thanks



--
View this message in context: http://r.789695.n4.nabble.com/Constraining-parameters-using-tag-in-SUR-model-ZELIG-tp4642927.html
Sent from the R help mailing list archive at Nabble.com.
#
Dear Samantha

I suggest that you directly use the systemfit() command rather than
the wrapper function zelig(). You can impose parameter restrictions
with the arguments "restrict.matrix", "restrict.rhs", and
"restrict.regMat". You can use argument "restrict.matrix" to specify
the restrictions numerically (as a matrix) or symbolically (with
character strings). The (symbolical and numerical) imposition of
parameter restrictions is described in [1], page 18-19 and in the
documentation of systemfit() (with examples in the "Example" section).

Please do not forget to cite systemfit in your publications--no matter
whether you directly use it or through zelig(). Thanks!

[1] http://www.jstatsoft.org/v23/i04/paper

/Arne


On 12 September 2012 20:05, Samantha Azzarello
<samantha.azzarello at cmegroup.com> wrote:

  
    
#
Arne,
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? 

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

Thank you



--
View this message in context: http://r.789695.n4.nabble.com/Constraining-parameters-using-tag-in-SUR-model-ZELIG-tp4642927p4643037.html
Sent from the R help mailing list archive at Nabble.com.
#
On 13 September 2012 18:38, Samantha Azzarello
<samantha.azzarello at cmegroup.com> wrote:
:-)
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!
OK.

/Arne