How to generate a matrix with a specific rank in R
1 answer
The simplest is the identity matrix, which always has full rank. So, for example, Application:
k <- 10
mymatrix <- diag(k)
Here the rows and columns are equal to the angle you specified
I am assuming that you want to mimic the regression model, so you may need more rows (which means "observations") than columns (eg "variables"). The following code allows you to specify both parameters:
k <- 5 # rank of your matrix
nobs <- 10 # number of lines within X
X <- rbind(diag(k), matrix(rep(0,k*(nobs-k)), ncol=k))
y <- X + rnorm(nobs)
Note that X - and therefore also y - now have full column rank. there is no multicollinearity in this "model".
+1
source to share