我正在绘制 4 个参数逻辑曲线。这是一个包含大量曲线的巨大数据集,我的一个输出失败了,因为模型拟合不适用于某些数据。一些数据未能产生曲线并给出
Warning message: Computation failed in 'stat_smooth()': argument is of length zero
这是曲线模型的代码
library(dr4pl)
library(car)
predict.dr4pl <- function (object, newdata=NULL, se.fit=FALSE, level, interval) {
xseq <- if (is.null(newdata)) object$data$Dose else newdata$x
pred <- MeanResponse(xseq, object$parameters)
if (!se.fit) {
return(pred)
}
qq <- qnorm((1+level)/2)
se <- sapply(xseq,
function(x) car::deltaMethod(object,
"UpperLimit + (LowerLimit - UpperLimit)/(1 + (x/IC50)^Slope)")[["Estimate"]])
return(list(fit=data.frame(fit=pred,lwr=pred-qq*se,
upr=pred+qq*se), se.fit=se))
}
数据集 1 工作正常(即使曲线很糟糕):
Data1<-structure(list(medPOC = c(1.05706789111184, 1.1384060347655,
1.10675631354542, 1.09544112823877, 1.09872089209577, 1.08773424190801,
1.11870837850395, 1.18073408703732, 1.04746786433328, 1.10523462908471,
1.15984893939929, 1.05297709384816, 1.15628419157872, 1.12589559877175,
1.11894257579501), Curve = c("Curve1", "Curve1", "Curve1", "Curve1",
"Curve1", "Curve2", "Curve2", "Curve2", "Curve2", "Curve2", "Curve3",
"Curve3", "Curve3", "Curve3", "Curve3"), dose = c(0.1, 0.3, 1,
3, 10, 0.1, 0.3, 1, 3, 10, 0.1, 0.3, 1, 3, 10)), row.names = c(NA,
-15L), class = c("tbl_df", "tbl", "data.frame"))
然而数据集 2 产生错误并且没有拟合曲线:
Data2<-structure(list(medPOC = c(1.04874856862424, 1.19188614428268,
1.27809586127924, 1.2592834941927, 1.14690004907574, 1.14877338877339,
1.02852390852391, 1.00515592515593, 1.15293139293139, 0.864033264033264,
1.08484115891663, 1.11691157027915, 1.16582933554943, 1.03384580515997,
0.684622067767159), Curve = c("Curve1", "Curve1", "Curve1", "Curve1",
"Curve1", "Curve2", "Curve2", "Curve2", "Curve2", "Curve2", "Curve3",
"Curve3", "Curve3", "Curve3", "Curve3"), dose = c(0.1, 0.3, 1,
3, 10, 0.1, 0.3, 1, 3, 10, 0.1, 0.3, 1, 3, 10)), row.names = c(NA,
-15L), class = c("tbl_df", "tbl", "data.frame"))
绘图代码:
library(ggplot)
ggplot(Data1, aes(dose,medPOC, col=Curve))+
geom_point(size=4, shape=1) +
geom_smooth(method="dr4pl",se=F)+
coord_trans(x="log10")+
theme_bw()+
scale_x_continuous(breaks = c(0.01, 0.1, 1, 10, 100))+
theme(plot.title = element_text(lineheight = 0.9, face="bold", size=20, hjust=0.5))+
ggtitle("Dose Response")+
theme(axis.title = element_text(face="bold", size = 14))+
theme(axis.text = element_text(face="bold", size = 12, colour="black"))+
theme(panel.spacing = unit(0.8, "lines"))+
scale_color_manual(values = c("Curve1" = "grey28",
"Curve2" = "yellow2",
"Curve3"="tomato2"))
非常感激任何的帮助!!!