关于 r:为什么我的 lm 模型不显示线性关系,但在 geom_smooth 中显示? | 珊瑚贝

Why does my lm model not show a linear relationship but does in geom_smooth?


我试图建立一个线性模型来解释粒子浓度和荧光之间的关系。由于某种原因,我无法让模型使用 lm 来拟合数据,但它确实在 ggplot geom_smooth 函数中工作。

下面是对数荧光和对数粒子浓度的图…

enter

我用下面的代码做了一个模型

1
2
3
Calicurve.M1 <- lm(Fluorescence~Particle.conc,
                na.action = na.exclude,
                data = Calicurve)

但是,当我使用此模型来预测值并添加到我的绘图(在 ggplot2 中)时,它看起来不正确

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    ### predict values and put into dataframe
pdat <- expand.grid(Particle.conc = c(5, 50, 500, 5000, 50000, 500000, 5000000,
                                      50000000, 500000000, 5000000000, 50000000000,
                                      500000000000))
pred <- predict(Calicurve.M1, newdata = pdat, na.rm=T,
                type =”response”, se.fit = TRUE)
predframe <- data.frame (pdat, preds=pred$fit, se=pred$se.fit)
predframe$upperse <- (predframe$preds+predframe$se)

predframe$lowerse <- (predframe$preds-predframe$se)

### plot calibration curve ###    
plot <- ggplot(data=Calicurve, aes(x=Particle.conc, y=Fluorescence)) +
  geom_point()+
  scale_y_log10(name =”Fluorecence (AFU)”,
                     limits = c(1,1200))+
  scale_x_log10(name =”Particle concentration (particles/mL)”)+
  theme_bw() +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        strip.text = element_text(face =”italic”),
        legend.position = c(0.6, 0.75), legend.justification = c(1, 0)) +
  geom_line(data= predframe, aes(x=Particle.conc,y=preds), linetype=1) +
  geom_line(data= predframe, aes(x=Particle.conc,y=upperse), linetype=2) +

  geom_line(data= predframe, aes(x=Particle.conc,y=lowerse), linetype=2)

enter

最后,当我使用 #geom_smooth(method=’lm’)+ 在 geom_smooth 中使用线性模型时,它会按照我的预期绘制关系…



来源:https://www.codenong.com/59715834/

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?