【问题标题】:How to pass nlpr (n parameter logistic regression) to stat_smooth in ggplot?如何在ggplot中将nlpr(n参数逻辑回归)传递给stat_smooth?
【发布时间】:2017-11-27 20:49:50
【问题描述】:

我的数据如下

 # 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 个“菌株”,每个菌株都有自己的一组“时间”和“OD600”值。

到目前为止,我一直在使用 ggplot 进行如下绘制(为简单起见,去除了美感),使用“黄土”来拟合曲线:

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 参数逻辑回归而不是“黄土”方法,因为它是更好的数据模型并拟合更准确的曲线。

我使用包“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 

有什么想法可以在 ggplot 中使用“stat_smooth”命令来使用 5 参数逻辑回归,无论是否使用“nplr”包?

【问题讨论】:

    标签: r ggplot2 logistic-regression


    【解决方案1】:

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

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

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

    从这里我使用了“geom_line”函数,使用了这些 x 和 y 参数,这给了我以 logn 的形式追求的 (n) 参数逻辑回归。将“geom_point”作为 abice 第一层,你会得到一个好看的图表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 2012-02-09
      • 1970-01-01
      • 2021-12-07
      相关资源
      最近更新 更多