我试图建立一个线性模型来解释粒子浓度和荧光之间的关系。由于某些原因,我无法使用lm
来使模型适合数据,但它确实在ggplot geom_smooth
函数中起作用。
下面是对数荧光和对数颗粒浓度的图...
我使用以下代码制作了模型
Calicurve.M1 <- lm(Fluorescence~Particle.conc,
na.action = na.exclude,
data = Calicurve)
但是,当我使用此模型预测值并将其添加到绘图中(在ggplot2中时,它看起来不正确)>
### 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)
最后,当我使用#geom_smooth(method='lm')+
在geom_smooth中使用线性模型时,它按我的期望绘制关系...
我想了解为什么第一个模型不起作用以及如何修复它,以便我可以使用该模型来预测荧光值。
我试图建立一个线性模型来解释粒子浓度和荧光之间的关系。由于某些原因,我无法使用lm来使模型适合数据,但是它确实可以在...
在将变量传递到lm
之前,您必须先对其进行转换。