pseudo_data_gen | R Documentation |
This function generates data from summary statistics that in turn have the same summary statistics. This can be useful to replicate analyses for which we only have summary statistics. See reference and example. Code comes from https://github.com/lizlimpocouhasselt/LMM-from-summary-statistics.
pseudo_data_gen(n = 1, mu, Sigma, tol = 1e-06, empirical = TRUE)
n |
number of observations to generate |
mu |
mean |
Sigma |
covariance matrix |
tol |
used to confirm Sigma is positive definite |
empirical |
logical (default is TRUE). Which procedure to use. |
Matrix
Limpoco, M.A.A., Faes, C. and Hens, N. (2024), Linear Mixed Modeling of Federated Data When Only the Mean, Covariance, and Sample Size Are Available. Statistics in Medicine. https://doi.org/10.1002/sim.10300
# using the Swiss data that come with R
xbar <- apply(swiss, 2, mean) # mean
s <- cov(swiss) # covariance
# Now generate psuedo data using these summary stats
pseudo_swiss <- pseudo_data_gen(n = nrow(swiss), mu = xbar, Sigma = s)
# verify summary stats of pseudo data match original summary stats
all.equal(xbar, apply(pseudo_swiss, 2, mean))
# [1] TRUE
all.equal(s, cov(pseudo_swiss))
# [1] TRUE
# Same analysis results
pseudo_swiss <- as.data.frame(pseudo_swiss)
m1 <- lm(Fertility ~ ., data = swiss)
m2 <- lm(Fertility ~ ., data = pseudo_swiss)
all.equal(coef(m1), coef(m2))
# [1] TRUE
summary(m1)$coefficients
summary(m2)$coefficients
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.