0

我正在参观一个鸟类保护区,那里有许多不同种类的鸟类。有些物种数量较多,而其他物种数量较少。我回到保护区 9 次,每次访问后,我都会计算我观察到的物种总数。不出所料,我的访问次数减少了,因为我每次访问时都观察到最多的物种,但这并没有增加观察到的物种的数量。R 中预测我第 20 次访问时将观察到多少只鸟的最佳函数是什么?

这是data.frame

d <- structure(list(visit = 1:9, 
                    totalNumSpeciesObserved = c(200.903, 296.329, 370.018, 431.59, 485.14, 533.233, 576.595, 616.536, 654)), 
                    class = "data.frame", row.names = c(NA, 9L))

我希望看到一个模型能够很好地拟合数据并以“类似对数”的方式表现,预测收益递减

4

2 回答 2

0

为了最好地提出问题,stack 有一些很好的链接:https ://stackoverflow.com/help/how-to-ask

如果您尝试对此进行建模,我可能会根据数据对自变量的平方根进行回归。不过,将其视为访问的函数有点奇怪……也许即使是间隔的时间段,它也会更有意义。

d <- structure(list(visit = 1:9, 
                    totalNumSpeciesObserved = c(200.903, 296.329, 370.018, 431.59, 485.14, 533.233, 576.595, 616.536, 654)), 
               class = "data.frame", row.names = c(NA, 9L))

mod <- lm(totalNumSpeciesObserved ~ I(sqrt(visit)), d)
new.df <- data.frame(visit=1:13)
out <- predict(mod, newdata = new.df)
plot(d, type = 'o',pch = 16, xlim = c(1,13), ylim = c(200,800), lwd = 2, cex = 2)
points(out, type= 'o', pch = 21, col = "blue", cex = 2)

在此处输入图像描述

包装器I()允许您即时转换自变量,因此sqrt()无需保存新变量即可使用。

于 2019-05-13T15:34:18.247 回答
0

我也不知道这是否有帮助,但您可以构建一个模拟器来测试渐近行为。例如,您可以建立一个人口:

population <- sample(size = 1e6, LETTERS[1:20], 
                     replace = TRUE, prob = 1/(2:21)^2)

这表示您的种群中有 20 个物种并且概率正在减少(根据需要扩展)。

您可以模拟访问和有关您访问的信息。例如,您访问的样本有多大?在访问期间,您只能看到 1% 的热带雨林等。

sim_visits <- function(visits, percent_obs, population){
  species_viewed <- vector()
  unique_views <- vector()

  for(i in 1:visits){
    my_samp <- sample(x = population, size = round(percent_obs*length(population),0), 
                      replace = FALSE)

    species_viewed <- c(species_viewed, my_samp)

    unique_views[i] <- length(unique(species_viewed))

  }

  new_observed <- unique_views - dplyr::lag(unique_views, 1, 0)
    df <- data.frame(unique_views = unique_views, new_observed)



    df$cummulative <- cumsum(unique_views)

    df
}

然后你可以多次从模拟中得出结论,看看你得到了什么样的值分布。

sim_visits(9, percent_obs = .001, population = population)
  unique_views new_observed cummulative
1           13           13          13
2           15            2          28
3           15            0          43
4           17            2          60
5           17            0          77
6           17            0          94
7           17            0         111
8           17            0         128
9           17            0         145

不知道这是否有帮助,但我发现模拟是概念化此类问题的好方法。

于 2019-05-13T18:03:36.923 回答