approx_mult_prod is sensitive to variable order
jackmwolf opened this issue · comments
The output of approx_mult_prod()
changes based on the order of response means/covariances.
The returned lists from both of the approx_mult_prod()
statements in the reprex below should be equal but they are not.
library(grass)
ex_data <- bin_data[c("g", "x", "y1", "y2", "y3")]
head(ex_data)
#> g x y1 y2 y3
#> 1 0 -0.9161478 1 0 1
#> 2 0 1.2496985 0 1 0
#> 3 1 -1.2708514 0 0 0
#> 4 2 0.0832760 0 1 0
#> 5 0 0.4686342 0 1 1
#> 6 2 0.4620154 0 1 0
means <- colMeans(ex_data)
covs <- cov(ex_data)
n <- nrow(ex_data)
predictors <- list(
new_predictor_snp(maf = mean(ex_data$g) / 2),
new_predictor_normal(mean = mean(ex_data$x), sd = sd(ex_data$x))
)
responses <- lapply(means[3:length(means)], new_predictor_binary)
approx_mult_prod(means, covs, n, response = "binary",
predictors = predictors, responses = responses, verbose = TRUE)
#> Approximating with responses ordered as: y1 * y2 * y3
#> Approximating with responses ordered as: y1 * y3 * y2
#> Approximating with responses ordered as: y2 * y3 * y1
#> $means
#> g x y1y2y3
#> 0.56800000 -0.02927950 0.05444547
#>
#> $covs
#> g x y1y2y3
#> g 0.40978579 -0.04510754 -0.02670105
#> x -0.04510754 0.99460726 0.04906614
#> y1y2y3 -0.02670105 0.04906614 0.05153269
# Reorder response means/covariances
means <- means[c(1, 2, 5, 4, 3)]
covs <- covs[c(1, 2, 5, 4, 3), c(1, 2, 5, 4, 3)]
responses <- lapply(means[3:length(means)], new_predictor_binary)
approx_mult_prod(means, covs, n, response = "binary",
predictors = predictors, responses = responses, verbose = TRUE)
#> Approximating with responses ordered as: y3 * y2 * y1
#> Approximating with responses ordered as: y3 * y1 * y2
#> Approximating with responses ordered as: y2 * y1 * y3
#> $means
#> g x y3y2y1
#> 0.56800000 -0.02927950 0.08101557
#>
#> $covs
#> g x y3y2y1
#> g 0.40978579 -0.04510754 -0.03324090
#> x -0.04510754 0.99460726 0.05203570
#> y3y2y1 -0.03324090 0.05203570 0.07452658
Created on 2020-08-05 by the reprex package (v0.3.0)