Why does my lm model not show a linear relationship but does in geom_smooth?
我试图建立一个线性模型来解释粒子浓度和荧光之间的关系。由于某种原因,我无法让模型使用 lm 来拟合数据,但它确实在 ggplot geom_smooth 函数中工作。
下面是对数荧光和对数粒子浓度的图…
我用下面的代码做了一个模型
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 ### geom_line(data= predframe, aes(x=Particle.conc,y=lowerse), linetype=2) |
最后,当我使用 #geom_smooth(method=’lm’)+ 在 geom_smooth 中使用线性模型时,它会按照我的预期绘制关系…
来源:https://www.codenong.com/59715834/