【问题标题】:What ML algorithm should I use to determine fish age-at-maturity?我应该使用什么 ML 算法来确定鱼的成熟年龄?
【发布时间】:2020-10-14 14:33:48
【问题描述】:

鱼的成熟年龄是生长速率斜率发生变化的地方。 Here is an example of a simulated individual fish and its two growth rates.

我想创建一个算法,该算法将根据年龄和长度数据确定成熟年龄,类似于我附上的图片。我对哪种算法有用以及如何将其应用于我的样本数据集几乎没有什么想法:

> head(data)
  age     length
1   0 0.01479779
2   1 0.05439856
3   2 0.18308919
4   3 0.24380771
5   4 0.37759992
6   5 0.44871502

有人建议我尝试使用 Cox 比例风险模型。为此,我会将成熟年龄视为事件发生的时间(成熟是事件,年龄是达到成熟的时间)。我尝试拟合该模型但收到此错误:

> cox.model <- coxph(Surv(age ~ length), data = data)
Error in Surv(age ~ length) : Time variable is not numeric

我尝试使用 as. numeric() 将这两个变量设为数值,但这没有帮助。

如果我用错了这个模型或者我应该使用不同的模型,请告诉我。

【问题讨论】:

标签: r machine-learning cox-regression


【解决方案1】:

据我所知,事件发生时间数据应包含事件指示器,即二进制变量。如果成熟度是事件,那么它应该作为这样的二进制变量包含在数据集中,你应该运行这个 cox.model &lt;- coxph(Surv(age, maturity) ~ length, data = data)

详情请查看手册

  1. Survival package
  2. Cox model

顺便说一句,该图是由分段回归和 ggplot 之类的东西创建的,我认为您可能想要使用此类技术。这是example

【讨论】:

    【解决方案2】:

    我同意@C.C.,1) 生存模型不适用于此提供的数据集,2) 简单的分段线性回归方法更合适。

    请参阅下面建议的 R 代码以及示例输出图:

    library(segmented)
    
    # create dummy data set, extended from provided one, with noise
    df <- data.frame(
      age = seq(from = 0, to = 20, by = 1),
      length = c(
        seq(from = 0, to = 0.45, length.out = 5) + rnorm(5, mean = 1e-3, sd = 1e-2),
        seq(from = 0.48, to = 0.6, length.out = 16) + rnorm(16, mean = 1e-3, sd = 1e-2)
        )
    )
    
    # fit normal linear regression and segmented regression
    lm1 <- lm(length ~ age, data = df)
    seg_lm <- segmented(lm1, ~ age)
    
    # determine age break point
    age_break_point <- seg_lm$psi.history$all.selected.psi[[1]]
    
    # plot raw data points, segmented fit and age break point
    plot(seg_lm, res = TRUE, main=paste0('Growth rate change @ ', round(age_break_point, 1), ' years old'), xlab='Age', ylab='Length')
    abline(v = age_break_point, col='red')
    

    【讨论】:

      猜你喜欢
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 2010-09-07
      • 2017-01-28
      • 1970-01-01
      相关资源
      最近更新 更多