AtoB {lazy.mat} R Documentation

## Linear Constraints Matrices: form A to form B conversion

### Description

Linear Constraints Matrices: form A to form B conversion

### Usage

```AtoB(A, d, E = 0, g = 0, eps = 1e-09, useginv = 1, useeigen = 1,
print = 0)
```

### Arguments

 `A` Form A constraints matrix A. `d` Form A constraints vector d. `E` Additional Form A constraints matrix E or 0. `g` Additional Form A constraints vector g or 0. `eps` eps for zero. `useginv` = 0 to use matSwp function instead of ginv in MASS. `useeigen` = 0 to use QRGS with orth=0. `print` = 1 to print result

### Details

This function converts a form A liner constraints of the form
beta = A %*% gamma + d, where E %*% gamma = g,
to form B linear constraints of the form
B %*% beta = c.

Although form B constraints are intuitive, it is difficult to enforce.
For example, in linear regression, the constrained solution of beta is:
betahat- invtXX%*%t(B)%*%solve(B%*%invtXX%*%t(B))%*%(B%*%betahat-c)
where betahat=invtXX%*%t(X)%*%y is the OLS and invtXX=solve(t(X)%*%X).
However, if you use equivalent form A constraints, the model becomes
y = X %*% (A %*% gamma + d)
and the solution becomes
solve(t(X%*%A)%*%X%*%A)%*%t(X%*%A)%*%(y-X%*%d) .

Of course, the use is not restricted to linear models.

### Value

A list of B and c.

### References

Mayekawa, Shin-ichi. (1996) Maximum likelihood estimation of the cell probabilities under linear constraints. Behaviormetrika, Vol.23, No.1, 111-128
Takane, Yoshio, Yanai, Haruo, and Mayekawa, Shin-ichi. (1991) Relationships among several methods of linearly constrained correspondence analysis. Psychometrika, Vol. 56, 667-684.

### Examples

```B <- c(1,1,1); c <- 1
Ad <- BtoA( B, c )

# generate multiple regression data
set.seed(1701)
n <- 50; np=3
X <- cbind(1,matrix(rnorm(n*3),n,3))
beta <- c(-5, 1, 1.5, 1)
y <- X%*%beta + rnorm(n)

# OLS of beta
invtXX <- solve(t(X)%*%X)
betahat <- invtXX%*%t(X)%*%y

# Form B Constraints indicating that three slopes are equal:  B%*%beta=c
B <- matrix(c(0, 1,-1,0,  0, 1,0,-1),2,4, byrow=1)
c <- c(0,0)

# Constrained LS using (B,c)
betaBc <- betahat-invtXX%*%t(B)%*%solve(B%*%invtXX%*%t(B))%*%(B%*%betahat-c)

# Form B Constraints indicating that three slopes are equal.
Ad <- BtoA( B, c )

# Constrained LS using (A,d)
gamma <- solve(t(X%*%A)%*%X%*%A)%*%t(X%*%A)%*%(y-X%*%d)