oldopts <- options(lfe.threads=1)
## create factors
f1 <- factor(sample(24000,100000,replace=TRUE))
f2 <- factor(sample(20000,length(f1),replace=TRUE))
f3 <- factor(sample(10000,length(f1),replace=TRUE))
f4 <- factor(sample(8000,length(f1),replace=TRUE))
## the matrix of dummies
D <- t(rBind(as(f1,'sparseMatrix'),as(f2,'sparseMatrix'),
as(f3,'sparseMatrix'), as(f4,'sparseMatrix')))
dim(D)
## an x
truex <- runif(ncol(D))
## and the right hand side
R <- as.vector(D %*% truex)
## solve it
sol <- kaczmarz(list(f1,f2,f3,f4),R)
## verify that the solution solves the system Dx = R
res <- D %*% sol - R
sqrt(sum(res^2))
## but the solution is not equal to the true x, because the system is
## underdetermined
sqrt(sum((sol - truex)^2))
## moreover, the solution from kaczmarz has smaller norm
sqrt(sum(sol^2))
sqrt(sum(truex^2))
options(oldopts)
Run the code above in your browser using DataLab