AtoB {lazy.mat}R Documentation

Linear Constraints Matrices: form A to form B conversion


Linear Constraints Matrices: form A to form B conversion


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



Form A constraints matrix A.


Form A constraints vector d.


Additional Form A constraints matrix E or 0.


Additional Form A constraints vector g or 0.


eps for zero.


= 0 to use matSwp function instead of ginv in MASS.


= 0 to use QRGS with orth=0.


= 1 to print result


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.


A list of B and c.


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.


B <- c(1,1,1); c <- 1
Ad <- BtoA( B, c )
AtoB( Ad$A, Ad$d )

# generate multiple regression data
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 )
A <- Ad$A; d=Ad$d

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

Print(beta,betahat,betaBc, betaAd)

# Go back to form B constraint from (A,d) above
Bc <- AtoB( A, d )
B1 <- Bc$B

# Row Space of B and B1 must be the same.
MustBeZero <- (diag(ncol(B))-t(B)%*%solve(B%*%t(B))%*%B)%*%t(B1)

[Package lazy.mat version 0.1.3 Index]