setCoef-methods {momentfit}R Documentation

Methods for Function setCoef in Package momentfit ~~

Description

The method validates the coefficient theta and returns a coefficient object in a format that satisfies the moment model.

Usage

## S4 method for signature 'momentModel'
setCoef(model, theta)
## S4 method for signature 'sysModel'
setCoef(model, theta)

Arguments

model

A moment model object.

theta

A coefficient object. The type depends on the model object. See the examples below.

Methods

signature(object = "momentModel")

Methods for all single equation models including the restricted ones.

signature(object = "sysModel")

Methods for all system of equations models including the restricted ones.

Examples

### A few system of equation models:
data(simData)
h <- list(~z1+z2+z3, ~x3+z1+z2+z3+z4, ~x3+x4+z1+z2+z3)
nlg <- list(Supply=y1~theta0+theta1*x1+theta2*z2,
            Demand1=y2~alpha0+alpha1*x1+alpha2*x2+alpha3*x3,
            Demand2=y3~beta0+beta1*x3+beta2*x4+beta3*z1)
g <- list(Supply=y1~x1+z2, Demand1=y2~x1+x2+x3, Demand2=y3~x3+x4+z1)
theta0 <- list(c(theta0=1,theta1=2,theta2=3),
               c(alpha0=1,alpha1=2,alpha2=3, alpha3=4),
               c(beta0=1,beta1=2,beta2=3,beta3=4))
nlin <- sysMomentModel(nlg, h, theta0, data=simData)
lin <- sysMomentModel(g, h, data=simData)

### from numeric vector to the proper format with names:
setCoef(nlin, 1:11)

### reorder the equation and name the coefficients
setCoef(nlin, list(Demand1=1:4, Supply=1:3, Demand2=1:4))

### reorder the coefficint to match the order in the model
tet <- do.call("c", theta0)
set.seed(112233)
setCoef(nlin, tet[sample(11)])

### It validates length and names and provide source of errors
## Not run: 
setCoef(nlin, list(Demand1=1:4, Supply=1:2, Demand2=1:4))
names(tet)[4] <- "gamma3"
setCoef(nlin, tet)
setCoef(nlin, list(Demand1=1:4, Supply=1:3, Demand4=1:4))

## End(Not run)

### a single equation model
single <- momentModel(nlg[[1]], h[[1]], theta0[[1]], data=simData)
setCoef(single, c(theta1=4, theta0=6, theta2=8))
setCoef(single, 1:3)

[Package momentfit version 0.5 Index]