SCM

[#6784] maintain non-structural zeros in Khatri-Rao product

Date:
2022-10-23 23:25
Priority:
3
State:
Open
Submitted by:
Ben Bolker (bbolker)
Assigned to:
Nobody (None)
Hardware:
None
Product:
None
Operating System:
None
Component:
None
Version:
None
Severity:
enhancement
Resolution:
None
URL:
Summary:
maintain non-structural zeros in Khatri-Rao product

Detailed description
Copying from https://github.com/lme4/lme4/issues/671, where there is more discussion

```
library(Matrix)
dat <- data.frame(y = 1:3,id = rep(1:2,each=3),t = c(0,1,0,2,3,4))
sm <- fac2sparse(factor(dat$id), to = "d")
mm <- model.matrix(~t, data = dat)
sm <- KhatriRao(sm, t(mm))
Matrix::t(sm)
```
Results:

```
6 x 4 sparse Matrix of class "dgCMatrix"
1 1 2 2
1 1 . . .
2 1 1 . .
3 1 . . .
4 . . 1 2
5 . . 1 3
6 . . 1 4
```

Desired results (i.e., keeping zero values in original `mm` as non-structural):

```
6 x 4 sparse Matrix of class "dgCMatrix"
1 1 2 2
1 1 0 . .
2 1 1 . .
3 1 0 . .
4 . . 1 2
5 . . 1 3
6 . . 1 4
```

Comments:

Message  ↓
Date: 2022-11-02 18:34
Sender: Ben Bolker

I didn't know that -- thanks for pointing it out. I guess I will add `sparseY=TRUE` to the lme4 code calling this (with further back-compatibility hooks ...)

Date: 2022-11-02 18:27
Sender: Mikael Jagan

I'm a bit confused. Didn't Martin add an argument 'sparseY' in Matrix 1.5-0, with default TRUE for backwards compatibility?

> KhatriRao(sm, t(mm), sparseY = FALSE)
4 x 6 sparse Matrix of class "dgCMatrix"

[1,] 1 1 1 . . .
[2,] 0 1 0 . . .
[3,] . . . 1 1 1
[4,] . . . 2 3 4

But perhaps we also need a 'sparseX' argument?

We must deal with kronecker() simultaneously, i.e., kronecker() methods involving denseMatrix or traditional matrices should also get an argument, say 'drop0', specifying how zeros in the dense factor(s) are treated.

Attached Files:

Changes

No Changes Have Been Made to This Item

Thanks to:
Vienna University of Economics and Business Powered By FusionForge