r - 在 R 包 HMSC 中运行 Mcmc 时如何修复 tcrossprod 错误
问题描述
在 R ( https://github.com/hmsc-r/HMSC ) 中使用 Hmsc 包时,我在小插曲中给出的一些(不是全部)示例以及我自己的数据中遇到了一致的错误。运行 sampleMcmc() 函数时会发生错误。
我试图确保我所有的数据框和矩阵的格式与小插图中的工作示例相同。但是,其中一些示例复制了我使用自己的数据收到的错误消息。例如:
library(Hmsc)
n = 50
x = rnorm(n)
alpha = 0
beta = 1
sigma = 1
L = alpha + beta*x
y = L + rnorm(n, sd = sigma)
Y = as.matrix(y)
XData = data.frame(x = x)
m = Hmsc(Y = Y, XData = XData, XFormula = ~x)
nChains = 2
thin = 5
samples = 1000
transient = 500*thin
verbose = 500*thin
m = sampleMcmc(m, thin = thin, samples = samples, transient = transient, nChains = nChains, verbose = verbose)
给我以下错误:
[1] "Computing chain 1"
Error in tcrossprod(x, y) :
requires numeric/complex matrix/vector arguments
我的系统信息是:
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_CTYPE=en_NZ.UTF-8 LC_NUMERIC=C LC_TIME=en_NZ.UTF-8 LC_COLLATE=en_NZ.UTF-8
[5] LC_MONETARY=en_NZ.UTF-8 LC_MESSAGES=en_NZ.UTF-8 LC_PAPER=en_NZ.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] truncnorm_1.0-8 statmod_1.4.32 phytools_0.6-99 pROC_1.15.3 pdist_1.2 nnet_7.3-12 mvtnorm_1.0-11 MCMCpack_1.4-4
[9] Matrix_1.2-17 ggplot2_3.2.0 BayesLogit_0.6 abind_1.4-5 dplyr_0.8.3 fields_9.8-3 maps_3.3.0 spam_2.2-2
[17] dotCall64_1.0-0 MASS_7.3-51.1 ape_5.3 corrplot_0.84 knitr_1.23 stringr_1.4.0 Hmsc_0.4.3.0 coda_0.19-3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 lattice_0.20-38 snow_0.4-3 gtools_3.8.1 assertthat_0.2.1
[6] R6_2.4.0 plyr_1.8.4 MatrixModels_0.4-1 pillar_1.4.2 rlang_0.4.0
[11] lazyeval_0.2.2 rstudioapi_0.10 SparseM_1.77 phangorn_2.5.5 combinat_0.0-8
[16] splines_3.6.1 igraph_1.2.4.1 munsell_0.5.0 xfun_0.8 compiler_3.6.1
[21] numDeriv_2016.8-1.1 pkgconfig_2.0.2 mnormt_1.5-5 mgcv_1.8-28 mcmc_0.9-6
[26] tidyselect_0.2.5 tibble_2.1.3 expm_0.999-4 quadprog_1.5-7 withr_2.1.2
[31] crayon_1.3.4 nlme_3.1-140 gtable_0.3.0 magrittr_1.5 scales_1.0.0
[36] stringi_1.4.3 scatterplot3d_0.3-41 fastmatch_1.1-0 tools_3.6.1 glue_1.3.1
[41] purrr_0.3.2 yaml_2.2.0 plotrix_3.7-6 colorspace_1.4-1 animation_2.6
[46] clusterGeneration_1.3.4 quantreg_5.42.1
很高兴了解我为什么会收到此错误,以及如何克服它,以便我可以修复我的真实数据集。
谢谢
解决方案
有一个错误,问题已解决。见https://github.com/hmsc-r/HMSC/issues/17
推荐阅读
- python - 如何在python中将矩阵的数量转换为分数而不是小数?
- javascript - 编辑文本区域后 jQuery 追加不起作用
- android - 在android studio的googlemap上显示错误的位置
- excel - 未定义索引:代码在 Laravel 5.8 中使用 Export to Excel
- mysql - Aurora Serverless Mysql 上的一致读/写
- node.js - 如何为我显示正确时区的时间和日期?
- python - PyCharm CE 无法识别 .pyx 文件
- tableau-api - 从 tableau javascript api 解析从 rememberCustomViewAsync 收到的响应
- java - 将linux路径转换为windows路径
- python - 以最有效的方式组合数字