我正在尝试创建一个投影矩阵并按照 Stubben 和 Milligan (2007) 使用 R 中的 popbio 包记录的相同程序计算引导转换。
我已将数据格式化为"test.census"
与包中可用的示例非常相似。但是,当我使用这些功能时projection.matrix
,boot.transitions
我收到以下错误:
[.data.frame(transitions, , stage) 中的错误:选择了未定义的列
如果我向函数添加其他参数,我可以开始projection.matrix
工作,但不是boot.transitions
.
有谁知道为什么会这样?有什么办法吗?
我花了很多时间研究为什么会发生这种情况,并且在发帖之前我已经尝试了所有替代方法。我将非常感谢任何帮助或见解。
这是我的数据集的一小部分:
structure(list(Site = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), Plot = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), Tag = c(1032L, 1002L, 1027L, 1013L, 1005L, 1037L, 1030L,
1028L, 1004L, 1010L, 1029L, 1018L, 1015L, 1007L, 1070L, 1056L,
1042L, 1078L, 1071L, 1055L, 1079L, 1065L, 1062L, 1054L, 1045L,
1073L, 1053L, 1046L, 1044L, 1113L, 1098L, 1093L, 1086L, 1118L,
1115L, 1082L, 1090L, 1114L, 1107L, 1099L, 1120L, 1111L, 1101L,
1096L, 1084L, 1092L, 1032L, 1002L, 1027L, 1013L, 1005L, 1037L,
1030L, 1028L, 1004L, 1010L, 1029L, 1018L, 1015L, 1007L, 1070L,
1056L, 1042L, 1078L, 1071L, 1055L, 1079L, 1065L, 1062L, 1054L,
1045L, 1073L, 1053L, 1046L, 1044L, 1113L, 1098L, 1093L, 1086L,
1118L, 1115L, 1082L, 1090L, 1114L, 1107L, 1099L, 1120L, 1111L,
1101L, 1096L, 1084L, 1092L), Status = structure(c(4L, 4L, 5L,
5L, 5L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 5L, 5L,
5L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 1L, 1L, 1L, 3L,
3L, 3L, 3L, 5L, 2L, 2L, 3L, 2L, 2L, 5L, 1L, 1L, 5L, 1L, 3L, 3L,
3L, 1L, 3L, 2L, 2L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 5L, 5L, 3L, 5L,
3L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 2L), .Label = c("DEAD", "LG",
"MD", "SEED", "SM"), class = "factor"), Year = c(2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L,
2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L
), Ramets = c(1L, 1L, 1L, 1L, 1L, 8L, 4L, 5L, 2L, 4L, 14L, 11L,
17L, 20L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 2L, 4L, 6L, 9L, 22L, 54L,
11L, 12L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 10L, 2L, 4L, 11L, 18L,
18L, 16L, 11L, 13L, 1L, 0L, 0L, 0L, 7L, 7L, 3L, 9L, 1L, 14L,
11L, 3L, 14L, 17L, 1L, 0L, 0L, 1L, 0L, 2L, 10L, 3L, 0L, 10L,
13L, 19L, 51L, 0L, 9L, 0L, 0L, 0L, 0L, 1L, 1L, 5L, 1L, 2L, 11L,
3L, 8L, 32L, 6L, 7L, 7L, 15L), Seeds = c(0, 0, 479.5146293, 479.5146293,
479.5146293, 3836.117034, 1918.058517, 2397.573146, 959.0292585,
1918.058517, 6713.20481, 5274.660922, 8151.748697, 9590.292585,
0, 0, 0, 479.5146293, 479.5146293, 479.5146293, 2877.087776,
959.0292585, 1918.058517, 2877.087776, 4315.631663, 10549.32184,
25893.78998, 5274.660922, 5754.175551, 0, 0, 0, 479.5146293,
479.5146293, 479.5146293, 479.5146293, 479.5146293, 4795.146293,
959.0292585, 1918.058517, 5274.660922, 8631.263327, 8631.263327,
7672.234068, 5274.660922, 6233.69018, 479.5146293, 0, 0, 0, 3356.602405,
3356.602405, 1438.543888, 4315.631663, 479.5146293, 6713.20481,
5274.660922, 1438.543888, 6713.20481, 8151.748697, 479.5146293,
0, 0, 479.5146293, 0, 959.0292585, 4795.146293, 1438.543888,
0, 4795.146293, 6233.69018, 9110.777956, 24455.24609, 0, 4315.631663,
0, 0, 0, 0, 479.5146293, 479.5146293, 2397.573146, 479.5146293,
959.0292585, 5274.660922, 1438.543888, 3836.117034, 15344.46814,
2877.087776, 3356.602405, 3356.602405, 7192.719439), SEEDS = c(0,
0, 2.206153846, 2.206153846, 2.206153846, 17.64923077, 8.824615385,
11.03076923, 4.412307692, 8.824615385, 30.88615385, 24.26769231,
37.50461538, 44.12307692, 0, 0, 0, 2.206153846, 2.206153846,
2.206153846, 13.23692308, 4.412307692, 8.824615385, 13.23692308,
19.85538462, 48.53538462, 119.1323077, 24.26769231, 26.47384615,
0, 0, 0, 2.206153846, 2.206153846, 2.206153846, 2.206153846,
2.206153846, 22.06153846, 4.412307692, 8.824615385, 24.26769231,
39.71076923, 39.71076923, 35.29846154, 24.26769231, 28.68, 2.206153846,
0, 0, 0, 15.44307692, 15.44307692, 6.618461538, 19.85538462,
2.206153846, 30.88615385, 24.26769231, 6.618461538, 30.88615385,
37.50461538, 2.206153846, 0, 0, 2.206153846, 0, 4.412307692,
22.06153846, 6.618461538, 0, 22.06153846, 28.68, 41.91692308,
112.5138462, 0, 19.85538462, 0, 0, 0, 0, 2.206153846, 2.206153846,
11.03076923, 2.206153846, 4.412307692, 24.26769231, 6.618461538,
17.64923077, 70.59692308, 13.23692308, 15.44307692, 15.44307692,
33.09230769)), .Names = c("Site", "Plot", "Tag", "Status", "Year",
"Ramets", "Seeds", "SEEDS"), row.names = c(NA, 92L), class = "data.frame")
这是我的代码:
##build a stage-fate data frame
trans3<-subset(merge(fate3, fate3, by = "Tag",
sort = FALSE), Year.x == Year.y - 1)
head2(trans3)
##rename columns
rownames(trans3)<-1:nrow(trans3)
colnames(trans3)[2:15]<-c("Site", "Plot", "Stage", "Year", "Ramets", "Seeds", "SEED", "Site", "Plot", "Fate", "Year2", "Ramets2",
"Seeds2", "SEED2")
head2(trans3)
##subset for one year
trans31<-subset(trans3, Year==2016, c(Tag, Site, Plot, Stage, Ramets, Seeds, Fate, SEED))
trans31
##order stages
stages<-c("SEED", "SM", "MD", "LG")
trans31$Stage<-ordered(trans31$Stage, levels=stages)
##projection matrix - error:undefined columns selected
projection.matrix(trans31, sort = stages)
##projeciton matrix - this works
a<-projection.matrix(trans31, Stage, Fate, SEED, sort=stages)
a
##boot transitions - error:undefined columns selected
boot.transitions(trans31, 5)