Now we have B, C and D. How do we get back to A? Need to invert D, which isn’t square so use Moore-Penrose pseudoinverse
library(pracma)Ahat <-pinv(D) %*% C %*% B
Does the prediction match the true A?
cor(c(Ahat), c(A))
[1] 0.9279607
plot(Ahat, A)
Quite close - the pseudoinverse has failed to get some of the values correct. Alternative to using pseudoinverse is to just manually re-label trait names with side effect values
sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
time zone: Europe/London
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] pracma_2.4.2
loaded via a namespace (and not attached):
[1] htmlwidgets_1.6.2 compiler_4.3.0 fastmap_1.1.1 cli_3.6.1
[5] tools_4.3.0 htmltools_0.5.5 rstudioapi_0.14 yaml_2.3.7
[9] rmarkdown_2.22 knitr_1.43 xfun_0.39 digest_0.6.31
[13] jsonlite_1.8.7 rlang_1.1.1 evaluate_0.21