某些组的 stat_smooth 线拟合错误导致无法生成图

发布于 2024-12-11 06:13:21 字数 273 浏览 0 评论 0原文

我正在尝试为包含大量不同组的数据集绘制曲线。我想将曲线全部可视化在一个适合通用模型的图表上(带有拟泊松误差的 glm 的 stat_smooth),因此,我使用颜色对它们进行分组。然而,对于某些曲线,拟合函数失败,我得到

错误:没有找到有效的系数集:请提供起始值

然后就没有绘图了。

有没有办法让情节在没有那些“坏”群体的曲线的情况下出现?我问,因为有大量的组,虽然我可以编写一个错误检查脚本,然后将它们从数据中剔除,但如果除了那些有错误的组之外的所有内容都可以绘制出来,那就更好了。

I'm trying to plot curves for a data set with a large number of different groups. I want to visualize the curves all together on one graph fit to a common model (stat_smooth with a glm with a quasipoisson error), so, I'm using color to group them. However, for some curves, the fitting function borks out and I get

Error: no valid set of coefficients has been found: please supply starting values

And then there is no plot.

Is there a way to have the plot come up without the curves for those "bad" groups? I ask as there are a huge number of groups, and while I could write an error-check script to then kick them out of the data, it would be nicer if everything but those with an error would plot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-12-18 06:13:21

我认为没有非常简单的方法来做到这一点,但我会尝试以下方法:

编写一个循环或ldply语句来运行您想要的模型,包裹在 try 中:例如

trymodelList <- ldply(mydata,.(grp1,grp2),glm,formula=y~x,family="quasipoisson")

(我认为当前数据块应该作为 data 参数自动填充)。

找出哪些是不好的:类似于 alply(trymodelList,inherits,what="try-error")

使用此逻辑向量来子集化您不需要的组,然后传递子集化的数据到geom_smooth而不是完整的数据集。

我知道遗漏了一些细节...

编辑:我发现我基本上已经写下了您的“编写错误检查脚本...然后将它们从数据中剔除”策略。抱歉,我认为没有更简单的方法可以做到这一点。您可以尝试 ggplot 用户列表...

I don't think there's a very easy way to do this, but here's what I would try:

Write a loop or an ldply statement to run the model you have in mind, wrapped in try: e.g.

trymodelList <- ldply(mydata,.(grp1,grp2),glm,formula=y~x,family="quasipoisson")

(I think that the current data chunk should get filled in automatically as the data argument).

Figure out which ones were bad: something like alply(trymodelList,inherits,what="try-error")

Use this logical vector to subset out the groups you don't want, then pass the subsetted data to geom_smooth instead of the full data set.

I know there are a few details left out ...

edit: I see that I've essentially written down your "write an error-check script ... then kick them out of the data" strategy. Sorry, I don't think there's an easier way to do this. You might try the ggplot users' list ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文