restModel-methods: ~~ Methods for Function 'restModel' in Package 'momentfit' ~~

restModel-methodsR Documentation

~~ Methods for Function restModel in Package momentfit ~~

Description

It converts momentModel objects into its restricted counterpart.

Usage

## S4 method for signature 'linearModel'
restModel(object, R, rhs=NULL)

## S4 method for signature 'slinearModel'
restModel(object, R, rhs=NULL)

## S4 method for signature 'snonlinearModel'
restModel(object, R, rhs=NULL)

## S4 method for signature 'nonlinearModel'
restModel(object, R, rhs=NULL)

## S4 method for signature 'formulaModel'
restModel(object, R, rhs=NULL)

## S4 method for signature 'functionModel'
restModel(object, R, rhs=NULL)

Arguments

object

An object of class "momentModel" or "sysModel".

R

Either a matrix or a vector of characters for linear models and a list of formulas for nonlinear models

rhs

The right hand side of the linear restrictions. It is ignored for nonlinear models.

Methods

signature(object = "linearModel")

Method for object of class linearModel.

signature(object = "linearGel")

Method for all classes related to linearGel.

signature(object = "slinearModel")

Method for object of class slinearModel.

signature(object = "snonlinearModel")

Method for object of class snonlinearModel.

signature(object = "nonlinearModel")

Method for object of class nonlinearModel.

signature(object = "nonlinearGel")

Method for object of class nonlinearGel.

signature(object = "functionModel")

Method for object of class functionModel.

signature(object = "functionGel")

Method for object of class functionGel.

signature(object = "formulaModel")

Method for object of class formulaModel.

signature(object = "formulaGel")

Method for object of class formulaGel.

Examples

data(simData)
theta <- c(beta0=1,beta1=2)

## Unrestricted model
model1 <- momentModel(y~x1+x2+x3+z1, ~x1+x2+z1+z2+z3+z4, data=simData)

## Using matrix R
R <- matrix(c(1,1,0,0,0,0,0,2,0,0,0,0,0,1,-1),3,5, byrow=TRUE)
q <- c(0,1,3)

rmodel1 <- restModel(model1, R, q)
rmodel1

## Using character
## Many ways to write the constraints

R1 <- c("x1","2*x2+z1=2", "4+x3*5=3")
rmodel1 <- restModel(model1, R1)
rmodel1

## Works with interaction and identity function I()

model1 <- momentModel(y~x1*x2+exp(x3)+I(z1^2), ~x1+x2+z1+z2+z3+z4, data=simData)
R1 <- c("x1","exp(x3)+2*x1:x2", "I(z1^2)=3")
rmodel1 <- restModel(model1, R1)
rmodel1

## nonlinear constraints on a linear model
## we need to convert the linear model into a nonlinear one

model <- momentModel(y~x1+x2+x3+z1, ~x1+x2+z1+z2+z3+z4, data=simData)
NLmodel <- as(model, "nonlinearModel")

## To avoid having unconventional parameter names, which happens
## when I() is used or with interaction, the X's and coefficients are
## renamed

NLmodel@parNames

## Restriction can be a list of formula or vector of characters
## For the latter, it will be converted into a list of formulas

R1 <- c("theta2=2", "theta3=theta4^2")
rmod1 <- restModel(NLmodel, R1)
res1 <- gmmFit(rmod1)
res1
## recover the orignial form
coef(rmod1, coef(res1))

## with formulas

R2 <- list(theta2~2, theta3~1/theta4)
rmod2 <- restModel(NLmodel, R2)
res2 <- gmmFit(rmod2)
res2
coef(rmod2, coef(res2))

## The same can be done with function based models


momentfit documentation built on Sept. 20, 2023, 3:01 a.m.