使用Lattice(panel.smoother)或ggplot提取用于获得最佳拟合的方程

使用Lattice(panel.smoother)或ggplot提取用于获得最佳拟合的方程,r,ggplot2,regression,lattice,stat,R,Ggplot2,Regression,Lattice,Stat,我有100多个类似数据的文件,它们遵循几乎相同的趋势。我已经设法获得了对所有这些问题的最佳拟合,但现在我想将其与一个理论论点进行比较。换句话说,我想用实验数据为我生成的最佳拟合曲线生成一个方程;该方程适用于特定范围内的任何随机值,并产生与以前类似的曲线,当然有一些误差 代码: 或ggplot,如下所示: library(ggplot2) ggplot(data1, aes(x=x, y=y)) + geom_point() + geom_smooth(se = FALSE) 我只想知道它的方

我有100多个类似数据的文件,它们遵循几乎相同的趋势。我已经设法获得了对所有这些问题的最佳拟合,但现在我想将其与一个理论论点进行比较。换句话说,我想用实验数据为我生成的最佳拟合曲线生成一个方程;该方程适用于特定范围内的任何随机值,并产生与以前类似的曲线,当然有一些误差

代码:

ggplot
,如下所示:

library(ggplot2)
ggplot(data1, aes(x=x, y=y)) + geom_point() + geom_smooth(se = FALSE)


我只想知道它的方程,或者可能只是曲线的一些参数(系数、标准误差值等)。

平滑器通常比您看起来理解的更复杂。它们通常仅在局部定义,因此不存在多项式拟合可能存在的全局方程。默认情况下,
面板.smoother
函数使用
平滑器,调用
xyplot
返回的对象中没有方程。而是调用
面板。面板节点的
lay
节点中保留了更平滑的
函数:

 myplot <- xyplot(y ~ x,data=data1,par.settings = ggplot2like(),
               panel = function(x,y,...){
                 panel.xyplot(x,y,...)
               })+ layer(panel.smoother(y ~ x, se = FALSE, span = 0.5))
 get('lay', envir = environment(myplot$panel))
#-------------
[[1]]
expression(panel.smoother(y ~ x, se = FALSE, span = 0.5))
attr(,"under")
[1] FALSE
attr(,"superpose")
[1] FALSE

attr(,"class")
[1] "layer"   "trellis"

myplot非常感谢您。在你发表文章之前,我实际上不理解smoother的功能。str()的结果正是我想要的。使用这些值,我想我可以创建我需要的等式。样条曲线()似乎也能正常工作。再次感谢你。
library(ggplot2)
ggplot(data1, aes(x=x, y=y)) + geom_point() + geom_smooth(se = FALSE)
 myplot <- xyplot(y ~ x,data=data1,par.settings = ggplot2like(),
               panel = function(x,y,...){
                 panel.xyplot(x,y,...)
               })+ layer(panel.smoother(y ~ x, se = FALSE, span = 0.5))
 get('lay', envir = environment(myplot$panel))
#-------------
[[1]]
expression(panel.smoother(y ~ x, se = FALSE, span = 0.5))
attr(,"under")
[1] FALSE
attr(,"superpose")
[1] FALSE

attr(,"class")
[1] "layer"   "trellis"
mysmooth <- loess(y~x)
str(mysmooth)
#--------
List of 17
 $ n        : int 10
 $ fitted   : num [1:10] 176 312 275 261 261 ...
 $ residuals: Named num [1:10] 6.78 -24.43 98.8 -159.25 -75.9 ...
  ..- attr(*, "names")= chr [1:10] "1" "2" "3" "4" ...
 ----------- omitting remaider of output------------