English 中文(简体)
原有抗逆转录酶病毒抗逆转录酶病毒剂的操作费
原标题:$ operator is invalid for atomic vectors ERROR while running R packages MetaLonDA
  • 时间:2023-05-29 17:30:40
  •  标签:
  • r
  • vector

我正在尝试运行一个特定的R软件包,MetaLonDA,它可以分析纵向、相对丰度、微生物组数据。该软件包包含两个命令:1. "metalonda()"用于测试一个特征,2. "metalondaAll"用于测试所有特征。我无法运行第一个命令"metalonda()",因为我一直会产生这个错误:$ 运算符对于原子向量无效。这个错误很奇怪,因为所有的向量都是数值型的。以下是我的代码和数据。

Github page: https://github.com/aametwally/MetaLonDA

从CRAN安装:

    install.packages("MetaLonDA")
    library(MetaLonDA)

Install from github:

    library(devtools)
    install_github("aametwally/MetaLonDA", ref = "master")
    library(MetaLonDA)

病媒:

otu <- structure(c(2547, 0, 600, 3, 17, 0, 372, 202, 0, 339, 10491,
0, 1417, 2083, 0, 325, 4521, 0, 12366, 6, 5891, 0, 0, 0, 643,
399, 0, 301, 343, 0, 1194, 9, 15835, 0, 56, 0, 20554, 0, 11336,
2, 0, 0, 538, 1104, 0, 2736, 3430, 0, 1347, 1249, 0, 977, 6455,
0, 80, 39, 0, 429, 341, 0, 156, 70, 0, 382, 186, 0, 1751, 925,
0, 0, 7634, 0, 561, 99, 0, 1067, 655, 0, 160, 654, 0, 0, 2009,
0, 139, 0, 5433, 0, 0, 0, 169, 85, 0, 406, 206, 0, 374, 236,
4, 459, 718, 51, 123, 81, 0, 623, 1992, 0, 0, 0, 344, 0, 40,
0, 304, 88, 0, 284, 1372, 0, 79, 96, 0, 130, 403, 0, 144, 61,
0, 357, 731, 40, 95, 504, 0, 2912, 9435, 0, 323, 15, 0, 485,
340, 0, 254, 100, 4, 863, 2210, 0, 32, 21, 0, 219, 443, 0, 1925,
103, 0, 327, 1420, 0, 457, 23, 0, 95, 370, 0, 68, 399, 0, 159,
932, 0, 82, 13, 0, 105, 225, 0, 244, 46, 0, 153, 786, 0, 3105,
1114, 0, 0, 1011, 0, 276, 364, 0, 604, 2936, 0, 417, 154, 0,
224, 710, 0, 55, 26, 0, 198, 254, 0, 92, 8, 0, 236, 37, 0, 243,
123, 0, 195, 161, 0, 115, 123, 0, 869, 577, 0, 1272, 730, 0,
520, 844, 0, 50, 368, 8, 5, 902, 0, 602, 52, 0, 828, 2176, 0,
338, 143, 3, 416, 1341, 31, 1032, 12727, 25637, 0, 5566, 0, 41,
11, 0, 309, 205, 0, 70, 4, 0, 359, 198, 0, 154, 60, 0, 51, 1221,
0, 3, 4, 0, 77, 85, 0, 65, 152, 0, 257, 917, 0, 136, 60, 0, 78,
746, 0), .Dim = c(6L, 49L), .Dimnames = list(c("taxa 1", "taxa 2",
"taxa 3", "taxa 4", "taxa 5", "taxa 6"), c("LID_100039", "LID_100080",
"LID_100105", "LID_100125", "LID_100194", "LID_100225", "LID_100229",
"LID_100551", "LID_101556", "LID_101558", "LID_101560", "LID_101562",
"LID_101564", "LID_101566", "LID_101569", "LID_101570", "LID_101571",
"LID_101573", "LID_101575", "LID_101577", "LID_101581", "LID_101584",
"LID_101587", "LID_101590", "LID_101591", "LID_101592", "LID_101593",
"LID_101594", "LID_101596", "LID_101597", "LID_101601", "LID_101602",
"LID_101604", "LID_101606", "LID_101608", "LID_101610", "LID_101612",
"LID_101613", "LID_101616", "LID_101617", "LID_101618", "LID_101619",
"LID_101620", "LID_101621", "LID_101622", "LID_101623", "LID_101624",
"LID_101630", "LID_101632")))

Group <- structure(c(2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L), .Label = c("Female", "Male"))

