某些组的 stat_smooth 线拟合错误导致无法生成图
我正在尝试为包含大量不同组的数据集绘制曲线。我想将曲线全部可视化在一个适合通用模型的图表上(带有拟泊松误差的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有非常简单的方法来做到这一点,但我会尝试以下方法:
编写一个循环或
ldply
语句来运行您想要的模型,包裹在try
中:例如(我认为当前数据块应该作为
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 intry
: e.g.(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 ...