0

I have a design matrix that is not full-rank and I want to convert it to full-rank. I decided to make a contrast matrix. I have subtracted the first row from succeeding rows. However, it does not sum to zero. What should I do next to make it sum to zero so that I can use it to reparameterize my design matrix, which then should becomee full-rank?


Here is my procedure:

install.packages("UsingR")
require(UsingR)
    #--1. source
df <- grip %>% dplyr::select(UBP, person, grip.type)
df <- arrange(df, person, grip.type)
lapply(df, head)
df %>% group_by(person, grip.type, .add=TRUE) %>% group_nest()
    #--2. model
X <- cbind(1, as.matrix( ( model.matrix( UBP ~ person + grip.type + 0, data=df) ) ))
Y <- df$UBP
n <- nrow(X); k <- qr(X)$rank

The problem is with lambda after subtracting first row from succeeding rows:

    #--3. estimating parameters
lambda <- unique(X)
lambda[-1,] <- lambda[-1,] - lambda[1,][col( data.matrix( lambda[-1,]) )]
B_ <- ginv(t(X) %*% X) %*% (t(X) %*% Y);  colnames(B_) <- "Estimates"
Z.prime_ <- X %*% ( t(lambda) %*% solve( (lambda %*% t(lambda)) ) ) #--prime model
gamma.prime_ <- lambda %*% B_
Y.prime_ <- Z.prime_ %*% gamma.prime_

lambda before subtracting:

> lambda
     person1 person2 person3 person4 grip.typeintegrated grip.typemodern
1  1       1       0       0       0                   0               0
25 1       1       0       0       0                   1               0
13 1       1       0       0       0                   0               1
4  1       0       1       0       0                   0               0
28 1       0       1       0       0                   1               0
16 1       0       1       0       0                   0               1
7  1       0       0       1       0                   0               0
31 1       0       0       1       0                   1               0
19 1       0       0       1       0                   0               1
10 1       0       0       0       1                   0               0
34 1       0       0       0       1                   1               0
22 1       0       0       0       1                   0               1

lambda after subtracting:

> lambda[-1,] <- lambda[-1,] - lambda[1,][col( data.matrix( lambda[-1,]) )]
> lambda
     person1 person2 person3 person4 grip.typeintegrated grip.typemodern
1  1       1       0       0       0                   0               0
25 0       0       0       0       0                   1               0
13 0       0       0       0       0                   0               1
4  0      -1       1       0       0                   0               0
28 0      -1       1       0       0                   1               0
16 0      -1       1       0       0                   0               1
7  0      -1       0       1       0                   0               0
31 0      -1       0       1       0                   1               0
19 0      -1       0       1       0                   0               1
10 0      -1       0       0       1                   0               0
34 0      -1       0       0       1                   1               0
22 0      -1       0       0       1                   0               1
> sum(lambda)
[1] 10
  • "I have subtracted the first row from succeeding rows." I don't understand why you are doing that and what you believe that's going to achieve. If you have categorical predictors and your design matrix isn't full rank, the usual approach is to merge categories (factor levels). Whatever you do, the first column of the design matrix represents the intercept. It must be a column of ones. – Roland Dec 08 '20 at 07:17
  • Since one of your categorical variables is "person", I would suggest a mixed effects model with a random intercept grouped by person. That way you would remove four parameters from the fixed part of the model and only add one parameter for the random part. – Roland Dec 08 '20 at 07:20
  • I am trying to create a contrast matrix. It requires linear independent estimable functions of Rank(X). The next step is to subtract the first row from succeeding rows. You can check it out here: https://stats.stackexchange.com/questions/78354/what-is-a-contrast-matrix. There is also a book called "Linear Models in Statistics" by Alvin C. Rencher and G. Bruce Schaalje. The PDF can be downloaded for free. Check sub-section 12.2.2 and section 12.5. – Michael Šòdéké Dec 08 '20 at 12:02

0 Answers0