Individual <- structure(c(64L, 34L, 5L, 23L, 53L, 4L, 47L, 80L, 71L, 43L, 1L,
87L, 48L, 45L, 55L, 18L, 11L, 47L, 75L, 44L, 47L, 10L, 86L, 44L,
28L, 61L, 21L, 73L, 70L, 86L, 45L, 1L, 43L, 47L, 48L, 11L, 16L,
60L, 58L, 40L, 30L, 31L, 50L, 17L, 5L, 86L, 76L, 60L, 69L), .Label = c("F100",
"F101", "F102", "F103", "F104", "F105", "F106", "F107", "F108",
"F109", "F110", "F111", "F112", "F113", "F114", "F115", "F116",
"F117", "F118", "F119", "F120", "F121", "F122", "F123", "F124",
"F125", "F126", "F127", "F128", "F129", "F130", "F131", "F132",
"F32", "F74", "F84", "F85", "F86", "F87", "F88", "F89", "F90",
"F91", "F92", "F93", "F94", "F95", "F96", "F97", "F98", "F99",
"M49", "M50", "M51", "M52", "M53", "M54", "M55", "M56", "M57",
"M58", "M59", "M60", "M61", "M62", "M63", "M64", "M65", "M66",
"M67", "M68", "M69", "M70", "M71", "M72", "M73", "M74", "M75",
"M76", "M77", "M78", "M79", "M80", "M81", "M82", "M83", "M84",
"M85", "M86"))

Time <- structure(c(13L, 5L, 2L, 6L, 4L, 1L, 12L, 3L, 44L, 45L, 44L,
43L, 42L, 42L, 40L, 41L, 39L, 38L, 36L, 37L, 34L, 35L, 33L, 32L,
8L, 9L, 7L, 7L, 26L, 27L, 23L, 22L, 24L, 21L, 28L, 29L, 25L,
19L, 20L, 14L, 15L, 16L, 17L, 18L, 18L, 11L, 10L, 30L, 31L), .Label = c("2015-02-20",
"2015-04-01", "2015-04-03", "2015-05-13", "2015-05-14", "2015-05-18",
"2015-11-25", "2016-01-09", "2016-01-12", "2016-02-02", "2016-02-13",
"2016-02-22", "2016-04-06", "2016-04-15", "2016-04-18", "2016-05-19",
"2016-05-23", "2016-07-02", "2017-06-02", "2017-06-06", "2017-06-16",
"2017-06-23", "2017-06-29", "2017-08-03", "2017-08-12", "2017-08-15",
"2017-08-21", "2017-10-03", "2017-10-06", "2017-12-02", "2017-12-21",
"2018-02-16", "2018-03-02", "2018-05-01", "2018-05-02", "2018-05-24",
"2018-06-01", "2018-06-02", "2018-06-05", "2018-06-11", "2018-06-16",
"2018-07-03", "2018-07-14", "2018-08-01", "2018-08-02"))

points = as.numeric(seq(1, 49, length.out = 49))

运行metalonda命令:

output2.metalonda.f5 = metalonda(Count = otu[5,], Time = Time, Group = Group,
ID = Individual, n.perm = 100, fit.method = "nbinomial", points = points,
text = rownames(subset_otu)[5], parall = FALSE, pvalue.threshold = 0.05,
adjust.method = "BH", time.unit = "days", ylabel = "Normalized Count",
col = c("black", "green"), prefix = "Test2_F5")

感谢你提供的任何帮助。 我有可能误解如何为一揽子计划建立病媒(上述Github网页上概述了这些指示)。

问题回答

首先要说明的是:您可以从 Hadley Wickham 的《Advanced R》第22章学习 R 的调试技巧,该章节涵盖了我在这个答案中使用到的所有方法。

1. Locate the bug

我主要使用debug()来深入了解函数调用堆栈,你的情况从这里开始:

debug(MetaLonDA::metalonda)
output2.metalonda.f5 <- MetaLonDA::metalonda(
  Count = otu[5,], 
  Time = Time, 
  Group = Group,
  ID = Individual, 
  n.perm = 100, 
  fit.method = "nbinomial", 
  points = points,
  parall = FALSE, 
  pvalue.threshold = 0.05,
  adjust.method = "BH", 
  time.unit = "days", 
  ylabel = "Normalized Count",
  col = c("black", "green"), 
  prefix = "Test2_F5"
)

如果你照此办理,你可能会在此遇到错误。 http://www.un.org/Depts/DGACM/index_french.htm

将此翻译成中文:enter image description here 无法翻译,因为这是一个图片链接。

在此时,您可以尝试在tryCatch()内调用函数,以确保函数MetaLonDA::curveFitting()是出现错误的地方。

“entergraph

然后退出调试模式(通过控制台中的 Q)并:

undebug(MetaLonDA::metalonda)  # quit debugging metalonda...
debug(MetaLonDA::curveFitting)  # ...and start digging deeper

