如何将nlpr(n参数逻辑回归)传递给ggplot中的stat_smooth?

How to pass nlpr (n parameter logistic regression) to stat_smooth in ggplot?

我的数据如下

 # A tibble: 24 x 3
     time  OD600     strain
    <dbl>  <dbl>      <chr>
 1 0.0001 0.0001 M12-611020
 2 1.0000 0.0880 M12-611020
 3 3.0000 0.2110 M12-611020
 4 4.0000 0.2780 M12-611020
 5 4.5000 0.4040 M12-611020
 6 5.0000 0.6060 M12-611020
 7 5.5000 0.7780 M12-611020
 8 6.0000 0.9020 M12-611020
 9 6.5000 1.0240 M12-611020
10 8.0000 1.1000 M12-611020
11 0.0001 0.0001 M12-611025
12 1.0000 0.0770 M12-611025
13 3.0000 0.0880 M12-611025
14 4.0000 0.1250 M12-611025
15 5.0000 0.3040 M12-611025
16 5.5000 0.4210 M12-611025
17 6.0000 0.5180 M12-611025
18 6.5000 0.6160 M12-611025
19 7.0000 0.7180 M12-611025
20 7.5000 0.8520 M12-611025
21 8.0000 0.9400 M12-611025
22 8.5000 0.9500 M12-611025
23 9.0000 0.9680 M12-611025

我在 data.frame 中有 2 个 "strains",每个都有自己的一组值 "time" 和 "OD600"。

到目前为止,我一直在使用 ggplot 进行如下绘制(为简单起见,删除了美学)使用 "loess" 来拟合曲线:

growth_curve_SE <- growth_curve + 
  stat_smooth(aes(group=strain,fill=strain, colour = strain) ,method = "loess", se = T, alpha=0.2 , span = 0.8) + 
  geom_point(aes(fill=factor(strain)),alpha=0.5 , size=3,shape = 21,colour = "black", stroke = 1)

我最终想要实现的是为该方法拟合 5 参数逻辑回归而不是 "loess",因为它是更好的数据模型并且拟合更准确的曲线。

我使用包 "nplr" 来拟合多个菌株的回归,使用按菌株划分的列表:

strain_list <- split(multi_strain, multi_strain$strain)

np2 <- lapply(strain_list, function(tmp) {nplr(tmp$time, tmp$OD600, useLog = F)})

哪个符合回归:

$`M12-611020`
Instance of class nplr 

Call:
nplr(x = tmp$time, y = tmp$OD600, useLog = F)
weights method: residuals

5-P logistic model
Bottom asymptote: 0.03026607 
Top asymptote: 1.104278 
Inflexion point at (x, y): 5.297454 0.6920488 
Goodness of fit: 0.9946967 
Weighted Goodness of fit: 0.9998141 
Standard error: 0.0308006 0.01631115 


$`M12-611025`
Instance of class nplr 

Call:
nplr(x = tmp$time, y = tmp$OD600, useLog = F)
weights method: residuals

5-P logistic model
Bottom asymptote: -0.0009875526 
Top asymptote: 0.9902298 
Inflexion point at (x, y): 6.329304 0.5919818 
Goodness of fit: 0.9956551 
Weighted Goodness of fit: 0.9998606 
Standard error: 0.02541948 0.01577407 

有什么想法可以使用 "stat_smooth" 命令在 ggplot 中实现相同的目的,以使用 5 参数逻辑回归,无论是否使用 "nplr" 包?

对于任何感兴趣的人,我都找到了解决方法。

nplr 包允许您将曲线输出为一系列 x 和 y 坐标,如下所示:

x <- getXcurve(data)
y <-getYcurve(data)

从这里我使用 "geom_line" 函数使用这些 x 和 y 参数,它以 logn 的形式给出了我想要的 (n) 参数逻辑回归。第一层 "geom_point" 作为 abice,你会得到一个漂亮的图形