library(clusterGeneration)
library(mvtnorm)
# sample size
n = 30
# number of response variables
m = 6
# Error covariance
Sigma = genPositiveDefMat(m)$Sigma
# regression parameters
beta = matrix(.6, 1, m)
# covariates
X = matrix(rnorm(n), ncol=1)
# Simulate response variables
Y = X %*% beta + rmvnorm(n, sigma = Sigma)
# Multivariate regression
fit = lm(Y ~ X)
# Correlation between residuals
C = cor(residuals(fit))
# Extract effect sizes and standard errors from model fit
df = lapply(coef(summary(fit)), function(a)
data.frame(beta = a["X", 1], se = a["X", 2]))
df = do.call(rbind, df)
# Meta-analysis assuming infinite sample size
# but the p-value is anti-conservative
LS(df$beta, df$se, C)
# Meta-analysis explicitly modeling the finite sample size
# Gives properly calibrated p-values
# nu is the residual degrees of freedom from the model fit
LS.empirical(df$beta, df$se, C, nu=n-2)
Run the code above in your browser using DataLab