经过数次迭代,您可能会发现错误消息来自于 gss::mkphi.tp(),而实际问题是 gss::mkterm()(调用了gss :: mkphi.tp())向前一个错误的参数。这个问题追溯到您的 Time 对象,它不是一个向量。

将此翻译成中文:enter image description here 无法翻译为中文,因为这只是一个带有图像链接的HTML代码。

2. Back to the manual

页: 1 梅塔隆达:metalonda() 手册。 它说,time,GroupID的论点都应当都是病媒。 在你的情况下,不幸的是,他们根本不是。

将此翻译成中文:输入图像描述

> is.vector(Time)
[1] FALSE
> is.vector(Individual)
[1] FALSE
> is.vector(Group)
[1] FALSE

所以我尝试对这些数据进行了这些更改:

Group <- 
  c(2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
    1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L,
    2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
    2L, 2L, 2L, 2L)

Individual <- 
  c(64L, 34L, 5L, 23L, 53L, 4L, 47L, 80L, 71L, 43L, 1L,
    87L, 48L, 45L, 55L, 18L, 11L, 47L, 75L, 44L, 47L, 10L, 86L, 44L,
    28L, 61L, 21L, 73L, 70L, 86L, 45L, 1L, 43L, 47L, 48L, 11L, 16L,
    60L, 58L, 40L, 30L, 31L, 50L, 17L, 5L, 86L, 76L, 60L, 69L)

Time <- 
  c(13L, 5L, 2L, 6L, 4L, 1L, 12L, 3L, 44L, 45L, 44L,
    43L, 42L, 42L, 40L, 41L, 39L, 38L, 36L, 37L, 34L, 35L, 33L, 32L,
    8L, 9L, 7L, 7L, 26L, 27L, 23L, 22L, 24L, 21L, 28L, 29L, 25L,
    19L, 20L, 14L, 15L, 16L, 17L, 18L, 18L, 11L, 10L, 30L, 31L)

output2.metalonda.f5 <- metalonda(
  Count = otu[5,], 
  Time = Time, 
  Group = Group,
  ID = Individual, 
  n.perm = 100, 
  fit.method = "nbinomial", 
  points = points,
  parall = FALSE, 
  pvalue.threshold = 0.05,
  adjust.method = "BH", 
  time.unit = "days", 
  ylabel = "Normalized Count",
  col = c("black", "green"), 
  prefix = "Test2_F5"
)
Start MetaLonDA 
Visualizing Feature =  0 
Start Curve Fitting 
Fitting: NB SS 
Visualizing Splines of Feature =  0 
Calculate Area Under the Fitted Curves 
Start Permutation 
  |=======================================================================================================| 100%
p-value Adjustment Method =  BH 
Visualizing Significant Intervals of Feature =  0 


Warning message:
`guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> = "none")` instead. 
>

我不知道您从哪里获取 .Label 属性,也不知道它是否有意义。因此,结果可能不合理。我只是从工程师的角度尝试正确运行它。希望这能帮到您。

PS:sessioninfo:session_info(

─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.1.3 (2022-03-10)
 os       Ubuntu 20.04.5 LTS
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Etc/UTC
 date     2023-05-30
 rstudio  2022.02.2+485 Prairie Trillium (server)
 pandoc   2.5 @ /usr/bin/pandoc

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────
 ! package        * version date (UTC) lib source
 P assertthat       0.2.1   2019-03-21 [?] RSPM (R 4.1.0)
 P BiocManager      1.30.16 2021-06-15 [?] RSPM (R 4.1.0)
 P bit              4.0.4   2020-08-04 [?] RSPM (R 4.1.0)
 P bit64            4.0.5   2020-08-30 [?] RSPM (R 4.1.0)
 P cli              3.6.1   2023-03-23 [?] CRAN (R 4.1.3)
   codetools        0.2-18  2020-11-04 [2] CRAN (R 4.1.3)
 P colorspace       2.0-3   2022-02-21 [?] RSPM (R 4.1.0)
 P crayon           1.5.1   2022-03-26 [?] RSPM (R 4.1.0)
 P DBI              1.1.3   2022-06-18 [?] CRAN (R 4.1.3)
 P digest           0.6.29  2021-12-01 [?] RSPM (R 4.1.0)
 P doParallel       1.0.17  2022-02-07 [?] RSPM (R 4.1.0)
 P dplyr            1.0.8   2022-02-08 [?] RSPM (R 4.1.0)
 P ellipsis         0.3.2   2021-04-29 [?] RSPM (R 4.1.0)
 P fansi            1.0.3   2022-03-24 [?] RSPM (R 4.1.0)
 P farver           2.1.0   2021-02-28 [?] RSPM (R 4.1.0)
 P forcats          0.5.1   2021-01-27 [?] RSPM (R 4.1.0)
 P foreach          1.5.2   2022-02-02 [?] RSPM (R 4.1.0)
 P formatR          1.12    2022-03-31 [?] RSPM (R 4.1.0)
 P fs               1.5.2   2021-12-08 [?] RSPM (R 4.1.0)
 P futile.logger    1.4.3   2016-07-10 [?] RSPM (R 4.1.0)
 P futile.options   1.0.1   2018-04-20 [?] RSPM (R 4.1.0)
 P generics         0.1.2   2022-01-31 [?] RSPM (R 4.1.0)
 P ggplot2          3.3.5   2021-06-25 [?] RSPM (R 4.1.0)
 P ggsci            2.9     2018-05-14 [?] RSPM (R 4.1.0)
 P ggthemes         4.2.4   2021-01-20 [?] RSPM (R 4.1.0)
 P glue             1.6.2   2022-02-24 [?] RSPM (R 4.1.0)
 P gss              2.2-4   2023-03-15 [?] CRAN (R 4.1.3)
 P gtable           0.3.0   2019-03-25 [?] RSPM (R 4.1.0)
 P iterators        1.0.14  2022-02-05 [?] RSPM (R 4.1.0)
 P knitr            1.38    2022-03-25 [?] RSPM (R 4.1.0)
 P labeling         0.4.2   2020-10-20 [?] RSPM (R 4.1.0)
 P lambda.r         1.2.4   2019-09-18 [?] RSPM (R 4.1.0)
   lattice          0.20-45 2021-09-22 [2] CRAN (R 4.1.3)
 P lifecycle        1.0.3   2022-10-07 [?] CRAN (R 4.1.3)
 P lsa              0.73.2  2020-05-04 [?] RSPM (R 4.1.0)
 P magrittr         2.0.3   2022-03-30 [?] RSPM (R 4.1.0)
 P MetaLonDA      * 1.1.8   2019-12-18 [?] CRAN (R 4.1.3)
 P munsell          0.5.0   2018-06-12 [?] RSPM (R 4.1.0)
 P openxlsx         4.2.5   2021-12-14 [?] RSPM (R 4.1.0)
 P pillar           1.7.0   2022-02-01 [?] RSPM (R 4.1.0)
 P pkgconfig        2.0.3   2019-09-22 [?] RSPM (R 4.1.0)
 P plyr             1.8.7   2022-03-24 [?] RSPM (R 4.1.0)
 P pracma           2.4.2   2022-09-22 [?] CRAN (R 4.1.3)
 P purrr            1.0.1   2023-01-10 [?] CRAN (R 4.1.3)
 P R6               2.5.1   2021-08-19 [?] RSPM (R 4.1.0)
 P Rcpp             1.0.8.3 2022-03-17 [?] RSPM (R 4.1.0)
   renv             0.15.4  2022-03-03 [1] CRAN (R 4.1.3)
 P rlang            1.1.1   2023-04-28 [?] CRAN (R 4.1.3)
 P rstudioapi       0.13    2020-11-12 [?] RSPM (R 4.1.0)
 P scales           1.2.0   2022-04-13 [?] RSPM (R 4.1.0)
 P sessioninfo      1.2.2   2021-12-06 [?] RSPM (R 4.1.0)
 P showtext         0.9-6   2023-05-03 [?] CRAN (R 4.1.3)
 P showtextdb       3.0     2020-06-04 [?] RSPM (R 4.1.0)
 P SnowballC        0.7.0   2020-04-01 [?] RSPM (R 4.1.0)
 P stringi          1.7.6   2021-11-29 [?] RSPM (R 4.1.0)
 P stringr          1.4.0   2019-02-10 [?] RSPM (R 4.1.0)
 P sysfonts         0.8.8   2022-03-13 [?] RSPM (R 4.1.0)
 P tibble           3.1.6   2021-11-07 [?] RSPM (R 4.1.0)
 P tidyr            1.2.0   2022-02-01 [?] RSPM (R 4.1.0)
 P tidyselect       1.1.2   2022-02-21 [?] RSPM (R 4.1.0)
 P tzdb             0.3.0   2022-03-28 [?] RSPM (R 4.1.0)
 P utf8             1.2.2   2021-07-24 [?] RSPM (R 4.1.0)
 P vctrs            0.6.2   2023-04-19 [?] CRAN (R 4.1.3)
 P VennDiagram      1.7.3   2022-04-12 [?] RSPM (R 4.1.0)
 P vroom            1.5.7   2021-11-30 [?] RSPM (R 4.1.0)
 P xfun             0.30    2022-03-02 [?] RSPM (R 4.1.0)
 P zip              2.2.0   2021-05-31 [?] RSPM (R 4.1.0)
 P zoo              1.8-10  2022-04-15 [?] RSPM (R 4.1.0)




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签