繁体   English   中英

R 中的简单曲线拟合

[英]simple curve fitting in R

我正在尝试找到适合我的数据的方法。 但到目前为止还没有运气。 尝试了与 drc package 不同的对数,但我确信一定有更好的我只是不知道类型。 在另一个方面 - 我将不胜感激关于如何 go 关于一般曲线狩猎的建议。

library(drc)    
df<-structure(list(x = c(10, 11, 12, 13, 14, 15, 16, 17, 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, 
        52, 53, 54, 55), y = c(0.1066, -0.6204, -0.2028, 0.2621, 0.4083, 
        0.4497, 0.6343, 0.7762, 0.8809, 1.0029, 0.8089, 0.7845, 0.8009, 
        0.9319, 0.9414, 0.9505, 0.9323, 1.0321, 0.9381, 0.8975, 1.0929, 
        1.0236, 0.9589, 1.0644, 1.0411, 1.0763, 0.9679, 1.003, 1.142, 
        1.1049, 1.2868, 1.1569, 1.1952, 1.0802, 1.2125, 1.3765, 1.263, 
        1.2507, 1.2125, 1.2207, 1.2836, 1.3352, 1.1311, 1.2321, 1.4277, 
        1.1645), w = c(898, 20566, 3011, 1364, 1520, 2376, 1923, 1934, 
        1366, 1010, 380, 421, 283, 262, 227, 173, 118, 113, 95, 69, 123, 
        70, 80, 82, 68, 83, 76, 94, 101, 97, 115, 79, 98, 84, 92, 121, 
        97, 102, 93, 92, 101, 74, 124, 64, 52, 63)), row.names = c(NA, 
        -46L), class = c("tbl_df", "tbl", "data.frame"), na.action = structure(c(`47` = 47L), class = "omit"))
    
    fit <- drm(data = df,y ~ x,fct=LL.4(), weights = w)
    plot(fit)

在此处输入图像描述

如果我们忽略权重,那么 y = a + b * x + c/x^2 似乎拟合并且在系数中是线性的,因此很容易拟合。 即使它应该是相同的 model,nls 拟合似乎看起来更好。

fm <- lm(y ~ x + I(1 / x^2), df)
plot(y ~ x, df)
lines(fitted(fm) ~ x, df)

截屏

基本思路是了解所选的 function 的性能如何。 拿一个你知道的 function(例如逻辑)并修改它。 或者(甚至更好)go 到文献中,看看人们在您的特定领域中使用了哪些功能。 然后创建一个用户定义的model,玩弄它以了解参数,定义好的起始值然后拟合它。

她是用户定义的 function 的快速而肮脏的示例(具有 package 增长率)。 它肯定可以用 drc 类似地制作。

library("growthrates")

grow_userdefined <- function (time, parms) {
  with(as.list(parms), {
    y <- (K * y0)/(y0 + (K - y0) * exp(-mumax * time)) + shift 
    return(as.matrix(data.frame(time = time, y = y)))
  })
}

fit <- fit_growthmodel(FUN=grow_userdefined, 
  p = c(y0 = -1, K = 1, mumax = 0.1, shift = 1), 
  time = df$x, y = df$y)

plot(fit)
summary(fit)

当然可以做得更好。 由于我们在开始时没有指数开始,例如可以从简单的饱和 function 开始,而不是逻辑,例如类似于 Monod 的东西。 如前所述,首选方法是使用与应用程序域相关的 function。

改良后勤

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM