Last active
February 23, 2022 13:25
-
-
Save vankesteren/41c1ef5467520b298099cc135cdef4a9 to your computer and use it in GitHub Desktop.
fast vertically partitioned glms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setup | |
| set.seed(45) | |
| N <- 1000 | |
| ## alice | |
| Pa <- 20 | |
| Xa <- matrix(rnorm(N*Pa), N) | |
| ## bob | |
| Pb <- 15 | |
| Xb <- matrix(rnorm(N*Pb), N) | |
| ## full data | |
| X <- cbind(Xa, Xb) | |
| ## outcome | |
| beta <- rnorm(Pa+Pb) | |
| eta <- X%*%beta | |
| y <- vapply(binomial()$linkinv(eta), \(pr) rbinom(1, 1, prob = pr), 1L) | |
| # full model | |
| fit_full <- glm(y ~ X, family = binomial()) | |
| # modeling from alice's perspective | |
| ## Bob generates random key matrix Rb | |
| Rb <- matrix(runif(Pb*Pb), Pb) | |
| ## Bob ensures Rb is invertible | |
| solve(Rb) | |
| ## Bob obscures his data with this key matrix | |
| Vb <- Xb%*%Rb | |
| ## Alice obtains Vb and creates new dataset Za | |
| Za <- cbind(Xa, Vb) | |
| ## Alice proceeds to do the glm as normal but with Za | |
| fit_alice <- glm(y ~ Za, family = binomial()) | |
| ## now all of alice's parameters and standard errors are correct | |
| comparison <- cbind(summary(fit_full)$coef, summary(fit_alice)$coef) | |
| comparison[1:21,] | |
| ## only bob's part is different | |
| comparison[23:36,] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alice's parameters
Bob's parameters