我在使用segmented
包中的pscore.test
函数时遇到了问题(我相信),因为它在内部要求在最初制作模型的环境之外的环境中对我的模型框架进行判断.以下是代码和错误回溯:
ESs <- c("comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp138286_c0_seq1:1233")
models <- lapply(ESs, function(i){
lm(EL ~ temp, 数据=subset(数据, es_code == i))
})
library(segmented)
lapply(models, function(i) pscore.test(i, seg.Z=~temp))
产生的错误消息:
Error in `filter()`:
! Problem while computing `..1 = es_code == i`.
Caused by error in `mask$eval_all_filter()`:
! object 'i' not found
---
Backtrace:
▆
1. ├─BiocGenerics::lapply(models, function(i) pscore.test(i, seg.Z = ~temp))
2. ├─base::lapply(models, function(i) pscore.test(i, seg.Z = ~temp))
3. │ └─global FUN(X[[i]], ...)
4. │ └─segmented::pscore.test(i, seg.Z = ~temp)
5. │ ├─base::eval(mf)
6. │ │ └─base::eval(mf)
7. │ ├─stats::model.frame(...)
8. │ ├─stats::model.frame.default(...)
9. │ │ └─base::is.数据.frame(数据)
10. │ ├─dplyr::filter(数据, es_code == i)
11. │ └─dplyr:::filter.数据.frame(数据, es_code == i)
12. │ └─dplyr:::filter_rows(.数据, ..., caller_env = caller_env())
13. │ └─dplyr:::filter_eval(dots, mask = mask, error_call = error_call)
14. │ ├─base::withCallingHandlers(...)
15. │ └─mask$eval_all_filter(dots, env_filter)
16. └─base::.handleSimpleError(...)
17. └─dplyr (local) h(simpleError(msg, call))
18. └─rlang::abort(bullets, call = error_call, parent = skip_internal_condition(e))
即使我在Apply语句中创建了lm
并将其输入到pscore.test
中,我也得到了相同的问题.我不知道该如何处理这个问题.
数据
数据 <- structure(list(EL = c(0.105914718019257, 0.00572519083969466,
0.875763747454175, 0.709941520467836, 0.0230607966457023, 0.00131061598951507,
0.88255033557047, 0.627272727272727, 0.127433628318584, 0.0772676371780515,
0.794117647058823, 0.619552414605418, 0.610021786492375, 0.284644194756554,
0.0939490445859873, 0.0137420718816068, 0.0749128919860627, 0.01,
0.868312757201646, 0.643356643356643, 0.543909348441926, 0.258706467661692,
0.822709163346614, 0.568459657701711, 0.27190332326284, 0.104795737122558,
0.579497907949791, 0.464713715046605, 0.563583815028902, 0.374376039933444,
0.460405156537753, 0.160046728971963, 0.531353135313531, 0.349532710280374,
0.319230769230769, 0.141025641025641, 0.589473684210526, 0.42258064516129,
0.602040816326531, 0.254752851711027, 0.965699208443272, 0.788273615635179,
0.96280276816609, 0.842271293375394, 0.987025023169602, 0.894894894894895,
0.966329966329966, 0.748914616497829, 0.946175637393768, 0.989655172413793,
0.825665859564165, 0.942332896461337, 0.928571428571429, 0.957163958641064,
0.934981684981685, 0.96353591160221, 0.955985915492958, 0.948051948051948,
0.9140625, 0.920071047957371, 0.959531416400426, 0.947741364038973,
0.965025906735751), temp = c(23L, 23L, 10L, 10L, 25L, 25L, 10L,
10L, 25L, 25L, 10L, 10L, 12L, 12L, 23L, 23L, 23L, 23L, 14L, 14L,
18L, 18L, 14L, 14L, 18L, 18L, 14L, 14L, 18L, 18L, 16L, 16L, 20L,
20L, 20L, 20L, 16L, 16L, 20L, 20L, 12L, 23L, 10L, 25L, 10L, 25L,
10L, 25L, 12L, 12L, 23L, 14L, 18L, 14L, 18L, 14L, 18L, 16L, 20L,
16L, 20L, 16L, 20L), es_code = c("comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp137978_c1_seq3:415",
"comp137978_c1_seq3:475", "comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp137978_c1_seq3:415",
"comp137978_c1_seq3:475", "comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp137978_c1_seq3:415",
"comp137978_c1_seq3:475", "comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp137978_c1_seq3:415",
"comp137978_c1_seq3:475", "comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp137978_c1_seq3:415",
"comp137978_c1_seq3:475", "comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp137978_c1_seq3:415",
"comp137978_c1_seq3:475", "comp137978_c1_seq3:415", "comp137978_c1_seq3:475",
"comp137978_c1_seq3:415", "comp137978_c1_seq3:475", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233", "comp138286_c0_seq1:1233",
"comp138286_c0_seq1:1233")), class = "数据.frame", row.names = c(NA,
-63L))
以下是我的会话信息:
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils 数据sets methods base
other attached packages:
[1] segmented_1.6-4 nlme_3.1-157 MASS_7.3-57
loaded via a namespace (and not attached):
[1] compiler_4.2.1 tools_4.2.1 rstudioapi_0.13 splines_4.2.1 grid_4.2.1 lattice_0.20-45