从ggplot2创建的nls拟合中提取系数

编程入门 行业动态 更新时间:2024-10-21 10:07:10
本文介绍了从ggplot2创建的nls拟合中提取系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有一个很好的解释这里介绍如何使用ggplot2创建一个散点图,使用nls来适合数据,并且在一行中绘制适合度,就像这样

我的问题是:使用这种构造,是否可以从该调用中提取实际的nls对象?我想知道我的系数,等等。现在我无法弄清楚如何在没有单独的nls调用的情况下获得它们。

div>

我的问题是:使用这种构造,是否可以从该调用中提取实际的nls对象?我想知道我的系数等。

这在ggplot2中目前是不可能的。 ggplot2函数返回来自模型的预测,但不返回模型对象本身。因此,您不能从 ggplot 对象中提取 nls 对象来查找系数等。

在ggplot2和ggplot2-dev邮件列表中有两个相关的讨论:

groups.google/d/topic/ggplot2/7tiUB2sjCxM/discussion

groups.google/d/topic/ggplot2-dev/ dLGJnzIg4ko /讨论

快速提要:

已经要求能够从 ggplot 对象中提取统计信息,开发人员正在考虑它,但似乎有点反对。他们希望用户使用ggplot2进行可视化,并使用适当的建模功能来探索建模参数。但是,Hadley支持实现将模型对象传递给 ggplot()调用的能力。因此,不是试图从 ggplot 对象中提取 nls 对象,而是:

$ (m,s),se = F,start = list(m = 20,...,n) s = 5,N = 300), data = myhist) ggplot(data = myhist,aes(x = size,y = counts))+ geom_point()+ geom_smooth )

这样,只需要调用一次模型,就可以做任何你想做的事情,而且您不必通过搜索 ggplot 对象来查找它。但是,我不知道何时或是否会执行此操作。

There's a nice explanation here of how to use ggplot2 to create a scatterplot, fit the data using nls, and plot the fit, all in one line, like so

myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) ) ggplot(data=myhist, aes(x=size, y=counts)) + geom_point() + geom_smooth(method="nls", formula = y ~ N * dnorm(x, m, s), se=F, start=list(m=20, s=5, N=300))

My question is: using this construction, is it possible to pull out the actual nls object from that call? I'd like to know my coefficients, etc. Right now I can't figure out how to get them without doing a separate nls call.

解决方案

My question is: using this construction, is it possible to pull out the actual nls object from that call? I'd like to know my coefficients, etc.

This is currently not possible in ggplot2. The ggplot2 functions return predictions from the model, but not the model object itself. Thus, you cannot extract an nls object from the ggplot object to find the coefficients, etc.

There are two relevant discussions in the ggplot2 and ggplot2-dev mailing lists:

groups.google/d/topic/ggplot2/7tiUB2sjCxM/discussion

groups.google/d/topic/ggplot2-dev/dLGJnzIg4ko/discussion

Quick synopsis:

While many users have asked for the ability to extract statistics from ggplot objects, the developers are considering it but seem somewhat opposed. They would prefer users to use ggplot2 for visualization, and appropriate modelling functions to explore modelling parameters. However, Hadley supports the idea of implementing the ability to pass a model object to a ggplot() call. So, instead of trying to extract the nls object from your ggplot object, you would instead:

mod <- nls(y ~ N * dnorm(x, m, s), se = F, start = list(m = 20, s = 5, N = 300), data = myhist) ggplot(data = myhist, aes(x = size, y = counts)) + geom_point() + geom_smooth(mod)

That way, the model only needs to be called once, you can do anything you want to it, and you don't have to go searching through ggplot objects to find it. However, I don't know when or if this will be implemented.

更多推荐

从ggplot2创建的nls拟合中提取系数

本文发布于:2023-07-27 23:08:10,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:系数   nls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!