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

quadra-methodsR Documentation

~~ Methods for Function quadra in Package momentfit ~~

Description

~~ Computes the quadratic form, where the center matrix is a class momentWeights object ~~

Usage

## S4 method for signature 'momentWeights,missing,missing'
quadra(w, x, y, genInv=FALSE)

## S4 method for signature 'momentWeights,matrixORnumeric,missing'
quadra(w, x, y,
genInv=FALSE)

## S4 method for signature 'momentWeights,matrixORnumeric,matrixORnumeric'
quadra(w, x,
y, genInv=FALSE)


## S4 method for signature 'sysMomentWeights,matrixORnumeric,matrixORnumeric'
quadra(w,
x, y)

## S4 method for signature 'sysMomentWeights,matrixORnumeric,missing'
quadra(w, x, y)

## S4 method for signature 'sysMomentWeights,missing,missing'
quadra(w, x, y)


Arguments

w

An object of class "momentWeights"

x

A matrix or numeric vector

y

A matrix or numeric vector

genInv

Should we invert the center matrix using a generalized inverse?

Value

It returns a single numeric value.

Methods

signature(w = "momentWeights", x = "matrixORnumeric", y = "matrixORnumeric")

It computes x'Wy, where W is the weighting matrix.

signature(w = "momentWeights", x = "matrixORnumeric", y = "missing")

It computes x'Wx, where W is the weighting matrix.

signature(w = "momentWeights", x = "missing", y = "missing")

It computes W, where W is the weighting matrix. When W is the inverse of the covariance matrix of the moment conditions, it is saved as either a QR decompisition, a Cholesky decomposition or a covariance matrix into the momentWeights object. The quadra method with no y and x is therefore a way to invert it. The same applies to system of equations

References

Courrieu P (2005), Fast Computation of Moore-Penrose Inverse Matrices. Neural Information Processing - Letters and Reviews, 8(2), 25–29.

Examples

data(simData)

theta <- c(beta0=1,beta1=2)
model1 <- momentModel(y~x1, ~z1+z2, data=simData)

gbar <- evalMoment(model1, theta)
gbar <- colMeans(gbar)

### Objective function of GMM with identity matrix
wObj <- evalWeights(model1, w="ident")
quadra(wObj, gbar)

### Objective function of GMM with efficient weights
wObj <- evalWeights(model1, theta)
quadra(wObj, gbar)

### Linearly dependent instruments

simData$z3 <- simData$z1+simData$z2
model2 <- momentModel(y~x1, ~z1+z2+z3, data=simData)
gbar2 <- evalMoment(model2, theta)
gbar2 <- colMeans(gbar2)

## A warning is printed about the singularity of the weighting matrix
wObj <- evalWeights(model2, theta)

## The regular inverse using the QR decomposition:
quadra(wObj)

## The regular inverse using the generalized inverse:
quadra(wObj, genInv=TRUE)



momentfit documentation built on Aug. 27, 2025, 1:09 a.m.