用R中的LinearK函数分析章鱼的捕获量 [英] Analyzing octopus catches with LinearK function in R

查看:130
本文介绍了用R中的LinearK函数分析章鱼的捕获量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望您能帮助我解决我找不到的问题.抱歉,如果我在写这篇文章时犯了一些错误,我的英语现在有点生疏了.

I hope you can help me with this problem i can't find how to overcome. Sorry if I made some mistakes while writing this post, my english is a bit rusty right now.

这是问题.我有要在R中分析的.shp数据..shp可以是代表我们设置为捕获章鱼的陷阱线的线,也可以是直接位于这些线上方的点,表示我们已经放置过的点.

Here is the question. I have .shp data that I want to analyze in R. The .shp can be either lines that represent lines of traps we set to catch octopuses or points located directly over those lines, representing where we had catured one.

我要回答的问题是:章鱼在统计上是否分组?

经过一番调查,在我看来,我需要使用Maptools,SpatStat和Sp库来使用R及其linearK函数来回答该问题.

After a bit of investigation it seems to me that i need to use R and its linearK function to answer that question, using the libraries Maptools, SpatStat and Sp.

这是我在RStudio中使用的代码:

Here is the code i'm using in RStudio:

加载库

library(spatstat)
library(maptools)
library(sp)

使用轨道创建红线对象

t1<- as.linnet(readShapeSpatial("./20170518/t1.shp"))

我收到以下警告,但它似乎起作用

I get the following warning but it seems to work

Warning messages:
1: use rgdal::readOGR or sf::st_read 
2: use rgdal::readOGR or sf::st_read 

进行绘制以确保一切正常

Plotting it to be sure everything is ok

plot(t1)

用这些点创建一个ppp对象

Creating a ppp object with the points

p1<- as.ppp(readShapeSpatial("./20170518/p1.shp"))

我在这里得到同样的警告,但是当我尝试绘制它时,真正的问题开始了:

I get the same warning here, but the real problems start when I try to plot it:

> plot(p1)
Error in if (!is.vector(xrange) || length(xrange) != 2 || xrange[2L] <  : 
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: Interpretation of arguments maxsize and markscale has changed (in spatstat version 1.37-0 and later). Size of a circle is now measured by its diameter. 
2: In plot.ppp(x, ..., multiplot = FALSE, do.plot = FALSE) :
  All mark values are NA; plotting locations only.
3: In plot.ppp(x, ..., multiplot = FALSE, do.plot = FALSE) :
  All mark values are NA; plotting locations only.
4: In plot.ppp(x, ..., multiplot = FALSE, do.plot = FALSE) :
  All mark values are NA; plotting locations only.
5: In plot.ppp(x, ..., multiplot = FALSE, do.plot = FALSE) :
  All mark values are NA; plotting locations only.
6: In plot.ppp(x, ..., multiplot = FALSE, do.plot = FALSE) :
  All mark values are NA; plotting locations only.
7: In plot.ppp(x, ..., multiplot = FALSE, do.plot = FALSE) :
  All mark values are NA; plotting locations only.

现在剩下的就是将对象合并到lpp对象中,并使用linearK函数对其进行分析

Now what is left is to join the objects in a lpp object and to analyze it with the linearK function

> pt1 <- lpp(p1,t1)
> linearK(pt1)
Function value object (class ‘fv’)
for the function r -> K[L](r)
......................................
    Math.label     Description        
r   r              distance argument r
est {hat(K)[L]}(r) estimated K[L](r)  
......................................
Default plot formula:  .~r
where "." stands for ‘est’
Recommended range of argument r: [0, 815.64]
Available range of argument r: [0, 815.64]

这是我现在的情况.我不知道的是为什么plot函数不能与我的ppp对象一起使用,以及如何低估linearK函数的返回.帮助(linearK)没有提供任何线索.由于我有很多音轨,每个音轨都有其一组点,因此我希望得到的结果是某种摘要,例如x音轨经过分析,成组,b分散和未知.

This is my situation right now. What i dont know is why the plot function is not working with my ppp object and how to understant the return of the linearK function. Help(linearK) didn't provide any clue. Since i have a lot of tracks, each with its set of points, my desired outcome would be some kind of summary like x tracks analized, a grouped, b dispersed and c unkown.

感谢您的宝贵时间,如果您能帮助我解决此问题,我将不胜感激.

Thank you for your time, i'll greatly appreciate if you can help me solve this problem.

这是指向一个zip文件的链接,该文件包含一天的shp文件,轨迹和指向,以及一个包含我的代码的txt文件. https://drive.google.com/open?id=0B0uvwT-2l4A5ODJpOTdCekIxWUU

Here is a link to a zip file containing al the shp files of one day, both tracks and points, and a txt file with my code. https://drive.google.com/open?id=0B0uvwT-2l4A5ODJpOTdCekIxWUU

推荐答案

前两点一般建议:(1)每次创建一个复杂的对象时,请在终端上打印该对象,以查看其是否符合您的期望. (2)出现错误时,立即键入traceback()并复制输出.这将准确显示检测到错误的位置.

First two pieces of general advice: (1) each time you create a complicated object, print it at the terminal, to see if it is what you expected. (2) When you get an error, immediately type traceback() and copy the output. This will reveal exactly where the error is detected.

ppp对象必须包含研究区域(窗口)的规范.在您的代码中,对象p1是通过将类SpatialPointsDataFrame的数据转换成类ppp的对象而创建的,该数据不包含研究区域的规范,而该数据通过函数as.ppp.SpatialPointsDataFrame转换为研究对象的规范.通过使用坐标的边界框来猜测窗口.不幸的是,在您的示例中,p1中只有一个数据点,因此默认的边界框是宽度为0且高度为0的矩形. .]通常可以用spatstat处理此类对象,但是此特定对象会触发函数plot.solist中的错误,该错误希望窗口的大小为非零.我将修复该错误,但是...

A ppp object must include a specification of the study region (window). In your code, the object p1 is created by converting data of class SpatialPointsDataFrame, which do not include a specification of the study region, converted via the function as.ppp.SpatialPointsDataFrame, into an object of class ppp in which the window is guessed by taking the bounding box of the coordinates. Unfortunately, in your example, there is only one data point in p1, so the default bounding box is a rectangle of width 0 and height 0. [This would have been revealed by printing p1.] Such objects can usually be handled by spatstat, but this particular object triggers a bug in the function plot.solist which expects windows to have non-zero size. I will fix the bug, but...

就您而言,我建议您

Window(p1) <- Window(t1)

在创建p1之后立即

.这样可以确保p1具有您可能想要的窗口.

immediately after creating p1. This will ensure that p1 has the window that you probably intended.

如果其他所有方法均失败,请阅读shapefile上的spatstat小插图...

If all else fails, read the spatstat vignette on shapefiles...

这篇关于用R中的LinearK函数分析章鱼的捕获量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