BtoA {lazy.mat} | R Documentation |
Linear Constraints Matrices: form B to form A conversion
BtoA(B, c, eps = 1e-09, useginv = 1, useeigen = 1, print = 0)
B |
Form B constraints matrix B. |
c |
Form B constraints vector c. |
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 |
This function converts a form B liner constraints of the form
B %*% beta = c.
to form A linear constraints of the form
beta = A %*% gamma + d.
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 A and d.
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 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 ) 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)