为什么我的ordisurf拟合值与实际变量值不匹配?

问题描述

这是我的Nmds排序矩阵(PA.mm.5p.rel)。

structure(c(0,1,1),.Dim = c(45L,8L),.Dimnames = list(c("3","4","5","7","8","10","11","12","13","15","16","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51"
),c("Onisimus","Amphipods","Krill","copepods","Fish","Gammarus","Arctic.cod","Sand.Lance")))

这是我的环境/个人数据(PA_Info)。

structure(list(Date = structure(c(3L,3L,5L,6L,7L,8L,9L,10L,12L,14L,15L,16L,17L,18L,19L,20L,21L,22L,23L,25L),.Label = c("2017-07-19","2017-07-25","2017-08-07","2017-08-08","2017-08-09","2017-08-12","2017-08-14","2017-08-15","2017-08-22","2017-09-01","2017-09-04","2018-07-20","2018-07-23","2018-07-26","2018-07-29","2018-07-30","2018-08-01","2018-08-02","2018-08-04","2018-08-06","2018-08-08","2018-08-14","2018-08-19","2018-08-20","2018-08-28","2019-08-08","2019-08-10","2019-08-11","2019-08-12","2019-08-13","2019-08-14"
),class = "factor"),Floy = c(NA,NA,2019L,2014L,2060L,2575L,NA),FishID = structure(c(16L,25L,24L,28L,26L,29L,27L,30L,4L,11L,13L,31L,33L,34L,35L,36L,37L,38L,39L,40L,41L,42L,43L,44L,45L,46L,47L,48L,49L,50L,51L,53L),.Label = c("Char 08","Char 09","Char 112","Char 116","Char 121","Char 123","Char 126","Char 129","Char 130","Char 132","Char 138","Char 150","Char 154","Char 156","Char 54","Char 56","Char 58","Char 60","Char 61","Char 62","Char 63","Char 65","Char 66","Char 68","Char 69","Char 86","Char 87","Char 88","Char 89","Char 90","SSS001","SSS002","SSS003","SSS004","SSS005","SSS006","SSS007","SSS008","SSS009","SSS010","SSS011","SSS012","SSS013","SSS014","SSS015","SSS016","SSS017A","SSS017B","SSS018","SSS019","SSS020","SSS021","SSS022","SSS23","SSS24","SSS25","SSS26","SSS27","SSS28","SSS29","SSS30","SSS31","SSS32","SSS33","SSS34","SSS35","SSS36","SSS37","SSS38","SSS39","SSS40","SSS41","SSS42","SSS43","SSS44","SSS45","SSS46","SSS47","SSS48","SSS49","SSS50","SSS51","SSS52","SSS53","TCH01","TCH02","TCH03","TCH04","TCH05","TCH06","TCH07"),TL = c(71,33.2,35.5,59.5,53.7,65.3,54.5,57.5,61.5,60,56.5,53.5,55,57,61,38.5,65.2,59,29.5,17,79.5,81.3,90,67,73.2,86,85,63.2,72.4,65.4,66.8,79,75,90.8,76,41.4,82,83,77.6),FL = structure(c(55L,67L,72L,63L,57L,62L,71L,53L,65L,60L,73L,61L,69L,70L,62L),.Label = c("13.5","15.8","16.5","28.3","31.5","34.5","39.4","40.6","46.8","48.6","51.5","52","53","53.2","53.5","55.4","56","57","57.2","57.5","58","58.3","58.4","58.8","59","59.2","59.6","60","61","61.1","61.2","61.4","61.8","62","62.5","62.6","63","63.5","64","65","65.4","65.6","66","66.4","66.8","67","67.6","68","69","69.9","70","70.1","70.4","72.6","72.8","75","76","76 (pcl)","76.4","76.8","77.4","77.5","78","79.8","81.4","83","83.8","89.8"),Girth = c(NA,29,32.4,31,30,36,38.6,43,20.6,37,46,35.4),Mass = c(3400,8.2,450,1800,1500,2900,1300,2100,1900,1650,1450,1625,1600,1850,550,2700,3600,237.2,41.2,4850,5100,6000,2350,4550,5600,1750,2400,2020,1940,2250,4000,3720,5550,3150,620,4350,6600,3900
),Sex = structure(c(5L,1L,5L),.Label = c("F","F?","I","J","M"),Year = structure(c(1L,2L,2L),.Label = c("2017","2018"),MassCat = c("Medium","Small","Medium","Large","Large"
    ),Datect = structure(c(1502078400,1502078400,1502251200,1502510400,1502683200,1502769600,1503374400,1504238400,1532059200,1532577600,1532836800,1532923200,1533096000,1533182400,1533355200,1533528000,1533700800,1534219200,1534651200,1535428800),class = c("POSIXct","POSIXt"),tzone = ""),week = structure(c(4L,7L),.Label = c("29","35"),yday = c(219,219,221,224,226,227,234,244,201,207,210,211,213,214,216,218,220,231,240)),row.names = c(10L,52L,54L,55L,56L,58L,60L),class = "data.frame")

创建Nmds和点的数据框。

PA.mm.5p.rel.nmds2<- Metamds(PA.mm.5p.rel,distance="bray",k = 2,autotransform=FALSE)

allNmds_DF<-as.data.frame(PA.mm.5p.rel.nmds2$points)

运行ordisurf并使用函数从sp.sf对象提取x,y和z坐标。

sp.sf <- ordisurf(PA.mm.5p.rel.nmds2 ~ PA_Info$TL)

extract.xyz <- function(obj) {
  xy <- expand.grid(x = obj$grid$x,y = obj$grid$y)
  xyz <- cbind(xy,c(obj$grid$z))
  names(xyz) <- c("x","y","z")
  return(xyz)
}

这是我提取坐标的位置,但是Contour.vals中的z值与PA_Info$TL中观察到的值范围不匹配。当您绘制并比较“水平”和“总长度”中的比例时,也可以在图例中看到此情况。因为存在差异,所以我担心不能信任ordisurf或相关p值(summary(sp.sf))的输出。有人知道会出什么问题吗?

contour.vals <- extract.xyz(obj = sp.sf,plot = F)
head(contour.vals)
contour.vals <- na.omit(contour.vals)

allNmds_DFTL <- allNmds_DF[which(!is.na(PA_Info$TL)),]

p <- ggplot(data = contour.vals,aes(x,y,z = z)) + stat_contour(aes(colour = ..level..)) + 
  coord_cartesian(xlim = c(-2,2),ylim = c(-1,1.5)) + theme_bw()+
  geom_point(data = allNmds_DFTL,aes(mds1,mds2,z = 0,shape = PA_Info$Year[which(!is.na(PA_Info$TL))],fill = PA_Info$TL[which(!is.na(PA_Info$TL))]),size=8,shape=21)+
  labs(fill = 'Total Length (cm)') + xlab("Axis 1 (38.2%)")+ylab("Axis 2 (27.9%)")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)